From 7f03eb382aaf90f59a24c25f36a5e1421774adf9 Mon Sep 17 00:00:00 2001 From: ProgrammerDan Date: Fri, 21 Dec 2018 23:18:40 -0500 Subject: [PATCH] Fixes for latest NMS, should be backwards compatible as well within 1.13.2 --- API/pom.xml | 2 +- Plugin/pom.xml | 6 ++-- v1_13_R2/pom.xml | 2 +- .../orebfuscator/nms/v1_13_R2/ChunkCache.java | 17 ++++++++-- .../orebfuscator/nms/v1_13_R2/NmsManager.java | 33 +++++++++++++++++-- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/API/pom.xml b/API/pom.xml index eb3fcab4..161f47ce 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -31,7 +31,7 @@ org.spigotmc spigot-api - 1.13.1-R0.1-SNAPSHOT + 1.13.2-R0.1-SNAPSHOT provided true diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 089c0a6c..515458fa 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -4,7 +4,7 @@ com.lishid orebfuscator - 4.4.2-SNAPSHOT + 4.4.3-SNAPSHOT jar Orebfuscator4 @@ -20,14 +20,14 @@ org.spigotmc spigot-api - 1.13.1-R0.1-SNAPSHOT + 1.13.2-R0.1-SNAPSHOT provided true com.comphenix.protocol ProtocolLib-API - 4.0 + 4.4.0 provided true diff --git a/v1_13_R2/pom.xml b/v1_13_R2/pom.xml index c33e7d9c..cdc60880 100644 --- a/v1_13_R2/pom.xml +++ b/v1_13_R2/pom.xml @@ -31,7 +31,7 @@ org.spigotmc spigot - 1.13.1-R0.1-SNAPSHOT + 1.13.2-R0.1-SNAPSHOT provided true diff --git a/v1_13_R2/src/main/java/com/lishid/orebfuscator/nms/v1_13_R2/ChunkCache.java b/v1_13_R2/src/main/java/com/lishid/orebfuscator/nms/v1_13_R2/ChunkCache.java index 9508c201..714b996e 100644 --- a/v1_13_R2/src/main/java/com/lishid/orebfuscator/nms/v1_13_R2/ChunkCache.java +++ b/v1_13_R2/src/main/java/com/lishid/orebfuscator/nms/v1_13_R2/ChunkCache.java @@ -9,6 +9,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; +import java.lang.reflect.Method; import java.util.HashMap; import net.minecraft.server.v1_13_R2.RegionFile; @@ -73,8 +74,20 @@ private synchronized RegionFile getRegionFile(File folder, int x, int z) { private synchronized void closeCacheFilesInternal() { for (RegionFile regionFile : cachedRegionFiles.values()) { try { - if (regionFile != null) - regionFile.c(); + if (regionFile != null) { + // This lovely piece of work is due to an NMS change in Spigot 1.13.2 without an R increase. + try { + Method c = regionFile.getClass().getDeclaredMethod("c"); + c.invoke(regionFile); + } catch (NoSuchMethodException nsme) { + try { + Method close = regionFile.getClass().getDeclaredMethod("close"); + close.invoke(regionFile); + } catch (NoSuchMethodException nsme2) { + + } + } + } } catch (Exception e) { e.printStackTrace(); diff --git a/v1_13_R2/src/main/java/com/lishid/orebfuscator/nms/v1_13_R2/NmsManager.java b/v1_13_R2/src/main/java/com/lishid/orebfuscator/nms/v1_13_R2/NmsManager.java index b6f4dfd7..3048c3a6 100644 --- a/v1_13_R2/src/main/java/com/lishid/orebfuscator/nms/v1_13_R2/NmsManager.java +++ b/v1_13_R2/src/main/java/com/lishid/orebfuscator/nms/v1_13_R2/NmsManager.java @@ -13,6 +13,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.craftbukkit.v1_13_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock; import org.bukkit.craftbukkit.v1_13_R2.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage; @@ -24,6 +25,8 @@ import com.lishid.orebfuscator.nms.INmsManager; import com.lishid.orebfuscator.types.BlockCoord; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -427,7 +430,16 @@ public IChunkCache createChunkCache() { public void updateBlockTileEntity(BlockCoord blockCoord, Player player) { CraftWorld world = (CraftWorld)player.getWorld(); - TileEntity tileEntity = world.getTileEntityAt(blockCoord.x, blockCoord.y, blockCoord.z); + // 1.13.2 has made this quite a bit different in later builds. + TileEntity tileEntity = null; + try { + Method getTileEntityAt = world.getClass().getMethod("getTileEntityAt", int.class, int.class, int.class); + tileEntity = (TileEntity) getTileEntityAt.invoke(world, blockCoord.x, blockCoord.y, blockCoord.z); + } catch (NoSuchMethodException nsme) { + tileEntity = world.getHandle().getTileEntity(new BlockPosition(blockCoord.x, blockCoord.y, blockCoord.z)); + } catch (Exception e) { + return; + } if (tileEntity == null) { return; @@ -527,8 +539,23 @@ private static IBlockData getBlockData(World world, int x, int y, int z, boolean int chunkZ = z >> 4; WorldServer worldServer = ((CraftWorld)world).getHandle(); - ChunkProviderServer chunkProviderServer = worldServer.getChunkProviderServer(); - + // like in ChunkCache, NMS change without R increment. + ChunkProviderServer chunkProviderServer = null; + try { + Method getChunkProviderServer = worldServer.getClass().getDeclaredMethod("getChunkProviderServer"); + chunkProviderServer = (ChunkProviderServer) getChunkProviderServer.invoke(worldServer); + } catch (NoSuchMethodException nmfe) { + try { + Method getChunkProvider = worldServer.getClass().getDeclaredMethod("getChunkProvider"); + chunkProviderServer = (ChunkProviderServer) getChunkProvider.invoke(worldServer); + } catch (NoSuchMethodException nsme) { + return null; // oops + } catch (Exception e) { + return null; + } + } catch (Exception e) { + return null; + } if(!loadChunk && !chunkProviderServer.isLoaded(chunkX, chunkZ)) return null; Chunk chunk = chunkProviderServer.getChunkAt(chunkX, chunkZ, true, true);