From b2c92fe70f5db9250e3602aca3a4b67e709f6ee7 Mon Sep 17 00:00:00 2001 From: iiAhmedYT <61851106+iiAhmedYT@users.noreply.github.com> Date: Sun, 15 Dec 2024 18:25:24 +0200 Subject: [PATCH] Fix PacketEvents initial support? --- .../itsme/itsmyconfig/processor/PacketContent.java | 6 +++--- .../processor/packetevents/PEventsListener.java | 2 +- .../processor/packetevents/PEventsProcessor.java | 7 ++++--- .../processor/protocollib/PLibListener.java | 2 +- .../processor/protocollib/PLibProcessor.java | 12 ++++++------ 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/to/itsme/itsmyconfig/processor/PacketContent.java b/src/main/java/to/itsme/itsmyconfig/processor/PacketContent.java index d301772..cc8116f 100644 --- a/src/main/java/to/itsme/itsmyconfig/processor/PacketContent.java +++ b/src/main/java/to/itsme/itsmyconfig/processor/PacketContent.java @@ -2,10 +2,10 @@ import net.kyori.adventure.text.Component; -public record PacketContent(PacketProcessor form, String message) { +public record PacketContent(C container, PacketProcessor processor, String message) { - public void save(final C container, final Component component) { - this.form.edit(container, component); + public void save(final Component component) { + this.processor.edit(container, component); } public boolean isEmpty() { diff --git a/src/main/java/to/itsme/itsmyconfig/processor/packetevents/PEventsListener.java b/src/main/java/to/itsme/itsmyconfig/processor/packetevents/PEventsListener.java index 7af0cea..b97d0f7 100644 --- a/src/main/java/to/itsme/itsmyconfig/processor/packetevents/PEventsListener.java +++ b/src/main/java/to/itsme/itsmyconfig/processor/packetevents/PEventsListener.java @@ -72,7 +72,7 @@ public void onPacketSend(final PacketSendEvent event) { Utilities.debug(() -> "Final Product: " + AbstractComponent.parse(parsed).toMiniMessage() + "\n" + "Overriding..."); event.markForReEncode(true); - packet.save(event, parsed); + packet.save(parsed); Utilities.debug(() -> Strings.DEBUG_HYPHEN); } diff --git a/src/main/java/to/itsme/itsmyconfig/processor/packetevents/PEventsProcessor.java b/src/main/java/to/itsme/itsmyconfig/processor/packetevents/PEventsProcessor.java index db6134e..3dce460 100644 --- a/src/main/java/to/itsme/itsmyconfig/processor/packetevents/PEventsProcessor.java +++ b/src/main/java/to/itsme/itsmyconfig/processor/packetevents/PEventsProcessor.java @@ -6,6 +6,7 @@ import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSystemChatMessage; import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; +import to.itsme.itsmyconfig.component.AbstractComponent; import to.itsme.itsmyconfig.processor.PacketContent; import to.itsme.itsmyconfig.processor.PacketProcessor; @@ -25,7 +26,7 @@ public void edit(PacketSendEvent container, Component component) { @Override public @NotNull PacketContent unpack(PacketSendEvent container) { - return new PacketContent<>(this, new WrapperPlayServerChatMessage(container).readString()); + return new PacketContent<>(container,this, AbstractComponent.parse(new WrapperPlayServerChatMessage(container).getMessage().getChatContent()).toMiniMessage()); } }; @@ -44,7 +45,7 @@ public void edit(PacketSendEvent container, Component component) { @Override public @NotNull PacketContent unpack(PacketSendEvent container) { - return new PacketContent<>(this, new WrapperPlayServerSystemChatMessage(container).readString()); + return new PacketContent<>(container, this, AbstractComponent.parse(new WrapperPlayServerSystemChatMessage(container).getMessage()).toMiniMessage()); } }; @@ -63,7 +64,7 @@ public void edit(PacketSendEvent container, Component component) { @Override public @NotNull PacketContent unpack(PacketSendEvent container) { - return new PacketContent<>(this, new WrapperPlayServerDisconnect(container).readString()); + return new PacketContent<>(container, this, AbstractComponent.parse(new WrapperPlayServerDisconnect(container).getReason()).toMiniMessage()); } }; diff --git a/src/main/java/to/itsme/itsmyconfig/processor/protocollib/PLibListener.java b/src/main/java/to/itsme/itsmyconfig/processor/protocollib/PLibListener.java index 262631b..b2b0aa1 100644 --- a/src/main/java/to/itsme/itsmyconfig/processor/protocollib/PLibListener.java +++ b/src/main/java/to/itsme/itsmyconfig/processor/protocollib/PLibListener.java @@ -72,7 +72,7 @@ public void onPacketSending(final PacketEvent event) { } Utilities.debug(() -> "Final Product: " + AbstractComponent.parse(parsed).toMiniMessage() + "\n" + "Overriding..."); - packet.save(container, parsed); + packet.save(parsed); Utilities.debug(() -> Strings.DEBUG_HYPHEN); } diff --git a/src/main/java/to/itsme/itsmyconfig/processor/protocollib/PLibProcessor.java b/src/main/java/to/itsme/itsmyconfig/processor/protocollib/PLibProcessor.java index 5869e40..84b001d 100644 --- a/src/main/java/to/itsme/itsmyconfig/processor/protocollib/PLibProcessor.java +++ b/src/main/java/to/itsme/itsmyconfig/processor/protocollib/PLibProcessor.java @@ -37,7 +37,7 @@ public PacketContent unpack(PacketContainer container) { return null; } - return this.of(AbstractComponent.parse(component).toMiniMessage()); + return this.of(container, AbstractComponent.parse(component).toMiniMessage()); } }, @@ -63,7 +63,7 @@ public PacketContent unpack(PacketContainer container) { } try { - return this.of(AbstractComponent.parse(found).toMiniMessage()); + return this.of(container, AbstractComponent.parse(found).toMiniMessage()); } catch (final Exception e) { Utilities.debug(() -> "An error happened while de/serializing " + found + ": ", e); } @@ -85,7 +85,7 @@ public void edit(PacketContainer container, Component component) { public PacketContent unpack(PacketContainer container) { final StructureModifier textComponentModifier = container.getModifier().withType(TextComponent.class); if (textComponentModifier.size() == 1) { - return this.of(processBaseComponents(textComponentModifier.readSafely(0))); + return this.of(container, processBaseComponents(textComponentModifier.readSafely(0))); } return null; } @@ -109,13 +109,13 @@ public PacketContent unpack(final PacketContainer container) { if (rawMessage == null) { return null; } - return this.of(AbstractComponent.parse(rawMessage).toMiniMessage()); + return this.of(container, AbstractComponent.parse(rawMessage).toMiniMessage()); } }; - PacketContent of(final String message) { - return new PacketContent<>(this, message); + PacketContent of(final PacketContainer container, final String message) { + return new PacketContent<>(container, this, message); } }