mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-02-15 01:01:20 +01:00
Access block byte data method in 1.13
This commit is contained in:
parent
576ad7f3c9
commit
3cb9588158
@ -97,13 +97,13 @@ public class BCauldron {
|
|||||||
byte data = block.getData();
|
byte data = block.getData();
|
||||||
if (data > 3) {
|
if (data > 3) {
|
||||||
data = 3;
|
data = 3;
|
||||||
block.setData(data);
|
LegacyUtil.setData(block, data);
|
||||||
} else if (data <= 0) {
|
} else if (data <= 0) {
|
||||||
bcauldrons.remove(bcauldron);
|
bcauldrons.remove(bcauldron);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
data -= 1;
|
data -= 1;
|
||||||
block.setData(data);
|
LegacyUtil.setData(block, data);
|
||||||
|
|
||||||
if (data == 0) {
|
if (data == 0) {
|
||||||
bcauldrons.remove(bcauldron);
|
bcauldrons.remove(bcauldron);
|
||||||
|
@ -2,6 +2,7 @@ package com.dre.brewery;
|
|||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.TreeSpecies;
|
import org.bukkit.TreeSpecies;
|
||||||
@ -18,12 +19,14 @@ public class LegacyUtil {
|
|||||||
|
|
||||||
private static Method GET_MATERIAL;
|
private static Method GET_MATERIAL;
|
||||||
private static Method GET_BLOCK_TYPE_ID_AT;
|
private static Method GET_BLOCK_TYPE_ID_AT;
|
||||||
|
private static Method SET_DATA;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
GET_MATERIAL = Material.class.getDeclaredMethod("getMaterial", int.class);
|
GET_MATERIAL = Material.class.getDeclaredMethod("getMaterial", int.class);
|
||||||
GET_BLOCK_TYPE_ID_AT = World.class.getDeclaredMethod("getBlockTypeIdAt", Location.class);
|
GET_BLOCK_TYPE_ID_AT = World.class.getDeclaredMethod("getBlockTypeIdAt", Location.class);
|
||||||
} catch (NoSuchMethodException | SecurityException ex) {
|
SET_DATA = Class.forName(Bukkit.getServer().getClass().getPackage().getName() + ".block.CraftBlock").getDeclaredMethod("setData", byte.class);
|
||||||
|
} catch (NoSuchMethodException | SecurityException | ClassNotFoundException ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,4 +178,12 @@ public class LegacyUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setting byte data to blocks works in 1.13, but isn't part of the API anymore
|
||||||
|
public static void setData(Block block, byte data) {
|
||||||
|
try {
|
||||||
|
SET_DATA.invoke(block, data);
|
||||||
|
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user