Skip to content

Commit 77304f3

Browse files
committed
Migration to Paper API
1 parent e24ae02 commit 77304f3

File tree

6 files changed

+24
-72
lines changed

6 files changed

+24
-72
lines changed

.github/workflows/maven.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v2
19-
- name: Set up JDK 1.8
20-
uses: actions/setup-java@v1
18+
- uses: actions/checkout@v4
19+
- name: Set up JDK 21
20+
uses: actions/setup-java@v4
2121
with:
22-
java-version: 1.8
22+
distribution: temurin
23+
java-version: 21
2324
- name: Build with Maven
2425
run: mvn -B package --file pom.xml

pom.xml

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<name>AnarchyStats</name>
3030

3131
<properties>
32-
<java.version>1.8</java.version>
32+
<java.version>21</java.version>
3333
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3434
</properties>
3535

@@ -67,18 +67,10 @@
6767
<pattern>org.bstats</pattern>
6868
<shadedPattern>lol.hyper.anarchystats.bstats</shadedPattern>
6969
</relocation>
70-
<relocation>
71-
<pattern>net.kyori</pattern>
72-
<shadedPattern>lol.hyper.anarchystats.adventure</shadedPattern>
73-
</relocation>
7470
<relocation>
7571
<pattern>lol.hyper.githubreleaseapi</pattern>
7672
<shadedPattern>lol.hyper.anarchystats.updater</shadedPattern>
7773
</relocation>
78-
<relocation>
79-
<pattern>space.arim.morepaperlib</pattern>
80-
<shadedPattern>lol.hyper.anarchystats.morepaperlib</shadedPattern>
81-
</relocation>
8274
</relocations>
8375
</configuration>
8476
<executions>
@@ -101,20 +93,16 @@
10193

10294
<repositories>
10395
<repository>
104-
<id>spigotmc-repo</id>
105-
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
106-
</repository>
107-
<repository>
108-
<id>arim-mvn-lgpl3</id>
109-
<url>https://mvn-repo.arim.space/lesser-gpl3/</url>
96+
<id>papermc</id>
97+
<url>https://repo.papermc.io/repository/maven-public/</url>
11098
</repository>
11199
</repositories>
112100

113101
<dependencies>
114102
<dependency>
115-
<groupId>org.spigotmc</groupId>
116-
<artifactId>spigot-api</artifactId>
117-
<version>1.20.1-R0.1-SNAPSHOT</version>
103+
<groupId>io.papermc.paper</groupId>
104+
<artifactId>paper-api</artifactId>
105+
<version>1.21.4-R0.1-SNAPSHOT</version>
118106
<scope>provided</scope>
119107
</dependency>
120108
<dependency>
@@ -129,23 +117,5 @@
129117
<version>1.0.5</version>
130118
<scope>compile</scope>
131119
</dependency>
132-
<dependency>
133-
<groupId>net.kyori</groupId>
134-
<artifactId>adventure-text-minimessage</artifactId>
135-
<version>4.17.0</version>
136-
<scope>compile</scope>
137-
</dependency>
138-
<dependency>
139-
<groupId>net.kyori</groupId>
140-
<artifactId>adventure-platform-bukkit</artifactId>
141-
<version>4.3.4</version>
142-
<scope>compile</scope>
143-
</dependency>
144-
<dependency>
145-
<groupId>space.arim.morepaperlib</groupId>
146-
<artifactId>morepaperlib</artifactId>
147-
<version>0.4.4</version>
148-
<scope>compile</scope>
149-
</dependency>
150120
</dependencies>
151121
</project>

src/main/java/lol/hyper/anarchystats/AnarchyStats.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
import lol.hyper.anarchystats.tools.WorldSize;
2525
import lol.hyper.githubreleaseapi.GitHubRelease;
2626
import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
27-
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
28-
import net.kyori.adventure.text.minimessage.MiniMessage;
2927
import org.bstats.bukkit.Metrics;
28+
import org.bukkit.Bukkit;
3029
import org.bukkit.configuration.file.FileConfiguration;
3130
import org.bukkit.configuration.file.YamlConfiguration;
3231
import org.bukkit.plugin.java.JavaPlugin;
33-
import space.arim.morepaperlib.MorePaperLib;
3432

