Use static factory method to create Builder with contents.

This commit is contained in:
Jeremy Wood 2021-07-06 15:01:41 -04:00
parent d95977eb48
commit c01a45f130
3 changed files with 21 additions and 21 deletions

View File

@ -76,10 +76,9 @@ public class GamerulesCommand extends MultiverseCommand {
}
}
new ContentDisplay.Builder<Map<String, Object>>()
ContentDisplay.forContent(getGameRuleMap(world))
.sender(sender)
.header("=== Gamerules for %s%s%s ===", ChatColor.AQUA, world.getName(), ChatColor.WHITE)
.contents(getGameRuleMap(world))
.displayHandler(DisplayHandlers.INLINE_MAP)
.colorTool(ColorAlternator.with(ChatColor.GREEN, ChatColor.GOLD))
.setting(DisplaySettings.OPERATOR, ": ")

View File

@ -68,10 +68,9 @@ public class ListCommand extends MultiverseCommand {
}
}
new ContentDisplay.Builder<Collection<String>>()
ContentDisplay.forContent(getListContents(sender))
.sender(sender)
.header("%s====[ Multiverse World List ]====", ChatColor.GOLD)
.contents(getListContents(sender))
.displayHandler(DisplayHandlers.PAGE_LIST)
.colorTool(ColorAlternator.with(ChatColor.AQUA, ChatColor.GOLD))
.filter(filter)
@ -79,7 +78,7 @@ public class ListCommand extends MultiverseCommand {
.display();
}
private List<String> getListContents(@NotNull CommandSender sender) {
private Collection<String> getListContents(@NotNull CommandSender sender) {
Player player = (sender instanceof Player) ? (Player) sender : null;
List<String> worldList = this.plugin.getMVWorldManager().getMVWorlds().stream()

View File

@ -19,16 +19,30 @@ public class ContentDisplay<T> {
public static final String LINE_BREAK = "%br%";
/**
* Creates a ContentDisplay.Builder for the given content.
*
* @param content The content to be displayed.
* @param <U> The type of the content which can be inferred.
* @return A new Builder.
*/
public static <U> Builder<U> forContent(U content) {
return new Builder<>(content);
}
private final T contents;
private CommandSender sender;
private String header;
private T contents;
private String emptyMessage = "No matching content to display.";
private DisplayHandler<T> displayHandler;
private ColorTool colorTool = ColorTool.DEFAULT;
private ContentFilter filter = ContentFilter.DEFAULT;
private final Map<DisplaySetting<?>, Object> settingsMap = new WeakHashMap<>();
private ContentDisplay() { }
private ContentDisplay(T contents) {
this.contents = contents;
}
/**
* Do the actual displaying of contents to the sender.
@ -138,8 +152,8 @@ public class ContentDisplay<T> {
private final ContentDisplay<T> display;
public Builder() {
this.display = new ContentDisplay<>();
private Builder(T content) {
this.display = new ContentDisplay<>(content);
}
/**
@ -167,18 +181,6 @@ public class ContentDisplay<T> {
return this;
}
/**
* Sets content to be displayed.
*
* @param contents The contents.
* @return The builder.
*/
@NotNull
public Builder<T> contents(@Nullable T contents) {
this.display.contents = contents;
return this;
}
/**
* Sets the message to show when no content is available for display.
*