mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 18:09:27 +00:00
@@ -82,8 +82,12 @@ public class BukkitCompatibilityManager implements CompatibilityManager {
|
||||
}
|
||||
// WorldEdit
|
||||
if (this.isPluginEnabled("FastAsyncWorldEdit")) {
|
||||
this.initFastAsyncWorldEditHook();
|
||||
logHook("FastAsyncWorldEdit");
|
||||
try {
|
||||
this.initFastAsyncWorldEditHook();
|
||||
logHook("FastAsyncWorldEdit");
|
||||
} catch (Exception e) {
|
||||
this.plugin.logger().warn("[Compatibility] Failed to initialize FastAsyncWorldEdit hook", e);
|
||||
}
|
||||
} else if (this.isPluginEnabled("WorldEdit")) {
|
||||
this.initWorldEditHook();
|
||||
logHook("WorldEdit");
|
||||
@@ -172,10 +176,28 @@ public class BukkitCompatibilityManager implements CompatibilityManager {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private void initFastAsyncWorldEditHook() {
|
||||
Plugin fastAsyncWorldEdit = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit");
|
||||
String version = VersionHelper.isPaper() ? fastAsyncWorldEdit.getPluginMeta().getVersion() : fastAsyncWorldEdit.getDescription().getVersion();
|
||||
if (!this.fastAsyncWorldEditVersionCheck(new int[]{2, 13, 0}, version)) {
|
||||
this.plugin.logger().warn("[Compatibility] FastAsyncWorldEdit version is too old, please update to 2.13.0 or newer");
|
||||
}
|
||||
new WorldEditBlockRegister(BukkitBlockManager.instance(), true);
|
||||
}
|
||||
|
||||
private boolean fastAsyncWorldEditVersionCheck(int[] target, String version) {
|
||||
String cleanVersion = version.split("-")[0];
|
||||
String[] parts = cleanVersion.split("\\.");
|
||||
for (int i = 0; i < target.length; i++) {
|
||||
if (i >= parts.length) return false;
|
||||
int currentPart = Integer.parseInt(parts[i]);
|
||||
if (currentPart > target[i]) return true;
|
||||
if (currentPart < target[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void initWorldEditHook() {
|
||||
WorldEditBlockRegister weBlockRegister = new WorldEditBlockRegister(BukkitBlockManager.instance(), false);
|
||||
try {
|
||||
|
||||
@@ -2083,9 +2083,9 @@ public class PacketConsumers {
|
||||
try {
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
ItemBuildContext context = ItemBuildContext.of((BukkitServerPlayer) user);
|
||||
int slot = buf.readVarInt();
|
||||
Object friendlyBuf = FastNMS.INSTANCE.constructor$FriendlyByteBuf(buf);
|
||||
ItemStack itemStack = FastNMS.INSTANCE.method$FriendlyByteBuf$readItem(friendlyBuf);
|
||||
int slot = buf.readVarInt();
|
||||
BukkitItemManager.instance().s2c(itemStack, context).ifPresent((newItemStack) -> {
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
@@ -2290,7 +2290,7 @@ public class PacketConsumers {
|
||||
private static BukkitNetworkManager.Handlers simpleAddEntityHandler(EntityPacketHandler handler) {
|
||||
return (user, event) -> {
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
user.entityPacketHandlers().put(buf.readVarInt(), handler);
|
||||
user.entityPacketHandlers().putIfAbsent(buf.readVarInt(), handler);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3604,7 +3604,7 @@ public class Reflections {
|
||||
|
||||
public static final Field field$FallingBlockEntity$blockState = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(
|
||||
clazz$FallingBlockEntity, clazz$BlockState, 0
|
||||
clazz$FallingBlockEntity, clazz$BlockState, VersionHelper.isOrAbove1_21_5() ? 1 : 0
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
"target": "@env(DEFAULT)",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"server": [
|
||||
"BlocksMixin",
|
||||
"ItemStackMixin"
|
||||
"BlocksMixin"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user