mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 11:29:17 +00:00
0.0.55
This commit is contained in:
@@ -19,6 +19,10 @@ dependencies {
|
||||
compileOnly("net.momirealms:antigrieflib:${rootProject.properties["anti_grief_version"]}")
|
||||
// NBT
|
||||
compileOnly("net.momirealms:sparrow-nbt:${rootProject.properties["sparrow_nbt_version"]}")
|
||||
compileOnly("net.momirealms:sparrow-nbt-adventure:${rootProject.properties["sparrow_nbt_version"]}")
|
||||
compileOnly("net.momirealms:sparrow-nbt-codec:${rootProject.properties["sparrow_nbt_version"]}")
|
||||
compileOnly("net.momirealms:sparrow-nbt-legacy-codec:${rootProject.properties["sparrow_nbt_version"]}")
|
||||
// Util
|
||||
compileOnly("net.momirealms:sparrow-util:${rootProject.properties["sparrow_util_version"]}")
|
||||
// NMS
|
||||
compileOnly("net.momirealms:craft-engine-nms-helper:${rootProject.properties["nms_helper_version"]}")
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.momirealms.craftengine.bukkit.item;
|
||||
|
||||
import com.saicone.rtag.RtagItem;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
@@ -32,13 +33,7 @@ public class LegacyItemWrapper implements ItemWrapper<ItemStack> {
|
||||
|
||||
public boolean setTag(Object value, Object... path) {
|
||||
if (value instanceof Tag tag) {
|
||||
try {
|
||||
Object nmsTag = FastNMS.INSTANCE.method$NbtIo$fromBytes(NBT.toBytes(tag, true));
|
||||
return this.rtagItem.set(nmsTag, path);
|
||||
} catch (IOException e) {
|
||||
CraftEngine.instance().logger().warn("Failed to set NBT tag " + Arrays.toString(path), e);
|
||||
return false;
|
||||
}
|
||||
return this.rtagItem.set(Reflections.instance$SPARROW_NBT_OPS.convertTo(Reflections.instance$NBT_OPS, tag), path);
|
||||
} else {
|
||||
return this.rtagItem.set(value, path);
|
||||
}
|
||||
@@ -46,15 +41,7 @@ public class LegacyItemWrapper implements ItemWrapper<ItemStack> {
|
||||
|
||||
public boolean add(Object value, Object... path) {
|
||||
if (value instanceof Tag tag) {
|
||||
try {
|
||||
// Incompatible DFU version
|
||||
// return this.rtagItem.add(Reflections.instance$SPARROW_NBT_OPS.convertTo(Reflections.instance$NBT_OPS, tag), path);
|
||||
Object nmsTag = FastNMS.INSTANCE.method$NbtIo$fromBytes(NBT.toBytes(tag, true));
|
||||
return this.rtagItem.add(nmsTag, path);
|
||||
} catch (IOException e) {
|
||||
CraftEngine.instance().logger().warn("Failed to add NBT tag " + Arrays.toString(path), e);
|
||||
return false;
|
||||
}
|
||||
return this.rtagItem.add(Reflections.instance$SPARROW_NBT_OPS.convertTo(Reflections.instance$NBT_OPS, tag), path);
|
||||
} else {
|
||||
return this.rtagItem.add(value, path);
|
||||
}
|
||||
@@ -67,12 +54,7 @@ public class LegacyItemWrapper implements ItemWrapper<ItemStack> {
|
||||
public Tag getNBTTag(Object... path) {
|
||||
Object tag = getExactTag(path);
|
||||
if (tag == null) return null;
|
||||
try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(FastNMS.INSTANCE.method$NbtIo$toBytes(tag)))) {
|
||||
return NBT.readUnnamedTag(dis, !VersionHelper.isOrAbove1_20_3());
|
||||
} catch (IOException e) {
|
||||
CraftEngine.instance().logger().warn("Failed to read NBT tag " + Arrays.toString(path), e);
|
||||
return null;
|
||||
}
|
||||
return Reflections.instance$NBT_OPS.convertTo(Reflections.instance$SPARROW_NBT_OPS, tag);
|
||||
}
|
||||
|
||||
public int count() {
|
||||
|
||||
@@ -565,17 +565,25 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
}
|
||||
|
||||
private boolean handleCompression(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
if (handledCompression) return false;
|
||||
if (this.handledCompression) return false;
|
||||
int compressIndex = ctx.pipeline().names().indexOf("compress");
|
||||
if (compressIndex == -1) return false;
|
||||
handledCompression = true;
|
||||
this.handledCompression = true;
|
||||
int encoderIndex = ctx.pipeline().names().indexOf(PACKET_ENCODER);
|
||||
if (encoderIndex == -1) return false;
|
||||
if (compressIndex > encoderIndex) {
|
||||
decompress(ctx, buffer, buffer);
|
||||
PluginChannelDecoder decoder = (PluginChannelDecoder) ctx.pipeline().get(PACKET_DECODER);
|
||||
if (decoder != null) {
|
||||
if (decoder.relocated) return true;
|
||||
decoder.relocated = true;
|
||||
}
|
||||
PluginChannelEncoder encoder = (PluginChannelEncoder) ctx.pipeline().remove(PACKET_ENCODER);
|
||||
String encoderName = ctx.pipeline().names().contains("outbound_config") ? "outbound_config" : "encoder";
|
||||
ctx.pipeline().addBefore(encoderName, PACKET_ENCODER, new PluginChannelEncoder(encoder));
|
||||
decoder = (PluginChannelDecoder) ctx.pipeline().remove(PACKET_DECODER);
|
||||
String decoderName = ctx.pipeline().names().contains("inbound_config") ? "inbound_config" : "decoder";
|
||||
ctx.pipeline().addBefore(decoderName, PACKET_DECODER, new PluginChannelDecoder(decoder));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -608,7 +616,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
|
||||
public class PluginChannelDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||
private final NetWorkUser player;
|
||||
private boolean handledCompression = false;
|
||||
public boolean relocated = false;
|
||||
|
||||
public PluginChannelDecoder(NetWorkUser player) {
|
||||
this.player = player;
|
||||
@@ -616,38 +624,17 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
|
||||
public PluginChannelDecoder(PluginChannelDecoder decoder) {
|
||||
this.player = decoder.player;
|
||||
this.handledCompression = decoder.handledCompression;
|
||||
this.relocated = decoder.relocated;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) {
|
||||
boolean needCompression = !handledCompression && handleCompression(channelHandlerContext, byteBuf);
|
||||
this.onByteBufReceive(byteBuf);
|
||||
if (needCompression) {
|
||||
compress(channelHandlerContext, byteBuf);
|
||||
}
|
||||
if (byteBuf.isReadable()) {
|
||||
list.add(byteBuf.retain());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean handleCompression(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
if (handledCompression) return false;
|
||||
int compressIndex = ctx.pipeline().names().indexOf("compress");
|
||||
if (compressIndex == -1) return false;
|
||||
handledCompression = true;
|
||||
int decoderIndex = ctx.pipeline().names().indexOf(PACKET_DECODER);
|
||||
if (decoderIndex == -1) return false;
|
||||
if (compressIndex > decoderIndex) {
|
||||
decompress(ctx, buffer, buffer);
|
||||
PluginChannelDecoder encoder = (PluginChannelDecoder) ctx.pipeline().remove(PACKET_DECODER);
|
||||
String decoderName = ctx.pipeline().names().contains("inbound_config") ? "inbound_config" : "decoder";
|
||||
ctx.pipeline().addBefore(decoderName, PACKET_DECODER, new PluginChannelDecoder(encoder));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onByteBufReceive(ByteBuf buffer) {
|
||||
// I don't care packets before PLAY for the moment
|
||||
if (player.decoderState() != ConnectionState.PLAY) return;
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.core.util.ReflectionUtils;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import net.momirealms.sparrow.nbt.codec.LegacyNBTOps;
|
||||
import net.momirealms.sparrow.nbt.codec.NBTOps;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.BlockState;
|
||||
@@ -6969,7 +6970,7 @@ public class Reflections {
|
||||
instance$JAVA_OPS = null;
|
||||
}
|
||||
instance$JSON_OPS = (DynamicOps<JsonElement>) method$RegistryOps$create.invoke(null, JsonOps.INSTANCE, instance$MinecraftRegistry);
|
||||
instance$SPARROW_NBT_OPS = (DynamicOps<Tag>) method$RegistryOps$create.invoke(null, NBTOps.INSTANCE, instance$MinecraftRegistry);
|
||||
instance$SPARROW_NBT_OPS = (DynamicOps<Tag>) method$RegistryOps$create.invoke(null, VersionHelper.isOrAbove1_20_5() ? NBTOps.INSTANCE : LegacyNBTOps.INSTANCE, instance$MinecraftRegistry);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ dependencies {
|
||||
compileOnly("org.yaml:snakeyaml:${rootProject.properties["snake_yaml_version"]}")
|
||||
// NBT
|
||||
implementation("net.momirealms:sparrow-nbt:${rootProject.properties["sparrow_nbt_version"]}")
|
||||
implementation("net.momirealms:sparrow-nbt-adventure:${rootProject.properties["sparrow_nbt_version"]}")
|
||||
implementation("net.momirealms:sparrow-nbt-codec:${rootProject.properties["sparrow_nbt_version"]}")
|
||||
implementation("net.momirealms:sparrow-nbt-legacy-codec:${rootProject.properties["sparrow_nbt_version"]}")
|
||||
// Util
|
||||
compileOnly("net.momirealms:sparrow-util:${rootProject.properties["sparrow_util_version"]}")
|
||||
// Adventure
|
||||
// TODO Create an API module
|
||||
|
||||
@@ -12,8 +12,8 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.json.JSONOptions;
|
||||
import net.kyori.adventure.text.serializer.json.legacyimpl.NBTLegacyHoverEventSerializer;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import net.momirealms.sparrow.nbt.serializer.NBTComponentSerializer;
|
||||
import net.momirealms.sparrow.nbt.serializer.NBTSerializerOptions;
|
||||
import net.momirealms.sparrow.nbt.adventure.NBTComponentSerializer;
|
||||
import net.momirealms.sparrow.nbt.adventure.NBTSerializerOptions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=0.0.54.12
|
||||
project_version=0.0.55
|
||||
config_version=34
|
||||
lang_version=14
|
||||
project_group=net.momirealms
|
||||
@@ -39,7 +39,7 @@ geantyref_version=1.3.16
|
||||
zstd_version=1.5.7-2
|
||||
commons_io_version=2.18.0
|
||||
commons_imaging_version=1.0.0-alpha6
|
||||
sparrow_nbt_version=0.8.4
|
||||
sparrow_nbt_version=0.9.0
|
||||
sparrow_util_version=0.47
|
||||
fastutil_version=8.5.15
|
||||
netty_version=4.1.121.Final
|
||||
|
||||
Reference in New Issue
Block a user