9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-28 03:09:14 +00:00
This commit is contained in:
XiaoMoMi
2024-10-07 01:28:26 +08:00
parent 4b2ddf6cd1
commit 2ba7ad95ba
15 changed files with 561 additions and 49 deletions

View File

@@ -27,6 +27,8 @@ package net.momirealms.customnameplates.common.dependency;
import net.momirealms.customnameplates.common.dependency.relocation.Relocation;
import net.momirealms.customnameplates.common.plugin.CustomNameplatesProperties;
import net.momirealms.customnameplates.common.util.Architecture;
import net.momirealms.customnameplates.common.util.Platform;
import org.jetbrains.annotations.Nullable;
import java.security.MessageDigest;
@@ -282,7 +284,48 @@ public enum Dependency {
"maven",
"commons-io",
Relocation.of("commons", "org{}apache{}commons")
);
),
LWJGL(
"org{}lwjgl",
"lwjgl",
"maven",
"lwjgl"
),
LWJGL_NATIVES(
"org{}lwjgl",
"lwjgl",
"maven",
"lwjgl-natives-" + getNativesPath(),
"-natives-" + getNativesPath()
) {
@Override
public String getVersion() {
return Dependency.LWJGL.getVersion();
}
},
LWJGL_FREETYPE(
"org{}lwjgl",
"lwjgl-freetype",
"maven",
"lwjgl-freetype"
) {
@Override
public String getVersion() {
return Dependency.LWJGL.getVersion();
}
},
LWJGL_FREETYPE_NATIVES(
"org{}lwjgl",
"lwjgl-freetype",
"maven",
"lwjgl-freetype-natives-" + getNativesPath(),
"-natives-" + getNativesPath()
) {
@Override
public String getVersion() {
return Dependency.LWJGL.getVersion();
}
};
private final List<Relocation> relocations;
private final String repo;
@@ -367,4 +410,12 @@ public enum Dependency {
public String getRepo() {
return repo;
}
private static String getNativesPath() {
String base = Platform.get().getNativePath();
if (Architecture.get() != Architecture.X64) {
base += "-" + Architecture.get().getNativePath();
}
return base;
}
}

View File

@@ -34,6 +34,10 @@ public final class Relocation {
return new Relocation(pattern.replace("{}", "."), RELOCATION_PREFIX + id);
}
public static Relocation of(String id, String pattern, String prefix) {
return new Relocation(pattern.replace("{}", "."), prefix.replace("{}", ".") + "." + RELOCATION_PREFIX + id);
}
private final String pattern;
private final String relocatedPattern;

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.common.util;
import java.util.Locale;
public enum Architecture {
X64(true),
X86(false),
ARM64(true),
ARM32(false),
PPC64LE(true),
RISCV64(true);
static final Architecture current;
final boolean is64Bit;
Architecture(boolean is64Bit) {
this.is64Bit = is64Bit;
}
public String getNativePath() {
return name().toLowerCase(Locale.ENGLISH);
}
public static Architecture get() {
return current;
}
static {
String osArch = System.getProperty("os.arch");
boolean is64Bit = osArch.contains("64") || osArch.startsWith("armv8");
if (!osArch.startsWith("arm") && !osArch.startsWith("aarch")) {
if (osArch.startsWith("ppc")) {
if (!"ppc64le".equals(osArch)) {
throw new UnsupportedOperationException("Only PowerPC 64 LE is supported.");
}
current = PPC64LE;
} else if (osArch.startsWith("riscv")) {
if (!"riscv64".equals(osArch)) {
throw new UnsupportedOperationException("Only RISC-V 64 is supported.");
}
current = RISCV64;
} else {
current = is64Bit ? X64 : X86;
}
} else {
current = is64Bit ? ARM64 : ARM32;
}
}
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.common.util;
public class OSUtils {
public static String getOSName() {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win")) {
return "windows";
} else if (os.contains("mac")) {
return "macos";
} else if (os.contains("nux") || os.contains("nix")) {
return "linux";
} else if (os.contains("freebsd")) {
return "freebsd";
} else {
return "unknown";
}
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.common.util;
public enum Platform {
FREEBSD("FreeBSD", "freebsd"),
LINUX("Linux", "linux"),
MACOS("macOS", "macos"),
WINDOWS("Windows", "windows");
private static final Platform current;
private final String name;
private final String nativePath;
Platform(String name, String nativePath) {
this.name = name;
this.nativePath = nativePath;
}
public String getName() {
return this.name;
}
public String getNativePath() {
return nativePath;
}
public static Platform get() {
return current;
}
static {
String osName = System.getProperty("os.name");
if (osName.startsWith("Windows")) {
current = WINDOWS;
} else if (osName.startsWith("FreeBSD")) {
current = FREEBSD;
} else if (!osName.startsWith("Linux") && !osName.startsWith("SunOS") && !osName.startsWith("Unix")) {
if (!osName.startsWith("Mac OS X") && !osName.startsWith("Darwin")) {
throw new LinkageError("Unknown platform: " + osName);
}
current = MACOS;
} else {
current = LINUX;
}
}
}

View File

@@ -26,4 +26,5 @@ jedis=${jedis_version}
h2-driver=${h2_driver_version}
sqlite-driver=${sqlite_driver_version}
byte-buddy=${byte_buddy_version}
commons-io=${commons_io_version}
commons-io=${commons_io_version}
lwjgl=${lwjgl_version}