mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancydialogs: Refactor dialog body classes to use records
This commit is contained in:
@@ -1,69 +0,0 @@
|
|||||||
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, @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);
|
|
||||||
|
|
||||||
abstract public void close(Player player);
|
|
||||||
|
|
||||||
public @NotNull String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(@NotNull String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable String getExternalTitle() {
|
|
||||||
return externalTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExternalTitle(@Nullable String externalTitle) {
|
|
||||||
this.externalTitle = externalTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canCloseWithEscape() {
|
|
||||||
return canCloseWithEscape;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.fancyinnovations.fancydialogs.api;
|
||||||
|
|
||||||
|
import com.fancyinnovations.fancydialogs.api.body.DialogBody;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record DialogData(
|
||||||
|
@NotNull String id,
|
||||||
|
@NotNull String title,
|
||||||
|
@Nullable String externalTitle,
|
||||||
|
boolean canCloseWithEscape,
|
||||||
|
@NotNull List<DialogBody> body
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.fancyinnovations.fancydialogs.api.body;
|
package com.fancyinnovations.fancydialogs.api.body;
|
||||||
|
|
||||||
public abstract class DialogBody {
|
public interface DialogBody {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,69 +4,13 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class ItemBody extends DialogBody {
|
public record ItemBody(
|
||||||
|
@NotNull ItemStack item,
|
||||||
|
@Nullable TextBody description,
|
||||||
|
boolean showDecorations,
|
||||||
|
boolean showTooltip,
|
||||||
|
int width,
|
||||||
|
int height
|
||||||
|
) implements 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,29 +2,9 @@ package com.fancyinnovations.fancydialogs.api.body;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class TextBody extends DialogBody {
|
public record TextBody(
|
||||||
|
@NotNull String content,
|
||||||
|
int width
|
||||||
|
) implements 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user