mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 20:39:13 +00:00
Support for 1.19.3
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class NMSHandlers {
|
||||
|
||||
private static final String[] SUPPORTED_VERSION = new String[]{"v1_19_R1"};
|
||||
private static final String[] SUPPORTED_VERSION = new String[]{"v1_19_R1", "v1_19_R2"};
|
||||
private static NMSHandler handler;
|
||||
|
||||
public static NMSHandler getHandler() {
|
||||
@@ -18,10 +23,18 @@ public class NMSHandlers {
|
||||
|
||||
public static void setup() {
|
||||
if (handler != null) return;
|
||||
final String packageName = HMCCosmeticsPlugin.getInstance().getServer().getClass().getPackage().getName();
|
||||
String packageVersion = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
|
||||
for (String version : SUPPORTED_VERSION) {
|
||||
MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.SEVERE);
|
||||
if (!version.contains(packageVersion)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
//Class.forName("org.bukkit.craftbukkit." + version + ".block.CraftBlock").getName();
|
||||
handler = (NMSHandler) Class.forName("com.hibiscusmc.hmccosmetics.nms." + version + ".NMSHandler").getConstructor().newInstance();
|
||||
handler = (NMSHandler) Class.forName("com.hibiscusmc.hmccosmetics.nms." + packageVersion + ".NMSHandler").getConstructor().newInstance();
|
||||
return;
|
||||
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException |
|
||||
IllegalAccessException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ServerUtils {
|
||||
|
||||
private static String COLOR_CHAR = "&";
|
||||
|
||||
/**
|
||||
* Converts a bukkit gamemode into an integer for use in packets
|
||||
* @param gamemode Bukkit gamemode to convert.
|
||||
@@ -22,4 +28,15 @@ public class ServerUtils {
|
||||
public static org.bukkit.entity.Entity getEntity(int entityId) {
|
||||
return NMSHandlers.getHandler().getEntity(entityId);
|
||||
}
|
||||
|
||||
public static Color hex2Rgb(String colorStr) {
|
||||
try {
|
||||
return Color.fromRGB(
|
||||
Integer.valueOf(colorStr.substring(1, 3), 16),
|
||||
Integer.valueOf(colorStr.substring(3, 5), 16),
|
||||
Integer.valueOf(colorStr.substring(5, 7), 16));
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user