mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
packets: Add support for notice dialogs
This commit is contained in:
@@ -1,13 +1,43 @@
|
||||
package de.oliver.fancysitula.versions.v1_21_6.packets;
|
||||
|
||||
import de.oliver.fancysitula.api.dialogs.FS_CommonDialogData;
|
||||
import de.oliver.fancysitula.api.dialogs.FS_Dialog;
|
||||
import de.oliver.fancysitula.api.dialogs.FS_DialogAction;
|
||||
import de.oliver.fancysitula.api.dialogs.actions.FS_CommonButtonData;
|
||||
import de.oliver.fancysitula.api.dialogs.actions.FS_DialogActionButton;
|
||||
import de.oliver.fancysitula.api.dialogs.actions.FS_DialogRunCommandAction;
|
||||
import de.oliver.fancysitula.api.dialogs.body.FS_DialogBody;
|
||||
import de.oliver.fancysitula.api.dialogs.body.FS_DialogItemBody;
|
||||
import de.oliver.fancysitula.api.dialogs.body.FS_DialogTextBody;
|
||||
import de.oliver.fancysitula.api.dialogs.inputs.FS_DialogBooleanInput;
|
||||
import de.oliver.fancysitula.api.dialogs.inputs.FS_DialogInput;
|
||||
import de.oliver.fancysitula.api.dialogs.inputs.FS_DialogNumberRangeInput;
|
||||
import de.oliver.fancysitula.api.dialogs.inputs.FS_DialogSingleOptionInput;
|
||||
import de.oliver.fancysitula.api.dialogs.types.FS_NoticeDialog;
|
||||
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 io.papermc.paper.adventure.PaperAdventure;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.common.ClientboundShowDialogPacket;
|
||||
import net.minecraft.server.dialog.Dialog;
|
||||
import net.minecraft.server.dialog.*;
|
||||
import net.minecraft.server.dialog.action.Action;
|
||||
import net.minecraft.server.dialog.action.CommandTemplate;
|
||||
import net.minecraft.server.dialog.body.DialogBody;
|
||||
import net.minecraft.server.dialog.body.ItemBody;
|
||||
import net.minecraft.server.dialog.body.PlainMessage;
|
||||
import net.minecraft.server.dialog.input.BooleanInput;
|
||||
import net.minecraft.server.dialog.input.InputControl;
|
||||
import net.minecraft.server.dialog.input.NumberRangeInput;
|
||||
import net.minecraft.server.dialog.input.SingleOptionInput;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ClientboundShowDialogPacketImpl extends FS_ClientboundShowDialogPacket {
|
||||
|
||||
@@ -30,6 +60,149 @@ public class ClientboundShowDialogPacketImpl extends FS_ClientboundShowDialogPac
|
||||
}
|
||||
|
||||
private Dialog toNms(FS_Dialog dialog) {
|
||||
if (dialog instanceof FS_NoticeDialog notice) {
|
||||
return noticeToNms(notice);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Dialog noticeToNms(FS_NoticeDialog notice) {
|
||||
CommonDialogData common = commonToNms(notice.getDialogData());
|
||||
ActionButton actionButton = actionButtonToNms(notice.getActionButton());
|
||||
|
||||
return new NoticeDialog(common, actionButton);
|
||||
}
|
||||
|
||||
private CommonDialogData commonToNms(FS_CommonDialogData dialogData) {
|
||||
Component title = PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(dialogData.getTitle()));
|
||||
|
||||
Optional<Component> externalTitle = dialogData.getExternalTitle() != null ?
|
||||
Optional.of(PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(dialogData.getExternalTitle()))) :
|
||||
Optional.empty();
|
||||
|
||||
return new CommonDialogData(
|
||||
title,
|
||||
externalTitle,
|
||||
dialogData.isCanCloseWithEscape(),
|
||||
dialogData.isPause(),
|
||||
actionToNms(dialogData.getAfterAction()),
|
||||
bodyToNms(dialogData.getBody()),
|
||||
inputsToNms(dialogData.getInputs())
|
||||
);
|
||||
}
|
||||
|
||||
private DialogAction actionToNms(FS_DialogAction dialogAction) {
|
||||
return switch (dialogAction) {
|
||||
case CLOSE -> DialogAction.CLOSE;
|
||||
case NONE -> DialogAction.NONE;
|
||||
case WAIT_FOR_RESPONSE -> DialogAction.WAIT_FOR_RESPONSE;
|
||||
};
|
||||
}
|
||||
|
||||
private List<DialogBody> bodyToNms(List<FS_DialogBody> bodies) {
|
||||
List<DialogBody> nmsBodies = new ArrayList<>();
|
||||
|
||||
for (FS_DialogBody body : bodies) {
|
||||
if (body instanceof FS_DialogTextBody textBody) {
|
||||
nmsBodies.add(new PlainMessage(
|
||||
PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(textBody.getText())),
|
||||
textBody.getWidth()
|
||||
));
|
||||
} else if (body instanceof FS_DialogItemBody itemBody) {
|
||||
Optional<PlainMessage> description = itemBody.getDescription() != null ?
|
||||
Optional.of(new PlainMessage(
|
||||
PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(itemBody.getDescription().getText())),
|
||||
itemBody.getDescription().getWidth()
|
||||
)) :
|
||||
Optional.empty();
|
||||
|
||||
nmsBodies.add(new ItemBody(
|
||||
CraftItemStack.asNMSCopy(itemBody.getItem()),
|
||||
description,
|
||||
itemBody.isShowDecorations(),
|
||||
itemBody.isShowTooltip(),
|
||||
itemBody.getWidth(),
|
||||
itemBody.getHeight()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return nmsBodies;
|
||||
}
|
||||
|
||||
private List<Input> inputsToNms(List<FS_DialogInput> inputs) {
|
||||
List<Input> nmsInputs = new ArrayList<>();
|
||||
|
||||
for (FS_DialogInput input : inputs) {
|
||||
String key = input.getKey();
|
||||
|
||||
InputControl control = null;
|
||||
if (input.getControl() instanceof FS_DialogBooleanInput booleanInput) {
|
||||
control = new BooleanInput(
|
||||
PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(booleanInput.getLabel())),
|
||||
booleanInput.isInitial(),
|
||||
booleanInput.getOnTrue(),
|
||||
booleanInput.getOnFalse()
|
||||
);
|
||||
} else if (input.getControl() instanceof FS_DialogNumberRangeInput numberRangeInput) {
|
||||
control = new NumberRangeInput(
|
||||
numberRangeInput.getWidth(),
|
||||
PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(numberRangeInput.getLabel())),
|
||||
numberRangeInput.getLabelFormat(),
|
||||
new NumberRangeInput.RangeInfo(
|
||||
numberRangeInput.getStart(),
|
||||
numberRangeInput.getEnd(),
|
||||
numberRangeInput.getInitial() != null ? Optional.of(numberRangeInput.getInitial()) : Optional.empty(),
|
||||
numberRangeInput.getStep() != null ? Optional.of(numberRangeInput.getStep()) : Optional.empty()
|
||||
)
|
||||
);
|
||||
} else if (input.getControl() instanceof FS_DialogSingleOptionInput singleOptionInput) {
|
||||
List<SingleOptionInput.Entry> nmsEntries = new ArrayList<>();
|
||||
for (FS_DialogSingleOptionInput.Entry entry : singleOptionInput.getEntries()) {
|
||||
nmsEntries.add(new SingleOptionInput.Entry(
|
||||
entry.getId(),
|
||||
entry.getDisplay() != null ? Optional.of(PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(entry.getDisplay()))) : Optional.empty(),
|
||||
entry.isInitial()
|
||||
));
|
||||
}
|
||||
|
||||
control = new SingleOptionInput(
|
||||
singleOptionInput.getWidth(),
|
||||
nmsEntries,
|
||||
PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(singleOptionInput.getLabel())),
|
||||
singleOptionInput.isLabelVisible()
|
||||
);
|
||||
}
|
||||
|
||||
nmsInputs.add(new Input(key, control));
|
||||
}
|
||||
|
||||
return nmsInputs;
|
||||
}
|
||||
|
||||
private ActionButton actionButtonToNms(FS_DialogActionButton actionButton) {
|
||||
CommonButtonData buttonData = commonButtonDataToNms(actionButton.getButtonData());
|
||||
|
||||
Action action = null;
|
||||
if (actionButton.getAction() instanceof FS_DialogRunCommandAction runCommandAction) {
|
||||
action = new CommandTemplate(null); // TODO: Fix this
|
||||
}
|
||||
|
||||
Optional<Action> optionalAction = action != null ?
|
||||
Optional.of(action) :
|
||||
Optional.empty();
|
||||
|
||||
return new ActionButton(buttonData, optionalAction);
|
||||
}
|
||||
|
||||
private CommonButtonData commonButtonDataToNms(FS_CommonButtonData commonButtonData) {
|
||||
Component label = PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(commonButtonData.getLabel()));
|
||||
Optional<Component> tooltip = commonButtonData.getTooltip() != null ?
|
||||
Optional.of(PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(commonButtonData.getTooltip()))) :
|
||||
Optional.empty();
|
||||
int width = commonButtonData.getWidth();
|
||||
|
||||
return new CommonButtonData(label, tooltip, width);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package de.oliver.fancysitula.api.dialogs;
|
||||
|
||||
import de.oliver.fancysitula.api.dialogs.body.FS_DialogBody;
|
||||
import de.oliver.fancysitula.api.dialogs.inputs.FS_DialogInput;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FS_CommonDialogData {
|
||||
|
||||
private String title;
|
||||
private @Nullable String externalTitle;
|
||||
private boolean canCloseWithEscape;
|
||||
private boolean pause;
|
||||
private FS_DialogAction afterAction;
|
||||
private List<FS_DialogBody> body;
|
||||
private List<FS_DialogInput> inputs;
|
||||
|
||||
public FS_CommonDialogData(String title, @Nullable String externalTitle, boolean canCloseWithEscape, boolean pause, FS_DialogAction afterAction, List<FS_DialogBody> body, List<FS_DialogInput> inputs) {
|
||||
this.title = title;
|
||||
this.externalTitle = externalTitle;
|
||||
this.canCloseWithEscape = canCloseWithEscape;
|
||||
this.pause = pause;
|
||||
this.afterAction = afterAction;
|
||||
this.body = body;
|
||||
this.inputs = inputs;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public @Nullable String getExternalTitle() {
|
||||
return externalTitle;
|
||||
}
|
||||
|
||||
public void setExternalTitle(@Nullable String externalTitle) {
|
||||
this.externalTitle = externalTitle;
|
||||
}
|
||||
|
||||
public boolean isCanCloseWithEscape() {
|
||||
return canCloseWithEscape;
|
||||
}
|
||||
|
||||
public void setCanCloseWithEscape(boolean canCloseWithEscape) {
|
||||
this.canCloseWithEscape = canCloseWithEscape;
|
||||
}
|
||||
|
||||
public boolean isPause() {
|
||||
return pause;
|
||||
}
|
||||
|
||||
public void setPause(boolean pause) {
|
||||
this.pause = pause;
|
||||
}
|
||||
|
||||
public FS_DialogAction getAfterAction() {
|
||||
return afterAction;
|
||||
}
|
||||
|
||||
public void setAfterAction(FS_DialogAction afterAction) {
|
||||
this.afterAction = afterAction;
|
||||
}
|
||||
|
||||
public List<FS_DialogBody> getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(List<FS_DialogBody> body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public List<FS_DialogInput> getInputs() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
public void setInputs(List<FS_DialogInput> inputs) {
|
||||
this.inputs = inputs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package de.oliver.fancysitula.api.dialogs;
|
||||
|
||||
public enum FS_DialogAction {
|
||||
CLOSE(0, "close"),
|
||||
NONE(1, "none"),
|
||||
WAIT_FOR_RESPONSE(2, "wait_for_response");
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
|
||||
FS_DialogAction(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package de.oliver.fancysitula.api.dialogs.actions;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class FS_CommonButtonData {
|
||||
|
||||
private String label;
|
||||
private @Nullable String tooltip;
|
||||
private int width;
|
||||
|
||||
public FS_CommonButtonData(String label, @Nullable String tooltip, int width) {
|
||||
this.label = label;
|
||||
this.tooltip = tooltip;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public @Nullable String getTooltip() {
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
public void setTooltip(@Nullable String tooltip) {
|
||||
this.tooltip = tooltip;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package de.oliver.fancysitula.api.dialogs.actions;
|
||||
|
||||
public class FS_DialogActionButton {
|
||||
|
||||
private FS_CommonButtonData buttonData;
|
||||
private FS_DialogActionButtonAction action;
|
||||
|
||||
public FS_DialogActionButton(FS_CommonButtonData buttonData, FS_DialogActionButtonAction action) {
|
||||
this.buttonData = buttonData;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public FS_CommonButtonData getButtonData() {
|
||||
return buttonData;
|
||||
}
|
||||
|
||||
public void setButtonData(FS_CommonButtonData buttonData) {
|
||||
this.buttonData = buttonData;
|
||||
}
|
||||
|
||||
public FS_DialogActionButtonAction getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(FS_DialogActionButtonAction action) {
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package de.oliver.fancysitula.api.dialogs.actions;
|
||||
|
||||
public interface FS_DialogActionButtonAction {
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.oliver.fancysitula.api.dialogs.actions;
|
||||
|
||||
public class FS_DialogRunCommandAction implements FS_DialogActionButtonAction {
|
||||
|
||||
private String command;
|
||||
|
||||
public FS_DialogRunCommandAction(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public void setCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package de.oliver.fancysitula.api.dialogs.body;
|
||||
|
||||
public interface FS_DialogBody {
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package de.oliver.fancysitula.api.dialogs.body;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class FS_DialogItemBody implements FS_DialogBody {
|
||||
|
||||
private ItemStack item;
|
||||
private @Nullable FS_DialogTextBody description;
|
||||
private boolean showDecorations;
|
||||
private boolean showTooltip;
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public FS_DialogItemBody(ItemStack item, @Nullable FS_DialogTextBody description, boolean showDecorations, boolean showTooltip, int width, int height) {
|
||||
this.item = item;
|
||||
this.description = description;
|
||||
this.showDecorations = showDecorations;
|
||||
this.showTooltip = showTooltip;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(ItemStack item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public @Nullable FS_DialogTextBody getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(@Nullable FS_DialogTextBody description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isShowDecorations() {
|
||||
return showDecorations;
|
||||
}
|
||||
|
||||
public void setShowDecorations(boolean showDecorations) {
|
||||
this.showDecorations = showDecorations;
|
||||
}
|
||||
|
||||
public boolean isShowTooltip() {
|
||||
return showTooltip;
|
||||
}
|
||||
|
||||
public void setShowTooltip(boolean showTooltip) {
|
||||
this.showTooltip = showTooltip;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package de.oliver.fancysitula.api.dialogs.body;
|
||||
|
||||
public class FS_DialogTextBody implements FS_DialogBody {
|
||||
|
||||
private String text;
|
||||
private int width;
|
||||
|
||||
public FS_DialogTextBody(String text, int width) {
|
||||
this.text = text;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package de.oliver.fancysitula.api.dialogs.inputs;
|
||||
|
||||
public class FS_DialogBooleanInput implements FS_DialogInputControl {
|
||||
|
||||
private String label;
|
||||
private boolean initial;
|
||||
private String onTrue;
|
||||
private String onFalse;
|
||||
|
||||
public FS_DialogBooleanInput(String label, boolean initial, String onTrue, String onFalse) {
|
||||
this.label = label;
|
||||
this.initial = initial;
|
||||
this.onTrue = onTrue;
|
||||
this.onFalse = onFalse;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public boolean isInitial() {
|
||||
return initial;
|
||||
}
|
||||
|
||||
public void setInitial(boolean initial) {
|
||||
this.initial = initial;
|
||||
}
|
||||
|
||||
public String getOnTrue() {
|
||||
return onTrue;
|
||||
}
|
||||
|
||||
public void setOnTrue(String onTrue) {
|
||||
this.onTrue = onTrue;
|
||||
}
|
||||
|
||||
public String getOnFalse() {
|
||||
return onFalse;
|
||||
}
|
||||
|
||||
public void setOnFalse(String onFalse) {
|
||||
this.onFalse = onFalse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package de.oliver.fancysitula.api.dialogs.inputs;
|
||||
|
||||
public class FS_DialogInput {
|
||||
|
||||
private String key;
|
||||
private FS_DialogInputControl control;
|
||||
|
||||
public FS_DialogInput(String key, FS_DialogInputControl control) {
|
||||
this.key = key;
|
||||
this.control = control;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public FS_DialogInputControl getControl() {
|
||||
return control;
|
||||
}
|
||||
|
||||
public void setControl(FS_DialogInputControl control) {
|
||||
this.control = control;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package de.oliver.fancysitula.api.dialogs.inputs;
|
||||
|
||||
public interface FS_DialogInputControl {
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package de.oliver.fancysitula.api.dialogs.inputs;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class FS_DialogNumberRangeInput implements FS_DialogInputControl {
|
||||
|
||||
private int width;
|
||||
private String label;
|
||||
private String labelFormat;
|
||||
private float start;
|
||||
private float end;
|
||||
private @Nullable Float initial;
|
||||
private @Nullable Float step;
|
||||
|
||||
public FS_DialogNumberRangeInput(int width, String label, String labelFormat, float start, float end, @Nullable Float initial, @Nullable Float step) {
|
||||
this.width = width;
|
||||
this.label = label;
|
||||
this.labelFormat = labelFormat;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.initial = initial;
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getLabelFormat() {
|
||||
return labelFormat;
|
||||
}
|
||||
|
||||
public void setLabelFormat(String labelFormat) {
|
||||
this.labelFormat = labelFormat;
|
||||
}
|
||||
|
||||
public float getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(float start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public float getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(float end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public @Nullable Float getInitial() {
|
||||
return initial;
|
||||
}
|
||||
|
||||
public void setInitial(@Nullable Float initial) {
|
||||
this.initial = initial;
|
||||
}
|
||||
|
||||
public @Nullable Float getStep() {
|
||||
return step;
|
||||
}
|
||||
|
||||
public void setStep(@Nullable Float step) {
|
||||
this.step = step;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package de.oliver.fancysitula.api.dialogs.inputs;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FS_DialogSingleOptionInput implements FS_DialogInputControl {
|
||||
|
||||
private int width;
|
||||
private List<Entry> entries;
|
||||
private String label;
|
||||
private boolean isLabelVisible;
|
||||
|
||||
public FS_DialogSingleOptionInput(int width, List<Entry> entries, String label, boolean isLabelVisible) {
|
||||
this.width = width;
|
||||
this.entries = entries;
|
||||
this.label = label;
|
||||
this.isLabelVisible = isLabelVisible;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public List<Entry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public void setEntries(List<Entry> entries) {
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public boolean isLabelVisible() {
|
||||
return isLabelVisible;
|
||||
}
|
||||
|
||||
public void setLabelVisible(boolean labelVisible) {
|
||||
isLabelVisible = labelVisible;
|
||||
}
|
||||
|
||||
public static class Entry {
|
||||
|
||||
private String id;
|
||||
private @Nullable String display;
|
||||
private boolean initial;
|
||||
|
||||
public Entry(String id, @Nullable String display, boolean initial) {
|
||||
this.id = id;
|
||||
this.display = display;
|
||||
this.initial = initial;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public @Nullable String getDisplay() {
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(@Nullable String display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public boolean isInitial() {
|
||||
return initial;
|
||||
}
|
||||
|
||||
public void setInitial(boolean initial) {
|
||||
this.initial = initial;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package de.oliver.fancysitula.api.dialogs.inputs;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class FS_DialogTextInput implements FS_DialogInputControl {
|
||||
|
||||
private int width;
|
||||
private String label;
|
||||
private boolean isLabelVisible;
|
||||
private String initial;
|
||||
private int maxLength;
|
||||
private @Nullable MultilineOptions multilineOptions;
|
||||
|
||||
public FS_DialogTextInput(int width, String label, boolean isLabelVisible, String initial, int maxLength, @Nullable MultilineOptions multilineOptions) {
|
||||
this.width = width;
|
||||
this.label = label;
|
||||
this.isLabelVisible = isLabelVisible;
|
||||
this.initial = initial;
|
||||
this.maxLength = maxLength;
|
||||
this.multilineOptions = multilineOptions;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public boolean isLabelVisible() {
|
||||
return isLabelVisible;
|
||||
}
|
||||
|
||||
public void setLabelVisible(boolean labelVisible) {
|
||||
isLabelVisible = labelVisible;
|
||||
}
|
||||
|
||||
public String getInitial() {
|
||||
return initial;
|
||||
}
|
||||
|
||||
public void setInitial(String initial) {
|
||||
this.initial = initial;
|
||||
}
|
||||
|
||||
public int getMaxLength() {
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
public void setMaxLength(int maxLength) {
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
|
||||
public @Nullable MultilineOptions getMultilineOptions() {
|
||||
return multilineOptions;
|
||||
}
|
||||
|
||||
public void setMultilineOptions(@Nullable MultilineOptions multilineOptions) {
|
||||
this.multilineOptions = multilineOptions;
|
||||
}
|
||||
|
||||
public static class MultilineOptions {
|
||||
|
||||
private @Nullable Integer maxLines;
|
||||
private @Nullable Integer height;
|
||||
|
||||
public MultilineOptions(@Nullable Integer maxLines, @Nullable Integer height) {
|
||||
this.maxLines = maxLines;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public @Nullable Integer getMaxLines() {
|
||||
return maxLines;
|
||||
}
|
||||
|
||||
public void setMaxLines(@Nullable Integer maxLines) {
|
||||
this.maxLines = maxLines;
|
||||
}
|
||||
|
||||
public @Nullable Integer getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(@Nullable Integer height) {
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package de.oliver.fancysitula.api.dialogs.types;
|
||||
|
||||
import de.oliver.fancysitula.api.dialogs.FS_CommonDialogData;
|
||||
import de.oliver.fancysitula.api.dialogs.FS_Dialog;
|
||||
import de.oliver.fancysitula.api.dialogs.actions.FS_DialogActionButton;
|
||||
|
||||
public class FS_NoticeDialog implements FS_Dialog {
|
||||
|
||||
private FS_CommonDialogData dialogData;
|
||||
private FS_DialogActionButton actionButton;
|
||||
|
||||
public FS_NoticeDialog(FS_CommonDialogData dialogData, FS_DialogActionButton actionButton) {
|
||||
this.dialogData = dialogData;
|
||||
this.actionButton = actionButton;
|
||||
}
|
||||
|
||||
public FS_CommonDialogData getDialogData() {
|
||||
return dialogData;
|
||||
}
|
||||
|
||||
public void setDialogData(FS_CommonDialogData dialogData) {
|
||||
this.dialogData = dialogData;
|
||||
}
|
||||
|
||||
public FS_DialogActionButton getActionButton() {
|
||||
return actionButton;
|
||||
}
|
||||
|
||||
public void setActionButton(FS_DialogActionButton actionButton) {
|
||||
this.actionButton = actionButton;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,13 @@
|
||||
package de.oliver.fancysitula.commands;
|
||||
|
||||
import de.oliver.fancysitula.api.dialogs.FS_CommonDialogData;
|
||||
import de.oliver.fancysitula.api.dialogs.FS_DialogAction;
|
||||
import de.oliver.fancysitula.api.dialogs.actions.FS_CommonButtonData;
|
||||
import de.oliver.fancysitula.api.dialogs.actions.FS_DialogActionButton;
|
||||
import de.oliver.fancysitula.api.dialogs.body.FS_DialogTextBody;
|
||||
import de.oliver.fancysitula.api.dialogs.inputs.FS_DialogBooleanInput;
|
||||
import de.oliver.fancysitula.api.dialogs.inputs.FS_DialogInput;
|
||||
import de.oliver.fancysitula.api.dialogs.types.FS_NoticeDialog;
|
||||
import de.oliver.fancysitula.api.entities.FS_RealPlayer;
|
||||
import de.oliver.fancysitula.api.packets.FS_ClientboundPlayerInfoUpdatePacket;
|
||||
import de.oliver.fancysitula.api.packets.FS_Color;
|
||||
@@ -34,7 +42,9 @@ public class FancySitulaCMD extends Command {
|
||||
|
||||
// Wrap the real player into an FS_Player instance
|
||||
FS_RealPlayer fsPlayer = new FS_RealPlayer(p);
|
||||
testTeam(p);
|
||||
testNoticeDialog(p);
|
||||
|
||||
// testTeam(p);
|
||||
|
||||
// FS_TextDisplay fakeTextDisplay = new FS_TextDisplay();
|
||||
// fakeTextDisplay.setBillboardRenderConstraints((byte) 3);
|
||||
@@ -61,6 +71,44 @@ public class FancySitulaCMD extends Command {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void testNoticeDialog(Player to) {
|
||||
FS_RealPlayer fsPlayer = new FS_RealPlayer(to);
|
||||
|
||||
FS_NoticeDialog noticeDialog = new FS_NoticeDialog(
|
||||
new FS_CommonDialogData(
|
||||
"My dialog",
|
||||
"External Title",
|
||||
true,
|
||||
false,
|
||||
FS_DialogAction.NONE,
|
||||
List.of(
|
||||
new FS_DialogTextBody("Hello world!", 200)
|
||||
),
|
||||
List.of(
|
||||
new FS_DialogInput(
|
||||
"booleanInput1",
|
||||
new FS_DialogBooleanInput(
|
||||
"Boolean button 1",
|
||||
false,
|
||||
"True value",
|
||||
"False value"
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
new FS_DialogActionButton(
|
||||
new FS_CommonButtonData(
|
||||
"button1",
|
||||
"tooltip1",
|
||||
40
|
||||
),
|
||||
null
|
||||
)
|
||||
);
|
||||
|
||||
FancySitula.PACKET_FACTORY.createShowDialogPacket(noticeDialog).send(fsPlayer);
|
||||
}
|
||||
|
||||
private void testTeam(Player to) {
|
||||
FS_RealPlayer fsPlayer = new FS_RealPlayer(to);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user