fancydialogs: Introduce DialogBody and its implementations

This commit is contained in:
Oliver
2025-05-15 19:27:24 +02:00
committed by Oliver
parent a67be52be8
commit c41faa53b8
4 changed files with 120 additions and 1 deletions

View File

@@ -1,25 +1,30 @@
package com.fancyinnovations.fancydialogs.api;
import com.fancyinnovations.fancydialogs.api.body.DialogBody;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public abstract class Dialog {
private final @NotNull String id;
private @NotNull String title;
private @Nullable String externalTitle;
private boolean canCloseWithEscape;
private @NotNull List<DialogBody> body;
/**
* @param externalTitle if null, the title will be used
* @param canCloseWithEscape default is true
*/
public Dialog(@NotNull String id, @NotNull String title, @Nullable String externalTitle, @Nullable Boolean canCloseWithEscape) {
public Dialog(@NotNull String id, @NotNull String title, @Nullable String externalTitle, @Nullable Boolean canCloseWithEscape, @NotNull List<DialogBody> body) {
this.id = id;
this.title = title;
this.externalTitle = externalTitle == null ? title : externalTitle;
this.canCloseWithEscape = canCloseWithEscape == null || canCloseWithEscape;
this.body = body;
}
abstract public void show(Player player);
@@ -53,4 +58,12 @@ public abstract class Dialog {
public void setCanCloseWithEscape(boolean canCloseWithEscape) {
this.canCloseWithEscape = canCloseWithEscape;
}
public @NotNull List<DialogBody> getBody() {
return body;
}
public void setBody(@NotNull List<DialogBody> body) {
this.body = body;
}
}

View File

@@ -0,0 +1,4 @@
package com.fancyinnovations.fancydialogs.api.body;
public abstract class DialogBody {
}

View File

@@ -0,0 +1,72 @@
package com.fancyinnovations.fancydialogs.api.body;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ItemBody extends DialogBody {
private @NotNull ItemStack item;
private @Nullable TextBody description;
boolean showDecorations;
boolean showTooltip;
int width;
int height;
public ItemBody(@NotNull ItemStack item, @Nullable TextBody 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 @NotNull ItemStack getItem() {
return item;
}
public void setItem(@NotNull ItemStack item) {
this.item = item;
}
public @Nullable TextBody getDescription() {
return description;
}
public void setDescription(@Nullable TextBody 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;
}
}

View File

@@ -0,0 +1,30 @@
package com.fancyinnovations.fancydialogs.api.body;
import org.jetbrains.annotations.NotNull;
public class TextBody extends DialogBody {
private @NotNull String content;
private int width;
public TextBody(@NotNull String content, int width) {
this.content = content;
this.width = width;
}
public @NotNull String getContent() {
return content;
}
public void setContent(@NotNull String content) {
this.content = content;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
}