mirror of
https://github.com/GeyserExtensionists/GeyserUtils.git
synced 2025-12-19 14:59:18 +00:00
fix sth
This commit is contained in:
@@ -15,7 +15,7 @@ public class NpcDialogueButton {
|
||||
private String text;
|
||||
private List<String> commands;
|
||||
private ButtonMode mode;
|
||||
|
||||
private boolean hasNextForm;
|
||||
public enum ButtonMode {
|
||||
BUTTON_MODE,
|
||||
ON_ENTER,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.zimzaza4.geyserutils.geyser;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundCustomPayloadPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundCustomPayloadPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundCustomPayloadPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
@@ -112,8 +112,7 @@ public class GeyserUtils implements Extension {
|
||||
if (button.mode() == NpcDialogueButton.ButtonMode.BUTTON_MODE) {
|
||||
session.sendDownstreamPacket(new ServerboundCustomPayloadPacket(GeyserUtilsChannels.MAIN, packetManager.encodePacket(new NpcFormResponseCustomPayloadPacket(formData.formId(), finalI))));
|
||||
}
|
||||
}
|
||||
));
|
||||
}, button.hasNextForm()));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@ public class Button {
|
||||
List<String> commands;
|
||||
NpcDialogueButton.ButtonMode mode;
|
||||
Runnable click;
|
||||
|
||||
|
||||
boolean hasNextForm;
|
||||
|
||||
public JsonObject toJsonObject() {
|
||||
JsonObject button = new JsonObject();
|
||||
|
||||
@@ -15,19 +15,22 @@ public class NPCFormResponseTranslator extends PacketTranslator<NpcRequestPacket
|
||||
@Override
|
||||
public void translate(GeyserSession geyserSession, NpcRequestPacket packet) {
|
||||
|
||||
// System.out.println(packet);
|
||||
NpcDialogueForm form = NpcDialogueForms.getOpenNpcDialogueForms(geyserSession);
|
||||
|
||||
if (form == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (form.dialogueButtons().isEmpty()) {
|
||||
if (packet.getRequestType().equals(NpcRequestType.EXECUTE_CLOSING_COMMANDS)) {
|
||||
NpcDialogueForms.removeNpcDialogueForm(geyserSession, form);
|
||||
}
|
||||
|
||||
if (packet.getSceneName().equals(form.sceneName())) {
|
||||
// System.out.println("CLOSE FORM");
|
||||
form.close(geyserSession);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Button button = form.dialogueButtons().get(packet.getActionType());
|
||||
@@ -36,14 +39,12 @@ public class NPCFormResponseTranslator extends PacketTranslator<NpcRequestPacket
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ((button.mode().equals(NpcDialogueButton.ButtonMode.ON_ENTER) && packet.getRequestType().equals(NpcRequestType.EXECUTE_OPENING_COMMANDS)) ||
|
||||
(button.mode().equals(NpcDialogueButton.ButtonMode.BUTTON_MODE) && packet.getRequestType().equals(NpcRequestType.EXECUTE_COMMAND_ACTION)) ||
|
||||
(button.mode().equals(NpcDialogueButton.ButtonMode.ON_EXIT) && packet.getRequestType().equals(NpcRequestType.EXECUTE_CLOSING_COMMANDS))) {
|
||||
if (button.mode().equals(NpcDialogueButton.ButtonMode.BUTTON_MODE) && packet.getRequestType().equals(NpcRequestType.EXECUTE_COMMAND_ACTION)) {
|
||||
button.click().run();
|
||||
if (!form.hasNextForm()) {
|
||||
if (!button.hasNextForm()) {
|
||||
form.close(geyserSession);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,22 @@ public final class GeyserUtils extends JavaPlugin {
|
||||
NpcFormResponseCustomPayloadPacket response = (NpcFormResponseCustomPayloadPacket) packet;
|
||||
if (NpcDialogueForm.FORMS.containsKey(response.getFormId())) {
|
||||
|
||||
BiConsumer<String, Integer> handler = NpcDialogueForm.FORMS.get(response.getFormId()).handler();
|
||||
if (handler != null) {
|
||||
handler.accept(response.getFormId(), response.getButtonId());
|
||||
NpcDialogueForm form = NpcDialogueForm.FORMS.get(response.getFormId());
|
||||
|
||||
if (form.handler() != null) {
|
||||
if (response.getButtonId() != -1) {
|
||||
form.handler().accept(response.getFormId(), response.getButtonId());
|
||||
}
|
||||
}
|
||||
if (response.getButtonId() == -1) {
|
||||
if (form.closeHandler() != null) {
|
||||
form.closeHandler().accept(response.getFormId());
|
||||
}
|
||||
NpcDialogueForm.FORMS.remove(response.getFormId());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@@ -38,6 +39,7 @@ public class NpcDialogueForm {
|
||||
boolean hasNextForm = false;
|
||||
List<NpcDialogueButton> buttons;
|
||||
BiConsumer<String, Integer> handler;
|
||||
Consumer<String> closeHandler;
|
||||
|
||||
public void send(FloodgatePlayer floodgatePlayer) {
|
||||
UUID formId = UUID.randomUUID();
|
||||
|
||||
Reference in New Issue
Block a user