mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
添加1.20.1-1.20.2容器标题拦截
This commit is contained in:
@@ -17,7 +17,6 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BukkitFontManager extends AbstractFontManager implements Listener {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.item;
|
||||
|
||||
import com.saicone.rtag.RtagItem;
|
||||
import net.kyori.adventure.Adventure;
|
||||
import net.kyori.adventure.text.NBTComponent;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.momirealms.craftengine.core.item.Enchantment;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -19,8 +18,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentItemFactory extends BukkitItemFactory {
|
||||
|
||||
@@ -154,6 +154,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
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() {
|
||||
|
||||
@@ -238,6 +238,35 @@ 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> LEVEL_PARTICLE = (user, event) -> {
|
||||
try {
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
|
||||
@@ -11,4 +11,6 @@ public interface PacketIds {
|
||||
int clientboundLevelEventPacket();
|
||||
|
||||
int clientboundAddEntityPacket();
|
||||
|
||||
int clientboundOpenScreenPacket();
|
||||
}
|
||||
|
||||
@@ -28,4 +28,10 @@ public class PacketIds1_20 implements PacketIds {
|
||||
public int clientboundAddEntityPacket() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO NOT TESTED
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,10 @@ public class PacketIds1_20_2 implements PacketIds {
|
||||
public int clientboundAddEntityPacket() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO NOT TESTED
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,10 @@ public class PacketIds1_20_3 implements PacketIds {
|
||||
public int clientboundAddEntityPacket() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO NOT TESTED
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,10 @@ public class PacketIds1_20_5 implements PacketIds {
|
||||
public int clientboundAddEntityPacket() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO NOT TESTED
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,9 @@ 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,4 +29,10 @@ public class PacketIds1_21_2 implements PacketIds {
|
||||
public int clientboundAddEntityPacket() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO NOT TESTED
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user