feat: hacks for 26.1.2

This commit is contained in:
ArikSquad committed 2026-05-05 19:03:02 +03:00
1 parent 7b44ea93ba
commit 148b3cf6f0
5 files changed
+93 -20

No files matched your search

@@ -19,6 +19,7 @@ package com.dfsek.terra.bukkit.handles;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -29,6 +30,9 @@ import com.dfsek.terra.api.handle.WorldHandle;
import com.dfsek.terra.bukkit.util.BukkitUtils;
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class BukkitWorldHandle implements WorldHandle {
private static final Logger logger = LoggerFactory.getLogger(BukkitWorldHandle.class);
@@ -40,9 +44,19 @@ public class BukkitWorldHandle implements WorldHandle {
@Override
public synchronized @NotNull BlockState createBlockState(@NotNull String data) {
org.bukkit.block.data.BlockData bukkitData = Bukkit.createBlockData(
data); // somehow bukkit managed to make this not thread safe! :)
return BukkitBlockState.newInstance(bukkitData);
try {
org.bukkit.block.data.BlockData bukkitData = Bukkit.createBlockData(data); // somehow bukkit managed to make this not thread safe! :)
return BukkitBlockState.newInstance(bukkitData);
} catch (Exception ignored) {
try {
Class<?> hacks = Class.forName("com.dfsek.terra.bukkit.nms.AwfulBukkitHacks");
Method method = hacks.getMethod("createBlockState", String.class);
Object result = method.invoke(null, data);
return BukkitBlockState.newInstance((BlockData) result);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException("Invalid block state data: " + data);
}
}
}
@Override
@@ -23,6 +23,13 @@ public class BukkitUtils {
if(!id.startsWith("minecraft:")) throw new IllegalArgumentException("Invalid entity identifier " + id);
String entityID = id.toUpperCase(Locale.ROOT).substring(10);
// TODO: remove this
// the default end seems to use this, this should be removed otherwise
// or replaced by a proper entity & NBT loader
if (entityID.contains("END_CRYSTAL")) {
entityID = "END_CRYSTAL";
}
return new BukkitEntityType(switch(entityID) {
case "END_CRYSTAL" -> org.bukkit.entity.EntityType.END_CRYSTAL;
case "ENDER_CRYSTAL" -> throw new IllegalArgumentException(