mirror of
https://github.com/LeavesMC/Leaves.git
synced 2026-01-06 15:51:33 +00:00
Fix Leaves Protocol Core, BECAUSE SOMETHING JUST RUN ON DEV
This commit is contained in:
@@ -120,10 +120,10 @@ index 0000000000000000000000000000000000000000..64a1d25973b032e8cab64bbffa6824a1
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocolManager.java b/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocolManager.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..c233f9cc008481c7a3449d58eb5f5b0f4d093990
|
||||
index 0000000000000000000000000000000000000000..055f044ce6cef4377f6f577efdbfad0ec9a2d57b
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocolManager.java
|
||||
@@ -0,0 +1,302 @@
|
||||
@@ -0,0 +1,340 @@
|
||||
+package top.leavesmc.leaves.protocol.core;
|
||||
+
|
||||
+import net.minecraft.network.FriendlyByteBuf;
|
||||
@@ -139,6 +139,7 @@ index 0000000000000000000000000000000000000000..c233f9cc008481c7a3449d58eb5f5b0f
|
||||
+import java.lang.reflect.InvocationTargetException;
|
||||
+import java.lang.reflect.Method;
|
||||
+import java.lang.reflect.Modifier;
|
||||
+import java.net.JarURLConnection;
|
||||
+import java.net.URL;
|
||||
+import java.net.URLDecoder;
|
||||
+import java.nio.charset.StandardCharsets;
|
||||
@@ -147,9 +148,12 @@ index 0000000000000000000000000000000000000000..c233f9cc008481c7a3449d58eb5f5b0f
|
||||
+import java.util.Enumeration;
|
||||
+import java.util.HashMap;
|
||||
+import java.util.HashSet;
|
||||
+import java.util.LinkedHashSet;
|
||||
+import java.util.List;
|
||||
+import java.util.Map;
|
||||
+import java.util.Set;
|
||||
+import java.util.jar.JarEntry;
|
||||
+import java.util.jar.JarFile;
|
||||
+
|
||||
+public class LeavesProtocolManager {
|
||||
+
|
||||
@@ -362,42 +366,76 @@ index 0000000000000000000000000000000000000000..c233f9cc008481c7a3449d58eb5f5b0f
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private static List<Class<?>> getClasses(String packageName) {
|
||||
+ List<Class<?>> classes = new ArrayList<>();
|
||||
+ String packageDirName = packageName.replace('.', '/');
|
||||
+ public static Set<Class<?>> getClasses(String pack) {
|
||||
+ Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
|
||||
+ String packageDirName = pack.replace('.', '/');
|
||||
+ Enumeration<URL> dirs;
|
||||
+ try {
|
||||
+ dirs = Thread.currentThread().getContextClassLoader().getResources(packageDirName);
|
||||
+ while (dirs.hasMoreElements()) {
|
||||
+ URL url = dirs.nextElement();
|
||||
+ findClassInPackageByFile(packageName, URLDecoder.decode(url.getFile(), StandardCharsets.UTF_8), classes);
|
||||
+ String protocol = url.getProtocol();
|
||||
+ if ("file".equals(protocol)) {
|
||||
+ String filePath = URLDecoder.decode(url.getFile(), StandardCharsets.UTF_8);
|
||||
+ findClassesInPackageByFile(pack, filePath, classes);
|
||||
+ } else if ("jar".equals(protocol)) {
|
||||
+ JarFile jar;
|
||||
+ try {
|
||||
+ jar = ((JarURLConnection) url.openConnection()).getJarFile();
|
||||
+ Enumeration<JarEntry> entries = jar.entries();
|
||||
+ findClassesInPackageByJar(pack, entries, packageDirName, classes);
|
||||
+ } catch (IOException e) {
|
||||
+ e.printStackTrace();
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ } catch (IOException e) {
|
||||
+ throw new RuntimeException(e);
|
||||
+ e.printStackTrace();
|
||||
+ }
|
||||
+ return classes;
|
||||
+ }
|
||||
+
|
||||
+ private static void findClassInPackageByFile(String packageName, String filePath, List<Class<?>> classes) {
|
||||
+ File dir = new File(filePath);
|
||||
+ private static void findClassesInPackageByFile(String packageName, String packagePath, Set<Class<?>> classes) {
|
||||
+ File dir = new File(packagePath);
|
||||
+ if (!dir.exists() || !dir.isDirectory()) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ File[] dirFiles = dir.listFiles(file -> file.getName().endsWith("class") || file.isDirectory());
|
||||
+ if (dirFiles != null) {
|
||||
+ for (File file : dirFiles) {
|
||||
+ File[] dirfiles = dir.listFiles((file) -> file.isDirectory() || file.getName().endsWith(".class"));
|
||||
+ if (dirfiles != null) {
|
||||
+ for (File file : dirfiles) {
|
||||
+ if (file.isDirectory()) {
|
||||
+ if (!file.getName().equals("core")) {
|
||||
+ findClassInPackageByFile(packageName + "." + file.getName(), file.getPath(), classes);
|
||||
+ findClassesInPackageByFile(packageName + "." + file.getName(), file.getAbsolutePath(), classes);
|
||||
+ } else {
|
||||
+ String className = file.getName().substring(0, file.getName().length() - 6);
|
||||
+ try {
|
||||
+ classes.add(Class.forName(packageName + '.' + className));
|
||||
+ } catch (ClassNotFoundException e) {
|
||||
+ e.printStackTrace();
|
||||
+ }
|
||||
+ continue;
|
||||
+ }
|
||||
+ String className = file.getName().substring(0, file.getName().length() - 6);
|
||||
+ try {
|
||||
+ classes.add(Thread.currentThread().getContextClassLoader().loadClass(packageName + "." + className));
|
||||
+ } catch (ClassNotFoundException e) {
|
||||
+ throw new RuntimeException(e);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private static void findClassesInPackageByJar(String packageName, Enumeration<JarEntry> entries, String packageDirName, Set<Class<?>> classes) {
|
||||
+ while (entries.hasMoreElements()) {
|
||||
+ JarEntry entry = entries.nextElement();
|
||||
+ String name = entry.getName();
|
||||
+ if (name.charAt(0) == '/') {
|
||||
+ name = name.substring(1);
|
||||
+ }
|
||||
+ if (name.startsWith(packageDirName)) {
|
||||
+ int idx = name.lastIndexOf('/');
|
||||
+ if (idx != -1) {
|
||||
+ packageName = name.substring(0, idx).replace('/', '.');
|
||||
+ }
|
||||
+ if (name.endsWith(".class") && !entry.isDirectory()) {
|
||||
+ String className = name.substring(packageName.length() + 1, name.length() - 6);
|
||||
+ try {
|
||||
+ classes.add(Class.forName(packageName + '.' + className));
|
||||
+ } catch (ClassNotFoundException e) {
|
||||
+ e.printStackTrace();
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
|
||||
@@ -34,10 +34,10 @@ index 17696dfdb3ad1d8c63ff1d1fa0c5eb6bf2e2ae42..bb47170917ed8918a9781b71ae60fd74
|
||||
public Level getLevel() {
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/protocol/BBORProtocol.java b/src/main/java/top/leavesmc/leaves/protocol/BBORProtocol.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..9bc31425ffaedcf17313aa000ba4fe3c16929810
|
||||
index 0000000000000000000000000000000000000000..4e1e099f6f480ae694405f0b1f98f429e2653d31
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/protocol/BBORProtocol.java
|
||||
@@ -0,0 +1,228 @@
|
||||
@@ -0,0 +1,227 @@
|
||||
+package top.leavesmc.leaves.protocol;
|
||||
+
|
||||
+import net.minecraft.core.BlockPos;
|
||||
@@ -83,8 +83,6 @@ index 0000000000000000000000000000000000000000..9bc31425ffaedcf17313aa000ba4fe3c
|
||||
+ private static final Map<Integer, Set<BBoundingBox>> playerBoundingBoxesCache = new HashMap<>();
|
||||
+ private static final Map<ResourceLocation, Map<BBoundingBox, Set<BBoundingBox>>> dimensionCache = new ConcurrentHashMap<>();
|
||||
+
|
||||
+ private static final ServerLevel OVERWORLD = MinecraftServer.getServer().overworld();
|
||||
+
|
||||
+ @Contract("_ -> new")
|
||||
+ public static @NotNull ResourceLocation id(String path) {
|
||||
+ return new ResourceLocation(PROTOCOL_ID, path);
|
||||
@@ -111,10 +109,11 @@ index 0000000000000000000000000000000000000000..9bc31425ffaedcf17313aa000ba4fe3c
|
||||
+ @ProtocolHandler.PlayerJoin
|
||||
+ public static void onPlayerLoggedIn(@NotNull ServerPlayer player) {
|
||||
+ if (LeavesConfig.bborProtocol) {
|
||||
+ ServerLevel overworld = MinecraftServer.getServer().overworld();
|
||||
+ ProtocolUtils.sendPayloadPacket(player, INITIALIZE_CLIENT, buf -> {
|
||||
+ buf.writeLong(OVERWORLD.getSeed());
|
||||
+ buf.writeInt(OVERWORLD.levelData.getXSpawn());
|
||||
+ buf.writeInt(OVERWORLD.levelData.getZSpawn());
|
||||
+ buf.writeLong(overworld.getSeed());
|
||||
+ buf.writeInt(overworld.levelData.getXSpawn());
|
||||
+ buf.writeInt(overworld.levelData.getZSpawn());
|
||||
+ });
|
||||
+ sendStructureList(player);
|
||||
+ }
|
||||
|
||||
Reference in New Issue
Block a user