Make compatible with Folia by using own ExecutorService

Our async tasks were already pretty world-independent (update checker as
 well as some logging so this should work pretty well)

For the rest the ORMLite library should already be able to handle access from
 different threads and whether economy plugins are compatible with Folia is
 up to them, not us...
This commit is contained in:
Phoenix616 2023-03-23 23:50:08 +01:00
parent b425dfb69f
commit d52c329618
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
7 changed files with 18 additions and 7 deletions

View File

@ -149,7 +149,7 @@
<dependency>
<groupId>fr.xephi</groupId>
<artifactId>authme</artifactId>
<version>5.5.0-SNAPSHOT</version>
<version>5.6.0-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>

View File

@ -91,6 +91,9 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.jar.JarFile;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
@ -105,6 +108,7 @@ public class ChestShop extends JavaPlugin {
private static ChestShop plugin;
private static Server server;
private static PluginDescriptionFile description;
private static final ExecutorService executorService = Executors.newCachedThreadPool();
private static BukkitAudiences audiences;
@ -304,7 +308,9 @@ public class ChestShop extends JavaPlugin {
}
public void onDisable() {
getServer().getScheduler().cancelTasks(this);
try {
executorService.awaitTermination(15, TimeUnit.SECONDS);
} catch (InterruptedException ignored) {}
Toggle.clearToggledPlayers();
@ -613,4 +619,8 @@ public class ChestShop extends JavaPlugin {
Bukkit.getOnlinePlayers().iterator().next().sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
}
}
public static void runInAsyncThread(Runnable runnable) {
executorService.submit(runnable);
}
}

View File

@ -1,6 +1,5 @@
package com.Acrobot.ChestShop.Listeners.Player;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -23,7 +22,7 @@ public class PlayerConnect implements Listener {
final PlayerDTO playerDTO = new PlayerDTO(event.getPlayer());
Bukkit.getScheduler().runTaskAsynchronously(ChestShop.getPlugin(), () -> {
ChestShop.runInAsyncThread(() -> {
if (NameManager.getAccount(playerDTO.getUniqueId()) != null) {
NameManager.storeUsername(playerDTO);
}

View File

@ -16,7 +16,7 @@ public class ShopCreationLogger implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public static void onShopCreation(final ShopCreatedEvent event) {
ChestShop.getBukkitServer().getScheduler().runTaskAsynchronously(ChestShop.getPlugin(), () -> {
ChestShop.runInAsyncThread(() -> {
String creator = event.getPlayer().getName();
String shopOwner = ChestShopSign.getOwner(event.getSignLines());
String typeOfShop = ChestShopSign.isAdminShop(shopOwner) ? "an Admin Shop" : "a shop" + (event.createdByOwner() ? "" : " for " + event.getOwnerAccount().getName());

View File

@ -21,7 +21,7 @@ public class ShopRemovalLogger implements Listener {
return;
}
ChestShop.getBukkitServer().getScheduler().runTaskAsynchronously(ChestShop.getPlugin(), () -> {
ChestShop.runInAsyncThread(() -> {
String shopOwner = ChestShopSign.getOwner(event.getSign());
String typeOfShop = ChestShopSign.isAdminShop(shopOwner) ? "An Admin Shop" : "A shop belonging to " + shopOwner;

View File

@ -1,5 +1,6 @@
package com.Acrobot.ChestShop.Updater;
import com.Acrobot.ChestShop.ChestShop;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.bukkit.configuration.file.FileConfiguration;
@ -55,7 +56,7 @@ public class JenkinsBuildsNotifier implements Runnable {
try {
apiUrl = new URL(jenkinsJobUrl + "api/json");
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, this);
ChestShop.runInAsyncThread(this);
} catch (MalformedURLException e) {
plugin.getLogger().log(Level.WARNING, "Can not check for new dev builds as " + jenkinsJobUrl + "api/json is not a valid url!", e);
}

View File

@ -6,6 +6,7 @@ authors: ['https://github.com/ChestShop-authors/ChestShop-3/contributors']
description: A chest shop for economy plugins.
softdepend: [Vault, Reserve, LWC, Lockette, LockettePro, Deadbolt, BlockLocker, OddItem, WorldGuard, GriefPrevention, RedProtect, Heroes, SimpleChestLock, Residence, ShowItem, ItemBridge]
api-version: '1.13'
folia-supported: true
commands:
iteminfo: