Skip to content

Commit df151aa

Browse files
authored
Merge pull request #5 from FreshSMP/main
Folia Support
2 parents fddf7a9 + 6bd6a79 commit df151aa

5 files changed

Lines changed: 51 additions & 15 deletions

File tree

pom.xml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.abdullaharafat.AfkPool</groupId>
6-
<artifactId>afkpool</artifactId>
6+
<artifactId>AfkPool</artifactId>
77
<version>2.1.0</version>
88

99
<properties>
@@ -20,6 +20,10 @@
2020
<id>sk89q-repo</id>
2121
<url>https://maven.enginehub.org/repo/</url>
2222
</repository>
23+
<repository>
24+
<id>tcoded-releases</id>
25+
<url>https://repo.tcoded.com/releases</url>
26+
</repository>
2327
</repositories>
2428

2529
<dependencies>
@@ -35,10 +39,16 @@
3539
<version>LATEST</version>
3640
<scope>provided</scope>
3741
</dependency>
42+
<dependency>
43+
<groupId>com.tcoded</groupId>
44+
<artifactId>FoliaLib</artifactId>
45+
<version>0.5.1</version>
46+
<scope>compile</scope>
47+
</dependency>
3848
<dependency>
3949
<groupId>org.bstats</groupId>
4050
<artifactId>bstats-bukkit</artifactId>
41-
<version>3.0.2</version>
51+
<version>3.1.0</version>
4252
<scope>compile</scope>
4353
</dependency>
4454
</dependencies>
@@ -50,18 +60,24 @@
5060
<url>https://maven.pkg.github.com/kmaba/AfkPool</url>
5161
</repository>
5262
</distributionManagement>
53-
5463
<build>
5564
<plugins>
5665
<plugin>
5766
<groupId>org.apache.maven.plugins</groupId>
5867
<artifactId>maven-shade-plugin</artifactId>
59-
<version>3.1.0</version>
68+
<version>3.6.1</version>
6069
<configuration>
70+
<artifactSet>
71+
<includes>
72+
<include>com.tcoded:FoliaLib</include>
73+
</includes>
74+
</artifactSet>
6175
<relocations>
6276
<relocation>
6377
<pattern>org.bstats</pattern>
6478
<shadedPattern>com.abdullaharafat.AfkPool</shadedPattern>
79+
<pattern>com.tcoded.folialib</pattern>
80+
<shadedPattern>com.abdullaharafat.AfkPool.libs.folialib</shadedPattern>
6581
</relocation>
6682
</relocations>
6783
</configuration>
@@ -82,5 +98,4 @@
8298
</resource>
8399
</resources>
84100
</build>
85-
86-
</project>
101+
</project>

src/main/java/com/abdullaharafat/AfkPool/App.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.Map;
66
import java.util.Set;
77

8+
import com.tcoded.folialib.FoliaLib;
9+
import com.tcoded.folialib.impl.PlatformScheduler;
810
import org.bukkit.Bukkit;
911
import org.bukkit.entity.Player;
1012
import org.bukkit.event.EventHandler;
@@ -26,6 +28,8 @@
2628

2729
public 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);

src/main/java/com/abdullaharafat/AfkPool/Metrics.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*
1313
* Violations will result in a ban of your plugin and account from bStats.
1414
*/
15+
1516
package com.abdullaharafat.AfkPool;
1617

1718
import java.io.BufferedReader;
@@ -41,6 +42,8 @@
4142
import java.util.stream.Collectors;
4243
import java.util.zip.GZIPOutputStream;
4344
import javax.net.ssl.HttpsURLConnection;
45+
46+
import com.tcoded.folialib.impl.PlatformScheduler;
4447
import org.bukkit.Bukkit;
4548
import org.bukkit.configuration.file.YamlConfiguration;
4649
import org.bukkit.entity.Player;
@@ -50,6 +53,8 @@
5053
public class Metrics {
5154

5255
private final Plugin plugin;
56+
57+
private final PlatformScheduler scheduler;
5358

5459
private final MetricsBase metricsBase;
5560

@@ -62,6 +67,7 @@ public class Metrics {
6267
*/
6368
public Metrics(JavaPlugin plugin, int serviceId) {
6469
this.plugin = plugin;
70+
this.scheduler = App.scheduler();
6571
// Get the config file
6672
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
6773
File configFile = new File(bStatsFolder, "config.yml");
@@ -101,7 +107,7 @@ public Metrics(JavaPlugin plugin, int serviceId) {
101107
enabled,
102108
this::appendPlatformData,
103109
this::appendServiceData,
104-
submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask),
110+
submitDataTask -> scheduler.runNextTick(task -> submitDataTask.run()),
105111
plugin::isEnabled,
106112
(message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
107113
(message) -> this.plugin.getLogger().log(Level.INFO, message),
@@ -158,7 +164,7 @@ private int getPlayerAmount() {
158164
public static class MetricsBase {
159165

160166
/** The version of the Metrics class. */
161-
public static final String METRICS_VERSION = "3.0.2";
167+
public static final String METRICS_VERSION = "3.1.0";
162168

163169
private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s";
164170

src/main/java/com/abdullaharafat/AfkPool/UpdateChecker.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.abdullaharafat.AfkPool;
22

3+
import com.tcoded.folialib.impl.PlatformScheduler;
34
import org.bukkit.Bukkit;
45
import org.bukkit.plugin.java.JavaPlugin;
56

@@ -12,15 +13,17 @@
1213
public class UpdateChecker {
1314

1415
private final JavaPlugin plugin;
16+
private final PlatformScheduler scheduler;
1517
private final int resourceId;
1618

1719
public UpdateChecker(JavaPlugin plugin, int resourceId) {
1820
this.plugin = plugin;
21+
this.scheduler = App.scheduler();
1922
this.resourceId = resourceId;
2023
}
2124

2225
public void getVersion(final Consumer<String> consumer) {
23-
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
26+
scheduler.runAsync(task -> {
2427
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
2528
if (scanner.hasNext()) {
2629
consumer.accept(scanner.next());

src/main/resources/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ main: com.abdullaharafat.AfkPool.App
44
description: A plugin that rewards AFK players in a specific region
55
version: ${project.version}
66
api-version: 1.13
7+
folia-supported: true
78
depend: [WorldGuard]
89
commands:
910
AfkPool:

0 commit comments

Comments
 (0)