mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 06:28:49 +00:00
Add about menu via new AboutMenu builder, start /huskhomes
This commit is contained in:
1 parent
1b0514ae07
commit
e3194ba15a
6 files changed
+305
-3
No files matched your search
@@ -0,0 +1,194 @@
|
||||
package net.william278.huskhomes.util;
|
||||
|
||||
import de.themoep.minedown.MineDown;
|
||||
import net.william278.huskhomes.config.Locales;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class AboutMenu {
|
||||
|
||||
@NotNull
|
||||
private final String title;
|
||||
|
||||
@Nullable
|
||||
private Version version;
|
||||
|
||||
@Nullable
|
||||
private String description;
|
||||
|
||||
@NotNull
|
||||
private final Map<String, List<Credit>> attributions;
|
||||
|
||||
@NotNull
|
||||
private final List<Link> buttons;
|
||||
|
||||
private AboutMenu(@NotNull String title) {
|
||||
this.title = title;
|
||||
this.buttons = new ArrayList<>();
|
||||
this.attributions = new HashMap<>();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AboutMenu create(@NotNull String title) {
|
||||
return new AboutMenu(title);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AboutMenu withDescription(@Nullable String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AboutMenu withVersion(@NotNull Version version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AboutMenu addAttribution(@NotNull String category, @NotNull Credit... credits) {
|
||||
final List<Credit> creditList = new ArrayList<>(Arrays.asList(credits));
|
||||
attributions.putIfAbsent(category, new ArrayList<>());
|
||||
attributions.get(category).addAll(creditList);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AboutMenu addButtons(@NotNull Link... links) {
|
||||
buttons.addAll(Arrays.asList(links));
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MineDown toMineDown() {
|
||||
final StringJoiner menu = new StringJoiner("\n")
|
||||
.add("[" + title + "](#00fb9a bold)" + (version != null ? " [| Version " + version + "](#00fb9a)" : ""));
|
||||
if (description != null) {
|
||||
menu.add("[" + Locales.escapeMineDown(description) + "](gray)");
|
||||
}
|
||||
|
||||
if (!attributions.isEmpty()) {
|
||||
menu.add("");
|
||||
}
|
||||
for (Map.Entry<String, List<Credit>> entry : attributions.entrySet()) {
|
||||
final StringJoiner creditJoiner = new StringJoiner(", ");
|
||||
for (final Credit credit : entry.getValue()) {
|
||||
creditJoiner.add("[" + credit.name + "](gray" +
|
||||
(credit.description != null ? " show_text=&7" + credit.description : "") +
|
||||
(credit.url != null ? " open_url=" + MineDown.escape(credit.url) : "") + ")");
|
||||
}
|
||||
|
||||
if (!creditJoiner.toString().isBlank()) {
|
||||
menu.add("[• " + entry.getKey() + ":](white) " + creditJoiner);
|
||||
}
|
||||
}
|
||||
|
||||
if (!buttons.isEmpty()) {
|
||||
final StringJoiner buttonsJoiner = new StringJoiner(" ");
|
||||
for (final Link link : buttons) {
|
||||
buttonsJoiner.add("[[" + (link.icon != null ? link.icon + " " : "")
|
||||
+ link.text + "…]](#00fb9a show_text=&7Click to open link open_url="
|
||||
+ MineDown.escape(link.url) + ")");
|
||||
}
|
||||
menu.add("").add("[Links:](gray) " + buttonsJoiner);
|
||||
}
|
||||
|
||||
return new MineDown(menu.toString()).replace();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String toConsoleString() {
|
||||
final StringJoiner menu = new StringJoiner("\n")
|
||||
.add(title + (version != null ? " | Version " + version : ""));
|
||||
if (description != null) {
|
||||
menu.add(description);
|
||||
}
|
||||
|
||||
if (!attributions.entrySet().isEmpty()) {
|
||||
menu.add("━━━━━━━━━━━━━━━━━━━━━━━━");
|
||||
}
|
||||
for (final Map.Entry<String, List<Credit>> entry : attributions.entrySet()) {
|
||||
final StringJoiner creditJoiner = new StringJoiner(", ");
|
||||
for (final Credit credit : entry.getValue()) {
|
||||
creditJoiner.add(credit.name + (credit.description != null ? " (" + credit.description + ")" : ""));
|
||||
}
|
||||
|
||||
if (!creditJoiner.toString().isBlank()) {
|
||||
menu.add("- " + entry.getKey() + ": " + creditJoiner);
|
||||
}
|
||||
}
|
||||
|
||||
if (!buttons.isEmpty()) {
|
||||
menu.add("━━━━━━━━━━━━━━━━━━━━━━━━");
|
||||
for (final Link link : buttons) {
|
||||
menu.add("- " + link.text + ": " + link.url);
|
||||
}
|
||||
}
|
||||
|
||||
return menu.toString();
|
||||
}
|
||||
|
||||
public static class Link {
|
||||
|
||||
@NotNull
|
||||
private String text = "Link";
|
||||
|
||||
@Nullable
|
||||
private String icon;
|
||||
|
||||
@NotNull
|
||||
private final String url;
|
||||
|
||||
private Link(@NotNull String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public static Link of(@NotNull String url) {
|
||||
return new Link(url);
|
||||
}
|
||||
|
||||
public Link withText(@NotNull String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Link withIcon(@NotNull String icon) {
|
||||
this.icon = icon;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Credit {
|
||||
@NotNull
|
||||
private final String name;
|
||||
|
||||
@Nullable
|
||||
private String description;
|
||||
|
||||
@Nullable
|
||||
private String url;
|
||||
|
||||
private Credit(@NotNull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static Credit of(@NotNull String name) {
|
||||
return new Credit(name);
|
||||
}
|
||||
|
||||
public Credit withDescription(@Nullable String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Credit withUrl(@Nullable String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -149,6 +149,14 @@ public enum Permission {
|
||||
* Lets the user use {@code /back} to return to where they died
|
||||
*/
|
||||
COMMAND_BACK_RETURN_BY_DEATH("huskhomes.command.back.death", DefaultAccess.EVERYONE),
|
||||
/**
|
||||
* Lets the user access /huskhomes subcommands
|
||||
*/
|
||||
COMMAND_HUSKHOMES("huskhomes.command.huskhomes", DefaultAccess.EVERYONE),
|
||||
/**
|
||||
* Lets the user view the command list
|
||||
*/
|
||||
COMMAND_HUSKHOMES_HELP("huskhomes.command.huskhomes.help", DefaultAccess.EVERYONE),
|
||||
/**
|
||||
* Lets the user view plugin information
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user