Skip to content

Commit

Permalink
Merge pull request #206 from DevotedMC/master
Browse files Browse the repository at this point in the history
Fixes for latest NMS, should be backwards compatible as well within 1…
  • Loading branch information
ProgrammerDan authored Dec 22, 2018
2 parents a842b26 + 7f03eb3 commit b2b91ed
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
2 changes: 1 addition & 1 deletion API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.1-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand Down
6 changes: 3 additions & 3 deletions Plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.lishid</groupId>
<artifactId>orebfuscator</artifactId>
<version>4.4.2-SNAPSHOT</version>
<version>4.4.3-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Orebfuscator4</name>
Expand All @@ -20,14 +20,14 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.1-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib-API</artifactId>
<version>4.0</version>
<version>4.4.0</version>
<scope>provided</scope>
<optional>true</optional>
<exclusions>
Expand Down
2 changes: 1 addition & 1 deletion v1_13_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.13.1-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b2b91ed

Please sign in to comment.