Skip to content

Commit b2b91ed

Browse files
Merge pull request #206 from DevotedMC/master
Fixes for latest NMS, should be backwards compatible as well within 1…
2 parents a842b26 + 7f03eb3 commit b2b91ed

File tree

5 files changed

+50
-10
lines changed

5 files changed

+50
-10
lines changed

API/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>org.spigotmc</groupId>
3333
<artifactId>spigot-api</artifactId>
34-
<version>1.13.1-R0.1-SNAPSHOT</version>
34+
<version>1.13.2-R0.1-SNAPSHOT</version>
3535
<scope>provided</scope>
3636
<optional>true</optional>
3737
</dependency>

Plugin/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.lishid</groupId>
66
<artifactId>orebfuscator</artifactId>
7-
<version>4.4.2-SNAPSHOT</version>
7+
<version>4.4.3-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>Orebfuscator4</name>
@@ -20,14 +20,14 @@
2020
<dependency>
2121
<groupId>org.spigotmc</groupId>
2222
<artifactId>spigot-api</artifactId>
23-
<version>1.13.1-R0.1-SNAPSHOT</version>
23+
<version>1.13.2-R0.1-SNAPSHOT</version>
2424
<scope>provided</scope>
2525
<optional>true</optional>
2626
</dependency>
2727
<dependency>
2828
<groupId>com.comphenix.protocol</groupId>
2929
<artifactId>ProtocolLib-API</artifactId>
30-
<version>4.0</version>
30+
<version>4.4.0</version>
3131
<scope>provided</scope>
3232
<optional>true</optional>
3333
<exclusions>

v1_13_R2/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>org.spigotmc</groupId>
3333
<artifactId>spigot</artifactId>
34-
<version>1.13.1-R0.1-SNAPSHOT</version>
34+
<version>1.13.2-R0.1-SNAPSHOT</version>
3535
<scope>provided</scope>
3636
<optional>true</optional>
3737
</dependency>

v1_13_R2/src/main/java/com/lishid/orebfuscator/nms/v1_13_R2/ChunkCache.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.DataInputStream;
1010
import java.io.DataOutputStream;
1111
import java.io.File;
12+
import java.lang.reflect.Method;
1213
import java.util.HashMap;
1314

1415
import net.minecraft.server.v1_13_R2.RegionFile;
@@ -73,8 +74,20 @@ private synchronized RegionFile getRegionFile(File folder, int x, int z) {
7374
private synchronized void closeCacheFilesInternal() {
7475
for (RegionFile regionFile : cachedRegionFiles.values()) {
7576
try {
76-
if (regionFile != null)
77-
regionFile.c();
77+
if (regionFile != null) {
78+
// This lovely piece of work is due to an NMS change in Spigot 1.13.2 without an R increase.
79+
try {
80+
Method c = regionFile.getClass().getDeclaredMethod("c");
81+
c.invoke(regionFile);
82+
} catch (NoSuchMethodException nsme) {
83+
try {
84+
Method close = regionFile.getClass().getDeclaredMethod("close");
85+
close.invoke(regionFile);
86+
} catch (NoSuchMethodException nsme2) {
87+
88+
}
89+
}
90+
}
7891
}
7992
catch (Exception e) {
8093
e.printStackTrace();

v1_13_R2/src/main/java/com/lishid/orebfuscator/nms/v1_13_R2/NmsManager.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.bukkit.Material;
1414
import org.bukkit.World;
1515
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
16+
import org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock;
1617
import org.bukkit.craftbukkit.v1_13_R2.block.data.CraftBlockData;
1718
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
1819
import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage;
@@ -24,6 +25,8 @@
2425
import com.lishid.orebfuscator.nms.INmsManager;
2526
import com.lishid.orebfuscator.types.BlockCoord;
2627

28+
import java.lang.reflect.InvocationTargetException;
29+
import java.lang.reflect.Method;
2730
import java.util.HashMap;
2831
import java.util.HashSet;
2932
import java.util.Set;
@@ -427,7 +430,16 @@ public IChunkCache createChunkCache() {
427430

428431
public void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
429432
CraftWorld world = (CraftWorld)player.getWorld();
430-
TileEntity tileEntity = world.getTileEntityAt(blockCoord.x, blockCoord.y, blockCoord.z);
433+
// 1.13.2 has made this quite a bit different in later builds.
434+
TileEntity tileEntity = null;
435+
try {
436+
Method getTileEntityAt = world.getClass().getMethod("getTileEntityAt", int.class, int.class, int.class);
437+
tileEntity = (TileEntity) getTileEntityAt.invoke(world, blockCoord.x, blockCoord.y, blockCoord.z);
438+
} catch (NoSuchMethodException nsme) {
439+
tileEntity = world.getHandle().getTileEntity(new BlockPosition(blockCoord.x, blockCoord.y, blockCoord.z));
440+
} catch (Exception e) {
441+
return;
442+
}
431443

432444
if (tileEntity == null) {
433445
return;
@@ -527,8 +539,23 @@ private static IBlockData getBlockData(World world, int x, int y, int z, boolean
527539
int chunkZ = z >> 4;
528540

529541
WorldServer worldServer = ((CraftWorld)world).getHandle();
530-
ChunkProviderServer chunkProviderServer = worldServer.getChunkProviderServer();
531-
542+
// like in ChunkCache, NMS change without R increment.
543+
ChunkProviderServer chunkProviderServer = null;
544+
try {
545+
Method getChunkProviderServer = worldServer.getClass().getDeclaredMethod("getChunkProviderServer");
546+
chunkProviderServer = (ChunkProviderServer) getChunkProviderServer.invoke(worldServer);
547+
} catch (NoSuchMethodException nmfe) {
548+
try {
549+
Method getChunkProvider = worldServer.getClass().getDeclaredMethod("getChunkProvider");
550+
chunkProviderServer = (ChunkProviderServer) getChunkProvider.invoke(worldServer);
551+
} catch (NoSuchMethodException nsme) {
552+
return null; // oops
553+
} catch (Exception e) {
554+
return null;
555+
}
556+
} catch (Exception e) {
557+
return null;
558+
}
532559
if(!loadChunk && !chunkProviderServer.isLoaded(chunkX, chunkZ)) return null;
533560

534561
Chunk chunk = chunkProviderServer.getChunkAt(chunkX, chunkZ, true, true);

0 commit comments

Comments
 (0)