Skip to content

Commit

Permalink
Add Folia support (#292)
Browse files Browse the repository at this point in the history
* feat(folia): added folia support

* chore(folia): apply folia-supported: true label

---------

Co-authored-by: R00tB33rMan <rootb33rman@gmail.com>
  • Loading branch information
xCodiq and R00tB33rMan authored Feb 19, 2025
1 parent 3b907e1 commit 0db487c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ planarwrappers = "3.3.0"
annotations = "26.0.2"
paperweight = "2.0.0-beta.14"
shadow = "8.3.6"
folia = "v0.0.3"

[libraries]
spigotapi = { module = "org.spigotmc:spigot-api", version.ref = "spigotapi" }
specialsource = { module = "net.md-5:SpecialSource", version.ref = "specialsource" }
planarwrappers = { module = "com.github.jikoo:planarwrappers", version.ref = "planarwrappers" }
annotations = { module = "org.jetbrains:annotations", version.ref = "annotations" }
folia = { module = "com.github.NahuLD.folia-scheduler-wrapper:folia-scheduler-wrapper", version.ref = "folia" }

[plugins]
paperweight = { id = "io.papermc.paperweight.userdev", version.ref = "paperweight" }
Expand Down
3 changes: 3 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
implementation(project(":openinvadapterpaper1_21_1"))
implementation(project(":openinvadapterspigot", configuration = "reobf"))
implementation(libs.planarwrappers)
implementation(libs.folia)
}

tasks.processResources {
Expand All @@ -26,8 +27,10 @@ tasks.jar {
}

tasks.shadowJar {
relocate("me.nahu.scheduler.wrapper", "com.lishid.openinv.internal.folia.scheduler")
minimize {
exclude(":openinv**")
exclude(dependency("com.github.NahuLD.folia-scheduler-wrapper:folia-scheduler-wrapper:.*"))
}
}

Expand Down
3 changes: 2 additions & 1 deletion plugin/src/main/java/com/lishid/openinv/OpenInv.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.lishid.openinv.util.lang.LanguageManager;
import com.lishid.openinv.util.setting.PlayerToggle;
import com.lishid.openinv.util.setting.PlayerToggles;
import me.nahu.scheduler.wrapper.FoliaWrappedJavaPlugin;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -59,7 +60,7 @@
/**
* The main class for OpenInv.
*/
public class OpenInv extends JavaPlugin implements IOpenInv {
public class OpenInv extends FoliaWrappedJavaPlugin implements IOpenInv {

private InternalAccessor accessor;
private Config config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import com.lishid.openinv.util.config.Config;
import com.lishid.openinv.util.lang.LanguageManager;
import com.lishid.openinv.util.lang.Replacement;
import me.nahu.scheduler.wrapper.runnable.WrappedRunnable;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
Expand Down Expand Up @@ -99,7 +99,7 @@ public boolean onCommand(@NotNull final CommandSender sender, @NotNull final Com
name = args[0];
}

new BukkitRunnable() {
new WrappedRunnable() {
@Override
public void run() {
final OfflinePlayer offlinePlayer = playerLoader.match(name);
Expand All @@ -109,7 +109,7 @@ public void run() {
return;
}

new BukkitRunnable() {
new WrappedRunnable() {
@Override
public void run() {
if (!player.isOnline()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.jikoo.planarwrappers.util.version.BukkitVersions;
import com.github.jikoo.planarwrappers.util.version.Version;
import com.google.errorprone.annotations.Keep;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.event.OpenEvents;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialInventory;
Expand Down Expand Up @@ -44,11 +45,11 @@ public class InventoryManager implements Listener {
private final Map<UUID, ISpecialPlayerInventory> inventories = new ConcurrentHashMap<>();
private final Map<UUID, ISpecialEnderChest> enderChests = new ConcurrentHashMap<>();
private final Set<UUID> expectedCloses = new HashSet<>();
private final @NotNull Plugin plugin;
private final @NotNull OpenInv plugin;
private final @NotNull Config config;
private final @NotNull InternalAccessor accessor;

public InventoryManager(@NotNull Plugin plugin, @NotNull Config config, @NotNull InternalAccessor accessor) {
public InventoryManager(@NotNull OpenInv plugin, @NotNull Config config, @NotNull InternalAccessor accessor) {
this.plugin = plugin;
this.config = config;
this.accessor = accessor;
Expand Down Expand Up @@ -164,7 +165,7 @@ private void onInventoryClose(@NotNull InventoryCloseEvent event) {
}

// Schedule task to check in use status later this tick. Closing user is still in viewer list.
plugin.getServer().getScheduler().runTask(plugin, () -> {
plugin.getScheduler().runTask(() -> {
if (loaded.isInUse()) {
return;
}
Expand Down
12 changes: 7 additions & 5 deletions plugin/src/main/java/com/lishid/openinv/util/PlayerLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.errorprone.annotations.Keep;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.util.config.Config;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
Expand All @@ -18,6 +19,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.logging.Level;
Expand All @@ -28,15 +30,15 @@
*/
public class PlayerLoader implements Listener {

private final @NotNull Plugin plugin;
private final @NotNull OpenInv plugin;
private final @NotNull Config config;
private final @NotNull InventoryManager inventoryManager;
private final @NotNull InternalAccessor internalAccessor;
private final @NotNull Logger logger;
private final @NotNull Cache<String, PlayerProfile> lookupCache;

public PlayerLoader(
@NotNull Plugin plugin,
@NotNull OpenInv plugin,
@NotNull Config config,
@NotNull InventoryManager inventoryManager,
@NotNull InternalAccessor internalAccessor,
Expand Down Expand Up @@ -78,8 +80,8 @@ public PlayerLoader(
return internalAccessor.getPlayerDataManager().loadPlayer(offline);
}

Future<Player> future = Bukkit.getScheduler().callSyncMethod(plugin,
() -> internalAccessor.getPlayerDataManager().loadPlayer(offline));
CompletableFuture<Player> future = new CompletableFuture<>();
plugin.getScheduler().runTask(() -> future.complete(internalAccessor.getPlayerDataManager().loadPlayer(offline)));

try {
player = future.get();
Expand Down Expand Up @@ -195,7 +197,7 @@ private void updateMatches(@NotNull PlayerJoinEvent event) {
return;
}

plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, () -> {
plugin.getScheduler().runTaskLaterAsynchronously(() -> {
Iterator<Map.Entry<String, PlayerProfile>> iterator = lookupCache.asMap().entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, PlayerProfile> entry = iterator.next();
Expand Down
1 change: 1 addition & 0 deletions plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ author: lishid
authors: [Jikoo, ShadowRanger]
description: Open a player's inventory as a chest and interact with it in real time.
api-version: "1.13"
folia-supported: true

permissions:

Expand Down

0 comments on commit 0db487c

Please sign in to comment.