Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.extendedclip.papi.expansion.server</groupId>
<artifactId>server-expansion</artifactId>
<version>2.5.0</version>
<version>2.6.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>
Expand All @@ -41,8 +45,8 @@
</exclusions>
</dependency>
</dependencies>
<build>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
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 {

Expand All @@ -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) {
Expand Down Expand Up @@ -400,4 +406,24 @@ public static String formatTime(final Duration duration) {
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);
}
}

}