Skip to content

Commit 53cadfa

Browse files
authored
Merge branch 'master' into add-percent-placeholder
2 parents d2602d8 + 55a4dea commit 53cadfa

2 files changed

Lines changed: 39 additions & 9 deletions

File tree

pom.xml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,36 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.extendedclip.papi.expansion.server</groupId>
44
<artifactId>server-expansion</artifactId>
5-
<version>2.5.0</version>
5+
<version>2.6.0</version>
66
<name>PAPI-Expansion-Server</name>
77
<description>PlaceholderAPI expansion for server placeholders</description>
8-
8+
99
<repositories>
1010
<repository>
1111
<id>spigot-repo</id>
1212
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
1313
</repository>
14+
<repository>
15+
<id>sonatype</id>
16+
<url>https://oss.sonatype.org/content/groups/public/</url>
17+
</repository>
1418
<repository>
1519
<id>placeholderapi</id>
16-
<url>https://repo.extendedclip.com/content/repositories/dev/</url>
20+
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
1721
</repository>
1822
</repositories>
19-
23+
2024
<dependencies>
2125
<dependency>
2226
<groupId>org.spigotmc</groupId>
2327
<artifactId>spigot-api</artifactId>
24-
<version>1.16.4-R0.1-SNAPSHOT</version>
28+
<version>1.17-R0.1-SNAPSHOT</version>
2529
<scope>provided</scope>
2630
</dependency>
2731
<dependency>
2832
<groupId>me.clip</groupId>
2933
<artifactId>placeholderapi</artifactId>
30-
<version>2.10.9</version>
34+
<version>2.10.10</version>
3135
<scope>provided</scope>
3236
<exclusions>
3337
<exclusion>
@@ -47,8 +51,8 @@
4751
<scope>compile</scope>
4852
</dependency>
4953
</dependencies>
50-
51-
<build>
54+
55+
<build>
5256
<plugins>
5357
<plugin>
5458
<groupId>org.apache.maven.plugins</groupId>

src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import java.util.HashMap;
4444
import java.util.Map;
4545
import java.util.concurrent.TimeUnit;
46+
import java.util.regex.Matcher;
47+
import java.util.regex.Pattern;
4648

4749
public class ServerExpansion extends PlaceholderExpansion implements Cacheable, Configurable {
4850

@@ -66,7 +68,11 @@ public class ServerExpansion extends PlaceholderExpansion implements Cacheable,
6668
public ServerExpansion() {
6769
try {
6870
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
69-
craftServer = Class.forName("net.minecraft.server." + version + ".MinecraftServer").getMethod("getServer").invoke(null);
71+
if (minecraftVersion() >= 17) {
72+
craftServer = Class.forName("net.minecraft.server.MinecraftServer").getMethod("getServer").invoke(null);
73+
} else {
74+
craftServer = Class.forName("net.minecraft.server." + version + ".MinecraftServer").getMethod("getServer").invoke(null);
75+
}
7076
tps = craftServer.getClass().getField("recentTps");
7177
variant = initializeVariant();
7278
} catch (Exception e) {
@@ -462,4 +468,24 @@ private String getPercent(double tps){
462468
return Math.min(Math.round(100 / 20.0 * tps), 100.0) + "%";
463469
}
464470

471+
/**
472+
* Helper method to return the major version that the server is running.
473+
*
474+
* This is needed because in 1.17, NMS is no longer versioned.
475+
*
476+
* @return the major version of Minecraft the server is running
477+
*/
478+
public static int minecraftVersion() {
479+
try {
480+
final Matcher matcher = Pattern.compile("\\(MC: (\\d)\\.(\\d+)\\.?(\\d+?)?\\)").matcher(Bukkit.getVersion());
481+
if (matcher.find()) {
482+
return Integer.parseInt(matcher.toMatchResult().group(2), 10);
483+
} else {
484+
throw new IllegalArgumentException(String.format("No match found in '%s'", Bukkit.getVersion()));
485+
}
486+
} catch (final IllegalArgumentException ex) {
487+
throw new RuntimeException("Failed to determine Minecraft version", ex);
488+
}
489+
}
490+
465491
}

0 commit comments

Comments
 (0)