Merge branch 'master' into feature/read-version-from-manifest

This commit is contained in:
Gabriel Dumitru authored and GitHub committed 2024-09-22 18:20:34 +03:00
commit 1b200d3f4f
4 files changed
+40 -19

No files matched your search

+5 -2
View File
@@ -7,12 +7,13 @@ group = "at.helpch.placeholderapi.expansion"
version = "2.7.2"
repositories {
maven("https://papermc.io/repo/repository/maven-public/")
mavenCentral()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT")
compileOnly("org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT")
compileOnly("me.clip:placeholderapi:2.11.3")
}
@@ -22,6 +23,8 @@ tasks {
attributes["Implementation-Title"] = "server"
attributes["Implementation-Version"] = project.version
}
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}
shadowJar {
@@ -5,6 +5,7 @@ import org.bukkit.Bukkit;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.OptionalInt;
import java.util.TreeMap;
@@ -12,13 +13,15 @@ import java.util.TreeMap;
public final class ServerUtil {
private static final Map<String, String> variants = new TreeMap<>();
private static final String variant;
private static final String build;
// TPS stuff
private static final Object craftServer;
private static final Field tpsField;
private static boolean hasTpsMethod; // Paper and its forks have Bukkit#getTps
private static Method getTpsMethod; // Paper and its forks have Bukkit#getTPS
// ----
private static final String variant;
private static final String build;
static {
variants.put("net.pl3x.purpur.PurpurConfig", "Purpur");
@@ -83,8 +86,7 @@ public final class ServerUtil {
private static Field getTpsHandler() {
try {
Bukkit.class.getMethod("getTPS");
hasTpsMethod = true;
getTpsMethod = Bukkit.class.getMethod("getTPS");
return null;
} catch (NoSuchMethodException ignored) { }
@@ -146,8 +148,12 @@ public final class ServerUtil {
}
public static double[] getTps() {
if (hasTpsMethod) {
return Bukkit.getTPS();
if (getTpsMethod != null) {
try {
return (double[]) getTpsMethod.invoke(null);
} catch (IllegalAccessException | InvocationTargetException ignored) {
return new double[]{0, 0, 0};
}
}
if (craftServer == null || tpsField == null) {
@@ -6,6 +6,7 @@ import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
@@ -46,9 +47,16 @@ public final class TimeFormatter {
try {
return DateTimeFormatter.ofPattern(pattern, timeLocale);
} catch (IllegalArgumentException e) {
Logging.warn("Could not parse DateTimeFormatter from string \"{0}\"", pattern);
return null;
Logging.error(e, "Could not parse DateTimeFormatter from pattern \"{0}\"", pattern);
} catch (DateTimeException e) {
if (e.getMessage().contains("obtain LocalTime from TemporalAccessor")) {
Logging.error(e, "The pattern \"{0}\" might be missing the time definition, try to add 'HH' at the end and set it to '00' (beginning of the day)", pattern);
} else {
Logging.error(e, "Could not parse DateTimeFormatter from pattern \"{0}\"", pattern);
}
}
return null;
});
}
@@ -27,6 +27,8 @@ import com.google.common.primitives.Ints;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -39,11 +41,10 @@ public final class VersionHelper {
private static final int V1_17 = 1_17_0;
private static final boolean IS_PAPER = checkPaper();
public static final String MINECRAFT_VERSION = getMinecraftVersion();
private static final int CURRENT_VERSION = getCurrentVersion();
private static final boolean IS_PAPER = checkPaper();
public static final boolean IS_1_17_OR_HIGHER = CURRENT_VERSION >= V1_17;
/**
@@ -92,13 +93,16 @@ public final class VersionHelper {
}
private static String getMinecraftVersion() {
try {
// Paper method from 2020 - returns the version like 1.20.1
return Bukkit.getMinecraftVersion();
} catch (NoSuchMethodError ignored) {
// The version is formatted as 1.20.1-R0.1-SNAPSHOT
return Bukkit.getBukkitVersion().split("-")[0];
if (IS_PAPER) {
try {
// Paper method from 2020 - returns the version like 1.20.1
final Method method = Bukkit.class.getDeclaredMethod("getMinecraftVersion");
return (String) method.invoke(Bukkit.getServer());
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
}
// The version is formatted as 1.20.1-R0.1-SNAPSHOT
return Bukkit.getBukkitVersion().split("-")[0];
}
public static String getNmsVersion() {