55import java .util .Map ;
66import java .util .Set ;
77
8+ import com .tcoded .folialib .FoliaLib ;
9+ import com .tcoded .folialib .impl .PlatformScheduler ;
810import org .bukkit .Bukkit ;
911import org .bukkit .entity .Player ;
1012import org .bukkit .event .EventHandler ;
2628
2729public class App extends JavaPlugin implements Listener {
2830
31+ private static PlatformScheduler scheduler ;
32+
2933 private Map <String , CommandConfig > commands ;
3034 private Map <String , Set <Player >> playersInRegions ;
3135
@@ -39,6 +43,9 @@ public class App extends JavaPlugin implements Listener {
3943
4044 @ Override
4145 public void onEnable () {
46+ FoliaLib foliaLib = new FoliaLib (this );
47+ scheduler = foliaLib .getScheduler ();
48+
4249 getLogger ().info ("AfkPool Version 2.1.0 enabled." );
4350 getServer ().getPluginManager ().registerEvents (this , this );
4451 saveDefaultConfig ();
@@ -61,7 +68,7 @@ public void onEnable() {
6168
6269 for (CommandConfig command : commands .values ()) {
6370 if (command .isEnabled ()) {
64- Bukkit . getScheduler (). scheduleSyncRepeatingTask ( this , ( ) -> executeCommandForRegion (command ), 0L , command .getInterval ());
71+ scheduler . runTimer (( ) -> executeCommandForRegion (command ), 1L , command .getInterval ());
6572 }
6673 }
6774 }
@@ -71,6 +78,10 @@ public void onDisable() {
7178 getLogger ().info ("AfkPool Disabled" );
7279 }
7380
81+ public static PlatformScheduler scheduler () {
82+ return scheduler ;
83+ }
84+
7485 public static String format (String str ) {
7586 return ChatColor .translateAlternateColorCodes ('&' , str );
7687 }
@@ -208,6 +219,7 @@ private void executeCommandForRegion(CommandConfig commandConfig) {
208219 break ;
209220 }
210221 }
222+
211223 if (isInRegion ) {
212224 if (!playersInRegions .get (commandConfig .getKey ()).contains (player )) {
213225 playersInRegions .get (commandConfig .getKey ()).add (player );
@@ -217,9 +229,7 @@ private void executeCommandForRegion(CommandConfig commandConfig) {
217229 }
218230 executeCommandForPlayer (player , commandConfig );
219231 } else {
220- if (playersInRegions .get (commandConfig .getKey ()).contains (player )) {
221- playersInRegions .get (commandConfig .getKey ()).remove (player );
222- }
232+ playersInRegions .get (commandConfig .getKey ()).remove (player );
223233 }
224234 }
225235 }
@@ -228,11 +238,12 @@ private void executeCommandForPlayer(Player player, CommandConfig commandConfig)
228238 if (commandConfig .isEnabled ()) {
229239 int value = commandConfig .getMin () + (int ) (Math .random () * ((commandConfig .getMax () - commandConfig .getMin ()) + 1 ));
230240 if (player .hasPermission ("afkpool.bonus" )) {
231- value *= commandConfig .getMultiplier ();
241+ value *= ( int ) commandConfig .getMultiplier ();
232242 }
233243 String command = commandConfig .getCommand ().replace ("%p" , player .getName ());
234244 command = command .replace ("%m" , String .valueOf (value ));
235- Bukkit .dispatchCommand (Bukkit .getConsoleSender (), command );
245+ String finalCommand = command ;
246+ scheduler .runNextTick (task -> Bukkit .dispatchCommand (Bukkit .getConsoleSender (), finalCommand ));
236247
237248 String formattedTitle = commandConfig .getTitle ().replace ("%m" , String .valueOf (value ));
238249 formattedTitle = format (formattedTitle );
0 commit comments