mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
修复声音
This commit is contained in:
@@ -150,11 +150,11 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
registerNMSPacketConsumer(PacketConsumers.EDIT_BOOK, Reflections.clazz$ServerboundEditBookPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.CUSTOM_PAYLOAD, Reflections.clazz$ServerboundCustomPayloadPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.SET_ENTITY_DATA, Reflections.clazz$ClientboundSetEntityDataPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.OPEN_SCREEN, Reflections.clazz$ClientboundOpenScreenPacket);
|
||||
registerByteBufPacketConsumer(PacketConsumers.SECTION_BLOCK_UPDATE, this.packetIds.clientboundSectionBlocksUpdatePacket());
|
||||
registerByteBufPacketConsumer(PacketConsumers.BLOCK_UPDATE, this.packetIds.clientboundBlockUpdatePacket());
|
||||
registerByteBufPacketConsumer(PacketConsumers.LEVEL_PARTICLE, this.packetIds.clientboundLevelParticlesPacket());
|
||||
registerByteBufPacketConsumer(PacketConsumers.LEVEL_EVENT, this.packetIds.clientboundLevelEventPacket());
|
||||
registerByteBufPacketConsumer(PacketConsumers.OPEN_SCREEN, this.packetIds.clientboundOpenScreenPacket());
|
||||
}
|
||||
|
||||
public static BukkitNetworkManager instance() {
|
||||
@@ -444,7 +444,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
}
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
plugin.logger().severe("An error occurred when reading packets", e);
|
||||
plugin.logger().severe("An error occurred when reading packets. Packet class: " + packet.getClass(), e);
|
||||
super.write(context, packet, channelPromise);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -29,6 +30,8 @@ import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.chunk.Palette;
|
||||
import net.momirealms.craftengine.core.world.chunk.PalettedContainer;
|
||||
import net.momirealms.craftengine.core.world.chunk.packet.MCSection;
|
||||
import net.momirealms.sparrow.nbt.NBT;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -238,34 +241,36 @@ public class PacketConsumers {
|
||||
}
|
||||
};
|
||||
|
||||
public static final BiConsumer<NetWorkUser, ByteBufPacketEvent> OPEN_SCREEN = (user, event) -> {
|
||||
try {
|
||||
if (VersionHelper.isVersionNewerThan1_20_3()) {
|
||||
|
||||
} else {
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
int containerId = buf.readVarInt();
|
||||
int type = buf.readVarInt();
|
||||
String json = buf.readUtf();
|
||||
Map<String, String> tokens = CraftEngine.instance().imageManager().matchTags(json);
|
||||
if (tokens.isEmpty()) return;
|
||||
event.setChanged(true);
|
||||
Component component = AdventureHelper.jsonToComponent(json);
|
||||
for (Map.Entry<String, String> token : tokens.entrySet()) {
|
||||
component = component.replaceText(b -> {
|
||||
b.matchLiteral(token.getKey()).replacement(AdventureHelper.miniMessage().deserialize(token.getValue()));
|
||||
});
|
||||
}
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeVarInt(containerId);
|
||||
buf.writeVarInt(type);
|
||||
buf.writeUtf(AdventureHelper.componentToJson(component));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundOpenScreenPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
// public static final BiConsumer<NetWorkUser, ByteBufPacketEvent> OPEN_SCREEN = (user, event) -> {
|
||||
// try {
|
||||
// if (VersionHelper.isVersionNewerThan1_20_3()) {
|
||||
// FriendlyByteBuf buf = event.getBuffer();
|
||||
// } else {
|
||||
// FriendlyByteBuf buf = event.getBuffer();
|
||||
// int containerId = buf.readVarInt();
|
||||
// int type = buf.readVarInt();
|
||||
// String json = buf.readUtf();
|
||||
// Map<String, String> tokens = CraftEngine.instance().imageManager().matchTags(json);
|
||||
// if (tokens.isEmpty()) return;
|
||||
// event.setChanged(true);
|
||||
// Component component = AdventureHelper.jsonToComponent(json);
|
||||
// for (Map.Entry<String, String> token : tokens.entrySet()) {
|
||||
// component = component.replaceText(b -> {
|
||||
// b.matchLiteral(token.getKey()).replacement(AdventureHelper.miniMessage().deserialize(token.getValue()));
|
||||
// });
|
||||
// }
|
||||
// buf.clear();
|
||||
// buf.writeVarInt(event.packetID());
|
||||
// buf.writeVarInt(containerId);
|
||||
// buf.writeVarInt(type);
|
||||
// buf.writeUtf(AdventureHelper.componentToJson(component));
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// CraftEngine.instance().logger().warn("Failed to handle ClientboundOpenScreenPacket", e);
|
||||
// }
|
||||
// };
|
||||
|
||||
public static final BiConsumer<NetWorkUser, ByteBufPacketEvent> LEVEL_PARTICLE = (user, event) -> {
|
||||
try {
|
||||
@@ -781,7 +786,8 @@ public class PacketConsumers {
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SOUND = (user, event, packet) -> {
|
||||
try {
|
||||
Object soundEvent = FastNMS.INSTANCE.field$ClientboundSoundPacket$soundEvent(packet);
|
||||
Key mapped = BukkitBlockManager.instance().replaceSoundIfExist(Key.of(FastNMS.INSTANCE.field$SoundEvent$location(soundEvent).toString()));
|
||||
Key soundId = Key.of(FastNMS.INSTANCE.field$SoundEvent$location(soundEvent).toString());
|
||||
Key mapped = BukkitBlockManager.instance().replaceSoundIfExist(soundId);
|
||||
if (mapped != null) {
|
||||
event.setCancelled(true);
|
||||
Object newId = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath(mapped.namespace(), mapped.value());
|
||||
@@ -1019,4 +1025,12 @@ public class PacketConsumers {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundSetEntityDataPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> OPEN_SCREEN = (user, event, packet) -> {
|
||||
try {
|
||||
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundOpenScreenPacket", e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,6 +11,4 @@ public interface PacketIds {
|
||||
int clientboundLevelEventPacket();
|
||||
|
||||
int clientboundAddEntityPacket();
|
||||
|
||||
int clientboundOpenScreenPacket();
|
||||
}
|
||||
|
||||
@@ -28,10 +28,4 @@ public class PacketIds1_20 implements PacketIds {
|
||||
public int clientboundAddEntityPacket() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO NOT TESTED
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,4 @@ public class PacketIds1_20_2 implements PacketIds {
|
||||
public int clientboundAddEntityPacket() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO NOT TESTED
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,4 @@ public class PacketIds1_20_3 implements PacketIds {
|
||||
public int clientboundAddEntityPacket() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO NOT TESTED
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,4 @@ public class PacketIds1_20_5 implements PacketIds {
|
||||
public int clientboundAddEntityPacket() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO NOT TESTED
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,4 @@ public class PacketIds1_21 implements PacketIds {
|
||||
public int clientboundAddEntityPacket() {
|
||||
return PacketIdFinder.clientboundByName("minecraft:add_entity");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return PacketIdFinder.clientboundByName("minecraft:open_screen");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,4 @@ public class PacketIds1_21_2 implements PacketIds {
|
||||
public int clientboundAddEntityPacket() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO NOT TESTED
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ byte_buddy_version=1.17.5
|
||||
ahocorasick_version=0.6.3
|
||||
snake_yaml_version=2.4
|
||||
anti_grief_version=0.13
|
||||
nms_helper_version=0.40
|
||||
nms_helper_version=0.42
|
||||
# Ignite Dependencies
|
||||
mixinextras_version=0.4.1
|
||||
mixin_version=0.15.2+mixin.0.8.7
|
||||
|
||||
Reference in New Issue
Block a user