Initial 1.17 support

This commit is contained in:
darbyjack committed 2021-06-11 08:52:31 -05:00
1 parent bd370a109b
commit fca45d5b6e
2 files changed
+38 -8

No files matched your search

+11 -7
View File
@@ -5,29 +5,33 @@
<version>2.5.0</version>
<name>PAPI-Expansion-Server</name>
<description>PlaceholderAPI expansion for server placeholders</description>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/dev/</url>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<version>1.17-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>PlaceholderAPI</artifactId>
<version>LATEST</version>
<version>2.10.9</version>
<scope>provided</scope>
<exclusions>
<exclusion>
@@ -41,8 +45,8 @@
</exclusions>
</dependency>
</dependencies>
<build>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -41,6 +41,8 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ServerExpansion extends PlaceholderExpansion implements Cacheable, Configurable {
@@ -61,7 +63,11 @@ public class ServerExpansion extends PlaceholderExpansion implements Cacheable,
public ServerExpansion() {
try {
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
craftServer = Class.forName("net.minecraft.server." + version + ".MinecraftServer").getMethod("getServer").invoke(null);
if (minecraftVersion() >= 17) {
craftServer = Class.forName("net.minecraft.server.MinecraftServer").getMethod("getServer").invoke(null);
} else {
craftServer = Class.forName("net.minecraft.server." + version + ".MinecraftServer").getMethod("getServer").invoke(null);
}
tps = craftServer.getClass().getField("recentTps");
variant = initializeVariant();
} catch (Exception e) {
@@ -400,4 +406,24 @@ public class ServerExpansion extends PlaceholderExpansion implements Cacheable,
return builder.toString();
}
/**
* Helper method to return the major version that the server is running.
*
* This is needed because in 1.17, NMS is no longer versioned.
*
* @return the major version of Minecraft the server is running
*/
public static int minecraftVersion() {
try {
final Matcher matcher = Pattern.compile("\\(MC: (\\d)\\.(\\d+)\\.?(\\d+?)?\\)").matcher(Bukkit.getVersion());
if (matcher.find()) {
return Integer.parseInt(matcher.toMatchResult().group(2), 10);
} else {
throw new IllegalArgumentException(String.format("No match found in '%s'", Bukkit.getVersion()));
}
} catch (final IllegalArgumentException ex) {
throw new RuntimeException("Failed to determine Minecraft version", ex);
}
}
}