3533
import java.io.File;
3634
import java.io.IOException;
@@ -47,17 +45,12 @@ public final class AnarchyStats extends JavaPlugin {
4745
public final Logger logger = this.getLogger();
4846
public final List<Path> worldPaths = new ArrayList<>();
4947
public final int CONFIG_VERSION = 2;
50-
public final MiniMessage miniMessage = MiniMessage.miniMessage();
51-
private BukkitAudiences adventure;
5248
public FileConfiguration config;
5349
public CommandReload commandReload;
5450
public MessageParser messageParser;
55-
public MorePaperLib morePaperLib;
5651

5752
@Override
5853
public void onEnable() {
59-
this.adventure = BukkitAudiences.create(this);
60-
morePaperLib = new MorePaperLib(this);
6154
messageParser = new MessageParser(this);
6255
commandReload = new CommandReload(this);
6356
if (!configFile.exists()) {
@@ -70,11 +63,11 @@ public void onEnable() {
7063
infoCommand.register();
7164

7265
this.getCommand("anarchystats").setExecutor(commandReload);
73-
morePaperLib.scheduling().asyncScheduler().run(this::updateWorldSize);
66+
Bukkit.getAsyncScheduler().runNow(this, scheduledTask -> updateWorldSize());
7467

7568
new Metrics(this, 6877);
7669

77-
morePaperLib.scheduling().asyncScheduler().run(this::checkForUpdates);
70+
Bukkit.getAsyncScheduler().runNow(this, scheduledTask -> checkForUpdates());
7871
}
7972

8073
public void updateWorldSize() {
@@ -83,7 +76,7 @@ public void updateWorldSize() {
8376

8477
public void loadConfig() {
8578
config = YamlConfiguration.loadConfiguration(configFile);
86-
if (worldPaths.size() > 0) {
79+
if (!worldPaths.isEmpty()) {
8780
worldPaths.clear();
8881
}
8982
for (String worldFolder : config.getStringList("worlds-to-use")) {
@@ -110,7 +103,7 @@ public void checkForUpdates() {
110103
e.printStackTrace();
111104
return;
112105
}
113-
GitHubRelease current = api.getReleaseByTag(this.getDescription().getVersion());
106+
GitHubRelease current = api.getReleaseByTag(this.getPluginMeta().getVersion());
114107
GitHubRelease latest = api.getLatestVersion();
115108
if (current == null) {
116109
logger.warning("You are running a version that does not exist on GitHub. If you are in a dev environment, you can ignore this. Otherwise, this is a bug!");
@@ -123,11 +116,4 @@ public void checkForUpdates() {
123116
logger.warning("A new version is available (" + latest.getTagVersion() + ")! You are running version " + current.getTagVersion() + ". You are " + buildsBehind + " version(s) behind.");
124117
}
125118
}
126-
127-
public BukkitAudiences getAdventure() {
128-
if (this.adventure == null) {
129-
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
130-
}
131-
return this.adventure;
132-
}
133119
}

src/main/java/lol/hyper/anarchystats/commands/CommandInfo.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,39 @@
1919

2020
import lol.hyper.anarchystats.AnarchyStats;
2121
import lol.hyper.anarchystats.tools.AbstractCommand;
22-
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
2322
import net.kyori.adventure.text.Component;
2423
import net.kyori.adventure.text.format.NamedTextColor;
24+
import org.bukkit.Bukkit;
2525
import org.bukkit.command.Command;
2626
import org.bukkit.command.CommandSender;
2727
import org.jetbrains.annotations.NotNull;
2828

2929
public class CommandInfo extends AbstractCommand {
3030

3131
private final AnarchyStats anarchyStats;
32-
private final BukkitAudiences audiences;
3332

3433
public CommandInfo(String command, AnarchyStats anarchyStats) {
3534
super(command);
3635
this.anarchyStats = anarchyStats;
37-
this.audiences = anarchyStats.getAdventure();
3836
}
3937

4038
@Override
4139
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
4240
if (anarchyStats.config.getBoolean("use-permission-node")) {
4341
String permission = anarchyStats.config.getString("permission-node");
4442
if (permission == null) {
45-
audiences.sender(sender).sendMessage(Component.text("Permission node is not set for this command! Please see 'permission-node' under AnarchyStats' config!").color(NamedTextColor.RED));
43+
sender.sendMessage(Component.text("Permission node is not set for this command! Please see 'permission-node' under AnarchyStats' config!").color(NamedTextColor.RED));
4644
return true;
4745
}
4846
if (!sender.hasPermission(permission)) {
49-
audiences.sender(sender).sendMessage(Component.text("You do not have permission for this command.").color(NamedTextColor.RED));
47+
sender.sendMessage(Component.text("You do not have permission for this command.").color(NamedTextColor.RED));
5048
return true;
5149
}
5250
}
53-
anarchyStats.morePaperLib.scheduling().asyncScheduler().run(anarchyStats::updateWorldSize);
51+
Bukkit.getAsyncScheduler().runNow(anarchyStats, scheduledTask -> anarchyStats.updateWorldSize());
5452
Component infoCommand = anarchyStats.messageParser.infoCommand();
5553
if (infoCommand != null) {
56-
audiences.sender(sender).sendMessage(infoCommand);
54+
sender.sendMessage(infoCommand);
5755
}
5856
return true;
5957
}

src/main/java/lol/hyper/anarchystats/tools/MessageParser.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@
3535
public class MessageParser {
3636

3737
private final AnarchyStats anarchyStats;
38-
private final MiniMessage miniMessage;
3938

4039
public MessageParser(AnarchyStats anarchyStats) {
4140
this.anarchyStats = anarchyStats;
42-
this.miniMessage = anarchyStats.miniMessage;
4341
}
4442

45-
4643
/**
4744
* Builds the /info command from the config.
4845
* @return A full component with the command.
@@ -98,9 +95,9 @@ public Component infoCommand() {
9895
// don't add a new line if it's the first one
9996
// creates a gap
10097
if (i == 0) {
101-
infoCommand = miniMessage.deserialize(line);
98+
infoCommand = Component.text(line);
10299
} else {
103-
infoCommand = infoCommand.append(Component.newline()).append(miniMessage.deserialize(line));
100+
infoCommand = infoCommand.append(Component.newline()).append(Component.text(line));
104101
}
105102
}
106103
return infoCommand;

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: AnarchyStats
22
version: ${project.version}
33
main: lol.hyper.anarchystats.AnarchyStats
4-
api-version: 1.13
4+
api-version: 1.21
55
load: STARTUP
66
author: hyperdefined
77
website: https://www.spigotmc.org/resources/anarchystats.66089/

0 commit comments

Comments
 (0)