packets: Add packets for dialogs

This commit is contained in:
Oliver
2025-05-31 08:53:13 +02:00
committed by Oliver
parent 9ca20c6f01
commit 458a0343d8
6 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package de.oliver.fancysitula.versions.v1_21_6.packets;
import de.oliver.fancysitula.api.entities.FS_RealPlayer;
import de.oliver.fancysitula.api.packets.FS_ClientboundClearDialogPacket;
import de.oliver.fancysitula.versions.v1_21_6.utils.VanillaPlayerAdapter;
import net.minecraft.network.protocol.common.ClientboundClearDialogPacket;
import net.minecraft.server.level.ServerPlayer;
public class ClientboundClearDialogPacketImpl extends FS_ClientboundClearDialogPacket {
@Override
public Object createPacket() {
return ClientboundClearDialogPacket.INSTANCE;
}
@Override
protected void sendPacketTo(FS_RealPlayer player) {
ClientboundClearDialogPacket packet = (ClientboundClearDialogPacket) createPacket();
ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer());
vanillaPlayer.connection.send(packet);
}
}

View File

@@ -0,0 +1,35 @@
package de.oliver.fancysitula.versions.v1_21_6.packets;
import de.oliver.fancysitula.api.dialogs.FS_Dialog;
import de.oliver.fancysitula.api.entities.FS_RealPlayer;
import de.oliver.fancysitula.api.packets.FS_ClientboundShowDialogPacket;
import de.oliver.fancysitula.versions.v1_21_6.utils.VanillaPlayerAdapter;
import net.minecraft.core.Holder;
import net.minecraft.network.protocol.common.ClientboundShowDialogPacket;
import net.minecraft.server.dialog.Dialog;
import net.minecraft.server.level.ServerPlayer;
public class ClientboundShowDialogPacketImpl extends FS_ClientboundShowDialogPacket {
public ClientboundShowDialogPacketImpl(FS_Dialog dialog) {
super(dialog);
}
@Override
public Object createPacket() {
Holder<Dialog> holder = Holder.direct(toNms(dialog));
return new ClientboundShowDialogPacket(holder);
}
@Override
protected void sendPacketTo(FS_RealPlayer player) {
ClientboundShowDialogPacket packet = (ClientboundShowDialogPacket) createPacket();
ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer());
vanillaPlayer.connection.send(packet);
}
private Dialog toNms(FS_Dialog dialog) {
return null;
}
}

View File

@@ -0,0 +1,4 @@
package de.oliver.fancysitula.api.dialogs;
public interface FS_Dialog {
}

View File

@@ -0,0 +1,4 @@
package de.oliver.fancysitula.api.packets;
public abstract class FS_ClientboundClearDialogPacket extends FS_ClientboundPacket {
}

View File

@@ -0,0 +1,20 @@
package de.oliver.fancysitula.api.packets;
import de.oliver.fancysitula.api.dialogs.FS_Dialog;
public abstract class FS_ClientboundShowDialogPacket extends FS_ClientboundPacket {
protected FS_Dialog dialog;
public FS_ClientboundShowDialogPacket(FS_Dialog dialog) {
this.dialog = dialog;
}
public FS_Dialog getDialog() {
return dialog;
}
public void setDialog(FS_Dialog dialog) {
this.dialog = dialog;
}
}

View File

@@ -1,5 +1,6 @@
package de.oliver.fancysitula.factories;
import de.oliver.fancysitula.api.dialogs.FS_Dialog;
import de.oliver.fancysitula.api.packets.*;
import de.oliver.fancysitula.api.utils.FS_EquipmentSlot;
import de.oliver.fancysitula.api.utils.ServerVersion;
@@ -477,4 +478,37 @@ public class PacketFactory {
throw new IllegalArgumentException("Unsupported server version: " + ServerVersion.getCurrentVersion());
}
}
/**
* Creates a new FS_ClientboundShowDialogPacket instance based on the server version
*
* @param dialog The dialog to show
* @return An instance of FS_ClientboundShowDialogPacket for the specified server version
*/
public FS_ClientboundShowDialogPacket createShowDialogPacket(
FS_Dialog dialog
) {
switch (ServerVersion.getCurrentVersion()) {
case v1_21_6 -> {
return new de.oliver.fancysitula.versions.v1_21_6.packets.ClientboundShowDialogPacketImpl(dialog);
}
default ->
throw new IllegalArgumentException("Unsupported server version: " + ServerVersion.getCurrentVersion());
}
}
/**
* Creates a new FS_ClientboundClearDialogPacket instance based on the server version
*
* @return An instance of FS_ClientboundClearDialogPacket for the specified server version
*/
public FS_ClientboundClearDialogPacket createClearDialogPacket() {
switch (ServerVersion.getCurrentVersion()) {
case v1_21_6 -> {
return new de.oliver.fancysitula.versions.v1_21_6.packets.ClientboundClearDialogPacketImpl();
}
default ->
throw new IllegalArgumentException("Unsupported server version: " + ServerVersion.getCurrentVersion());
}
}
}