Skip to content

Commit

Permalink
Fix PacketEvents initial support?
Browse files Browse the repository at this point in the history
  • Loading branch information
iiAhmedYT committed Dec 15, 2024
1 parent 96df6ef commit b2c92fe
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import net.kyori.adventure.text.Component;

public record PacketContent<C>(PacketProcessor<C> form, String message) {
public record PacketContent<C>(C container, PacketProcessor<C> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,7 +26,7 @@ public void edit(PacketSendEvent container, Component component) {

@Override
public @NotNull PacketContent<PacketSendEvent> unpack(PacketSendEvent container) {
return new PacketContent<>(this, new WrapperPlayServerChatMessage(container).readString());
return new PacketContent<>(container,this, AbstractComponent.parse(new WrapperPlayServerChatMessage(container).getMessage().getChatContent()).toMiniMessage());
}

};
Expand All @@ -44,7 +45,7 @@ public void edit(PacketSendEvent container, Component component) {

@Override
public @NotNull PacketContent<PacketSendEvent> unpack(PacketSendEvent container) {
return new PacketContent<>(this, new WrapperPlayServerSystemChatMessage(container).readString());
return new PacketContent<>(container, this, AbstractComponent.parse(new WrapperPlayServerSystemChatMessage(container).getMessage()).toMiniMessage());
}

};
Expand All @@ -63,7 +64,7 @@ public void edit(PacketSendEvent container, Component component) {

@Override
public @NotNull PacketContent<PacketSendEvent> unpack(PacketSendEvent container) {
return new PacketContent<>(this, new WrapperPlayServerDisconnect(container).readString());
return new PacketContent<>(container, this, AbstractComponent.parse(new WrapperPlayServerDisconnect(container).getReason()).toMiniMessage());
}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public PacketContent<PacketContainer> unpack(PacketContainer container) {
return null;
}

return this.of(AbstractComponent.parse(component).toMiniMessage());
return this.of(container, AbstractComponent.parse(component).toMiniMessage());
}
},

Expand All @@ -63,7 +63,7 @@ public PacketContent<PacketContainer> 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);
}
Expand All @@ -85,7 +85,7 @@ public void edit(PacketContainer container, Component component) {
public PacketContent<PacketContainer> unpack(PacketContainer container) {
final StructureModifier<TextComponent> 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;
}
Expand All @@ -109,13 +109,13 @@ public PacketContent<PacketContainer> 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<PacketContainer> of(final String message) {
return new PacketContent<>(this, message);
PacketContent<PacketContainer> of(final PacketContainer container, final String message) {
return new PacketContent<>(container, this, message);
}

}

0 comments on commit b2c92fe

Please sign in to comment.