Skip to content

Commit fdeb7c6

Browse files
Minimal fix for Drone in 1.13
The deprecated Block.setTypeIdAndData method that the Drone was using was finally removed from the Bukkit API as part of the 1.13 update. There is no longer a method on the Block interface that can work with the old numeric block IDs. Fortunately, CraftBukkit/Spigot now has a `CraftEvil` class offering a static `setTypeIdAndData` method that maps the old IDs to the new API. It is definitely not future-proof but allows us to run on 1.13 until we come up with a way to use the more recent API without breaking a lot of existing ScriptCraft code. This patch simply detects when the `Block.setTypeIdAndData` is missing and tries to use the `CraftEvil` class instead.
1 parent 0a6fe18 commit fdeb7c6

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

src/main/js/modules/drone/index.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,33 @@ function getDirFromRotation(location) {
326326
if (r > 225 && r <= 315) return 0; // east
327327
return 1; // south
328328
}
329+
330+
var setTypeIdAndData = makeTypeIdAndDataSetter();
331+
332+
function makeTypeIdAndDataSetter() {
333+
if (!__plugin.bukkit) {
334+
return null;
335+
}
336+
337+
var Block = Java.type('org.bukkit.block.Block');
338+
if (
339+
Java.from(Block.class.methods).some(function(m) {
340+
return m.name == 'setTypeIdAndData';
341+
})
342+
) {
343+
console.log('Drone using Block.setTypeIdAndData method');
344+
return function(block, typeId, data, applyPhysics) {
345+
block.setTypeIdAndData(typeId, data, applyPhysics);
346+
};
347+
} else {
348+
console.log('Drone using CraftEvil.setTypeIdAndData method');
349+
var CraftEvil = Java.type(server.class.package.name + '.util.CraftEvil');
350+
return function(block, typeId, data, applyPhysics) {
351+
CraftEvil.setTypeIdAndData(block, typeId, data, applyPhysics);
352+
};
353+
}
354+
}
355+
329356
/*
330357
low-level function to place a block in the world - all drone methods which
331358
place blocks ultimately invoke this function.
@@ -349,8 +376,7 @@ function putBlock(x, y, z, blockId, metadata, world, update) {
349376
}
350377
}
351378
if (__plugin.bukkit) {
352-
block.setTypeIdAndData(blockId, metadata, false);
353-
block.data = metadata;
379+
setTypeIdAndData(block, blockId, metadata, update);
354380
}
355381
return block;
356382
}

0 commit comments

Comments
 (0)