Ver Fonte

Support folia used Energie

Stabrinai há 8 meses atrás
pai
commit
6f3bccd6d9

+ 5 - 0
Plugin/pom.xml

@@ -85,6 +85,11 @@
 			<version>1.7</version>
 			<scope>provided</scope>
 		</dependency>
+		<dependency>
+			<groupId>com.github.Euphillya</groupId>
+			<artifactId>Energie</artifactId>
+			<version>5659f25e22</version>
+		</dependency>
 		<dependency>
 			<groupId>net.ess3</groupId>
 			<artifactId>EssentialsX</artifactId>

+ 3 - 2
Plugin/src/main/java/de/Linus122/TimeIsMoney/ATM.java

@@ -12,6 +12,7 @@ import java.util.Map.Entry;
 import java.util.TreeMap;
 import java.util.UUID;
 
+import fr.euphyllia.energie.model.SchedulerType;
 import org.bukkit.Bukkit;
 import org.bukkit.Material;
 import org.bukkit.OfflinePlayer;
@@ -237,7 +238,7 @@ public class ATM implements Listener, CommandExecutor {
 	/**
 	 * Checks if the player has the specified amount of money in their bank.
 	 *
-	 * @param p The player to check the balance of.
+	 * @param player The player to check the balance of.
 	 * @param amount The amount of money.
 	 * @return True if the player has the specified amount of money, false otherwise.
 	 */
@@ -386,7 +387,7 @@ public class ATM implements Listener, CommandExecutor {
 		final Block b = e.getBlock();
 		
 		if (b.getState() instanceof Sign) {
-			plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
+			Main.scheduler.runDelayed(SchedulerType.SYNC, task -> {
 				if (b.getState() instanceof Sign) {
 					Sign sign = (Sign) e.getBlock().getState();
 					if (sign.getLine(0).equalsIgnoreCase("[ATM]") 

+ 14 - 5
Plugin/src/main/java/de/Linus122/TimeIsMoney/Main.java

@@ -15,6 +15,9 @@ import java.util.stream.Collectors;
 
 import de.Linus122.TimeIsMoney.data.*;
 import de.Linus122.TimeIsMoney.tools.Utils;
+import fr.euphyllia.energie.Energie;
+import fr.euphyllia.energie.model.Scheduler;
+import fr.euphyllia.energie.model.SchedulerType;
 import org.bukkit.Bukkit;
 import org.bukkit.Location;
 import org.bukkit.Server;
@@ -47,6 +50,10 @@ public class Main extends JavaPlugin {
 	 * The economy being used by vault.
 	 */
 	static net.milkbowl.vault.economy.Economy economy = null;
+	/**
+	 * The scheduler being used by compatible with folia.
+	 */
+	public static Scheduler scheduler;
 	/**
 	 * The config version number.
 	 */
@@ -95,6 +102,7 @@ public class Main extends JavaPlugin {
 	@Override
 	public void onEnable() {
 
+		scheduler = new Energie(this).getScheduler(Energie.SchedulerSoft.MINECRAFT);
 		this.getCommand("timeismoney").setExecutor(new Cmd(this));
 		PL_VERSION = this.getDescription().getVersion();
 		
@@ -163,7 +171,8 @@ public class Main extends JavaPlugin {
 		if (Bukkit.getPluginManager().isPluginEnabled("Essentials") && this.getConfig().getBoolean("afk_use_essentials")) {
 			logger.info("Time is Money: Essentials found. Hook in it -> Will use Essentials's AFK feature if afk is enabled.");
 		}
-		new Metrics(this);
+		if (!Energie.isFolia())
+			new Metrics(this);
 		
 		logger.info(CC("&aTime is Money &2v" + PL_VERSION + " &astarted."));
 	}
@@ -172,7 +181,7 @@ public class Main extends JavaPlugin {
 		String intervalString = getConfig().getString("global_interval", getConfig().getInt("give_money_every_second") + "s");
 		int globalTimerSeconds = Utils.parseTimeFormat(intervalString);
 
-		playtimeWatcherTask = Bukkit.getScheduler().runTaskTimer(this, () -> {
+		scheduler.runAtFixedRate(SchedulerType.SYNC, task -> {
 			for (Player player : Bukkit.getOnlinePlayers()) {
 				if (disabledWorlds.contains(player.getWorld().getName())) continue;
 				PlayerData playerData = this.pluginData.getPlayerData(player);
@@ -205,7 +214,7 @@ public class Main extends JavaPlugin {
 	 */
 	@Override
 	public void onDisable() {
-		playtimeWatcherTask.cancel();
+		scheduler.cancelAllTask();
 
 		this.pluginData.saveData();
 
@@ -473,7 +482,7 @@ public class Main extends JavaPlugin {
 	private void dispatchCommandSync(final String cmd) {
 		final Server server = this.getServer();
 		
-		this.getServer().getScheduler().runTask(this, () -> server.dispatchCommand(server.getConsoleSender(), cmd));
+		scheduler.runTask(SchedulerType.SYNC, task -> server.dispatchCommand(server.getConsoleSender(), cmd));
 	}
 	
 	/**
@@ -538,7 +547,7 @@ public class Main extends JavaPlugin {
 			
 			times--;
 			for (int i = 0; i < times; i++) {
-				Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> sendSingleActionbarMessage(player, applyPlaceholders(player, CC(message))), 20L * i);
+				scheduler.runDelayed(SchedulerType.SYNC, task -> sendSingleActionbarMessage(player, applyPlaceholders(player, CC(message))), 20L * i);
 			}
 		}
 	}

+ 1 - 0
Plugin/src/main/resources/plugin.yml

@@ -5,6 +5,7 @@ author: Linus122
 website: "https://www.spigotmc.org/resources/time-is-money.12409/"
 main: de.Linus122.TimeIsMoney.Main
 api-version: 1.13
+folia-supported: true
 
 depend: [Vault]
 softdepend: [Essentials, PlaceholderAPI]