mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 20:16:06 +01:00
Futher absract content display to add KeyValueDisplay.
This commit is contained in:
parent
942f8a99ab
commit
3f8e514f51
@ -0,0 +1,6 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.display;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ContentCreator<T> {
|
||||
T generateContent();
|
||||
}
|
@ -5,27 +5,38 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class ContentDisplay {
|
||||
public abstract class ContentDisplay<T> {
|
||||
|
||||
protected final Plugin plugin;
|
||||
protected final CommandSender sender;
|
||||
protected final String header;
|
||||
protected final ContentCreator<T> creator;
|
||||
protected final ContentFilter filter;
|
||||
protected final ColourAlternator colours;
|
||||
|
||||
public ContentDisplay(@NotNull CommandSender sender,
|
||||
public ContentDisplay(Plugin plugin, @NotNull CommandSender sender,
|
||||
@Nullable String header,
|
||||
@NotNull ContentCreator<T> creator,
|
||||
@NotNull ContentFilter filter,
|
||||
@Nullable ColourAlternator colours) {
|
||||
|
||||
this.plugin = plugin;
|
||||
this.sender = sender;
|
||||
this.header = header;
|
||||
this.creator = creator;
|
||||
this.filter = filter;
|
||||
this.colours = colours;
|
||||
}
|
||||
|
||||
public abstract void showContent();
|
||||
public void showContent() {
|
||||
getShowPageRunnable().runTask(this.plugin);
|
||||
}
|
||||
|
||||
public abstract void showContentAsync(@NotNull Plugin plugin);
|
||||
public void showContentAsync() {
|
||||
getShowPageRunnable().runTaskAsynchronously(this.plugin);
|
||||
}
|
||||
|
||||
public abstract ShowRunnable<T> getShowPageRunnable();
|
||||
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
@ -35,6 +46,10 @@ public abstract class ContentDisplay {
|
||||
return header;
|
||||
}
|
||||
|
||||
public ContentCreator<T> getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
public ContentFilter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
@ -1,148 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2020. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commandTools.display;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandTools.PageFilter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PageDisplay extends ContentDisplay {
|
||||
|
||||
private final List<String> contents;
|
||||
private final int pageToShow;
|
||||
private int contentLinesPerPage; // excludes header
|
||||
|
||||
public static final int FIST_PAGE = 1;
|
||||
public static final int DEFAULT_LINES_PER_PAGE = 8;
|
||||
public static final String PAGE_PLACEHOLDER = "%page%";
|
||||
public static final String LINE_BREAK_PLACEHOLDER = "%lf%";
|
||||
|
||||
public PageDisplay(@NotNull CommandSender sender,
|
||||
@Nullable String header,
|
||||
@NotNull List<String> contents) {
|
||||
|
||||
this(sender, header, contents, FIST_PAGE, DEFAULT_LINES_PER_PAGE, new ContentFilter(null), null);
|
||||
}
|
||||
|
||||
public PageDisplay(@NotNull CommandSender sender,
|
||||
@Nullable String header,
|
||||
@NotNull List<String> contents,
|
||||
int pageToShow) {
|
||||
|
||||
this(sender, header, contents, pageToShow, DEFAULT_LINES_PER_PAGE, new ContentFilter(null), null);
|
||||
}
|
||||
|
||||
public PageDisplay(@NotNull CommandSender sender,
|
||||
@Nullable String header,
|
||||
@NotNull List<String> contents,
|
||||
int pageToShow,
|
||||
int contentLinesPerPage) {
|
||||
|
||||
this(sender, header, contents, pageToShow, contentLinesPerPage, new ContentFilter(null), null);
|
||||
}
|
||||
|
||||
public PageDisplay(@NotNull CommandSender sender,
|
||||
@Nullable String header,
|
||||
@NotNull List<String> contents,
|
||||
int pageToShow,
|
||||
int contentLinesPerPage,
|
||||
@Nullable ColourAlternator colours) {
|
||||
|
||||
this(sender, header, contents, pageToShow, contentLinesPerPage, new ContentFilter(null), colours);
|
||||
}
|
||||
|
||||
public PageDisplay(@NotNull CommandSender sender,
|
||||
@Nullable String header,
|
||||
@NotNull List<String> contents,
|
||||
@NotNull PageFilter pageFilter) {
|
||||
|
||||
this(sender, header, contents, pageFilter.getPage(), DEFAULT_LINES_PER_PAGE, pageFilter.getFilter(), null);
|
||||
}
|
||||
|
||||
public PageDisplay(@NotNull CommandSender sender,
|
||||
@Nullable String header,
|
||||
@NotNull List<String> contents,
|
||||
@NotNull PageFilter pageFilter,
|
||||
@Nullable ColourAlternator colours) {
|
||||
|
||||
this(sender, header, contents, pageFilter.getPage(), DEFAULT_LINES_PER_PAGE, pageFilter.getFilter(), colours);
|
||||
}
|
||||
|
||||
public PageDisplay(@NotNull CommandSender sender,
|
||||
@Nullable String header,
|
||||
@NotNull List<String> contents,
|
||||
int pageToShow,
|
||||
int contentLinesPerPage,
|
||||
@NotNull ContentFilter filter,
|
||||
@Nullable ColourAlternator colours) {
|
||||
|
||||
super(sender, header, filter, colours);
|
||||
this.contents = contents;
|
||||
this.pageToShow = pageToShow;
|
||||
this.contentLinesPerPage = contentLinesPerPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showContent() {
|
||||
getShowPageRunnable().run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showContentAsync(@NotNull Plugin plugin) {
|
||||
getShowPageRunnable().runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ShowPage getShowPageRunnable() {
|
||||
return (sender instanceof ConsoleCommandSender)
|
||||
? new ShowAllPage(this)
|
||||
: new ShowSelectedPage(this);
|
||||
}
|
||||
|
||||
public void reduceContentLinesPerPage(int by) {
|
||||
this.contentLinesPerPage -= by;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
public int getPageToShow() {
|
||||
return pageToShow;
|
||||
}
|
||||
|
||||
public int getContentLinesPerPage() {
|
||||
return contentLinesPerPage;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ContentFilter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ColourAlternator getColours() {
|
||||
return colours;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.display;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public abstract class ShowRunnable<T> extends BukkitRunnable {
|
||||
|
||||
protected final T contents;
|
||||
|
||||
protected ShowRunnable(ContentDisplay<T> display) {
|
||||
this.contents = display.getCreator().generateContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
calculateContent();
|
||||
display();
|
||||
}
|
||||
|
||||
public void display() {
|
||||
showHeader();
|
||||
showContent();
|
||||
}
|
||||
|
||||
public abstract void calculateContent();
|
||||
|
||||
public abstract boolean validateContent();
|
||||
|
||||
public abstract void showHeader();
|
||||
|
||||
public abstract void showContent();
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.display.kvpair;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ColourAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ShowRunnable;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class KeyValueDisplay extends ContentDisplay<Map<String, Object>> {
|
||||
|
||||
private final String operator;
|
||||
|
||||
public KeyValueDisplay(@NotNull Plugin plugin,
|
||||
@NotNull CommandSender sender,
|
||||
@Nullable String header,
|
||||
@NotNull ContentCreator<Map<String, Object>> creator,
|
||||
@NotNull ContentFilter filter,
|
||||
@Nullable ColourAlternator colours,
|
||||
@NotNull String operator) {
|
||||
|
||||
super(plugin, sender, header, creator, filter, colours);
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShowRunnable<Map<String, Object>> getShowPageRunnable() {
|
||||
return new ShowKeyValue(this);
|
||||
}
|
||||
|
||||
public String getOperator() {
|
||||
return operator;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.display.kvpair;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ShowRunnable;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ShowKeyValue extends ShowRunnable<Map<String, Object>> {
|
||||
|
||||
private final StringBuilder contentBuilder;
|
||||
private final KeyValueDisplay display;
|
||||
|
||||
public ShowKeyValue(KeyValueDisplay display) {
|
||||
super(display);
|
||||
this.display = display;
|
||||
this.contentBuilder = new StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculateContent() {
|
||||
ContentFilter filter = this.display.getFilter();
|
||||
boolean isFirst = true;
|
||||
for (Map.Entry<String, Object> entry : this.contents.entrySet()) {
|
||||
if (!filter.checkMatch(entry.getKey()) && !filter.checkMatch(entry.getValue().toString())) {
|
||||
continue;
|
||||
}
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
}
|
||||
else {
|
||||
contentBuilder.append(", ");
|
||||
}
|
||||
contentBuilder.append(this.display.getColours().getColorThis())
|
||||
.append(entry.getKey())
|
||||
.append(ChatColor.WHITE)
|
||||
.append(this.display.getOperator())
|
||||
.append(this.display.getColours().getColorThat())
|
||||
.append(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateContent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showHeader() {
|
||||
if (this.display.getHeader() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.display.getSender().sendMessage(this.display.getHeader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showContent() {
|
||||
this.display.getSender().sendMessage(contentBuilder.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2020. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commandTools.display.page;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandTools.PageFilter;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ColourAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ShowRunnable;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PageDisplay extends ContentDisplay<List<String>> {
|
||||
|
||||
private final int pageToShow;
|
||||
private int contentLinesPerPage; // excludes header
|
||||
|
||||
public static final int FIST_PAGE = 1;
|
||||
public static final int DEFAULT_LINES_PER_PAGE = 8;
|
||||
public static final String PAGE_PLACEHOLDER = "%page%";
|
||||
public static final String LINE_BREAK_PLACEHOLDER = "%lf%";
|
||||
|
||||
public PageDisplay(@NotNull Plugin plugin,
|
||||
@NotNull CommandSender sender,
|
||||
@Nullable String header,
|
||||
@NotNull ContentCreator<List<String>> creator,
|
||||
@NotNull ContentFilter filter,
|
||||
@Nullable ColourAlternator colours,
|
||||
int pageToShow,
|
||||
int contentLinesPerPage) {
|
||||
|
||||
super(plugin, sender, header, creator, filter, colours);
|
||||
this.pageToShow = pageToShow;
|
||||
this.contentLinesPerPage = contentLinesPerPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShowRunnable<List<String>> getShowPageRunnable() {
|
||||
return (this.sender instanceof ConsoleCommandSender)
|
||||
? new ShowAllPage(this)
|
||||
: new ShowSelectedPage(this);
|
||||
}
|
||||
|
||||
public void reduceContentLinesPerPage(int by) {
|
||||
this.contentLinesPerPage -= by;
|
||||
}
|
||||
|
||||
public int getPageToShow() {
|
||||
return pageToShow;
|
||||
}
|
||||
|
||||
public int getContentLinesPerPage() {
|
||||
return contentLinesPerPage;
|
||||
}
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.display;
|
||||
package com.onarandombox.MultiverseCore.commandTools.display.page;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.page.PageDisplay;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.page.ShowPage;
|
||||
|
||||
public class ShowAllPage extends ShowPage {
|
||||
|
||||
@ -9,10 +13,10 @@ public class ShowAllPage extends ShowPage {
|
||||
@Override
|
||||
public void calculateContent() {
|
||||
int index = -1;
|
||||
for (String line : this.display.getContents()) {
|
||||
for (String line : this.contents) {
|
||||
index++;
|
||||
if (PageDisplay.LINE_BREAK_PLACEHOLDER.equals(line)
|
||||
|| this.display.getFilter().checkMatch(this.display.getContents().get(index))) {
|
||||
|| this.display.getFilter().checkMatch(this.contents.get(index))) {
|
||||
contentToShowIndex.add(index);
|
||||
}
|
||||
}
|
@ -1,17 +1,18 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.display;
|
||||
package com.onarandombox.MultiverseCore.commandTools.display.page;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ColourAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ShowRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ShowPage extends BukkitRunnable {
|
||||
public abstract class ShowPage extends ShowRunnable<List<String>> {
|
||||
|
||||
protected PageDisplay display;
|
||||
protected final List<Integer> contentToShowIndex;
|
||||
|
||||
public ShowPage(PageDisplay display) {
|
||||
super(display);
|
||||
this.display = display;
|
||||
this.contentToShowIndex = new ArrayList<>();
|
||||
|
||||
@ -33,22 +34,12 @@ public abstract class ShowPage extends BukkitRunnable {
|
||||
display();
|
||||
}
|
||||
|
||||
public void display() {
|
||||
showHeader();
|
||||
showContent();
|
||||
}
|
||||
|
||||
public abstract void calculateContent();
|
||||
|
||||
public abstract boolean validateContent();
|
||||
|
||||
public abstract void showHeader();
|
||||
|
||||
@Override
|
||||
public void showContent() {
|
||||
ColourAlternator colours = this.display.getColours();
|
||||
|
||||
contentToShowIndex.stream()
|
||||
.map(this.display.getContents()::get)
|
||||
.map(this.contents::get)
|
||||
.map(line -> line.equals(PageDisplay.LINE_BREAK_PLACEHOLDER)
|
||||
? ""
|
||||
: line.replace(PageDisplay.PAGE_PLACEHOLDER, ""))
|
@ -1,4 +1,6 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.display;
|
||||
package com.onarandombox.MultiverseCore.commandTools.display.page;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentFilter;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@ -20,7 +22,7 @@ public class ShowSelectedPage extends ShowPage {
|
||||
public void calculateContent() {
|
||||
int lineCount = 0;
|
||||
int index = -1;
|
||||
for (String line : this.display.getContents()) {
|
||||
for (String line : this.contents) {
|
||||
index++;
|
||||
if (PageDisplay.LINE_BREAK_PLACEHOLDER.equals(line)) {
|
||||
lineCount = this.display.getContentLinesPerPage();
|
||||
@ -44,11 +46,21 @@ public class ShowSelectedPage extends ShowPage {
|
||||
return !pageOutOfRange();
|
||||
}
|
||||
|
||||
private boolean pageOutOfRange() {
|
||||
if (this.display.getPageToShow() < 0 || this.display.getPageToShow() > totalPages) {
|
||||
this.display.getSender().sendMessage((totalPages == 1)
|
||||
? "There is only 1 page."
|
||||
: String.format("Please enter a page from 1 to %s.", totalPages));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showHeader() {
|
||||
String theHeader;
|
||||
if (this.display.getHeader() == null) {
|
||||
theHeader = this.display.getContents().get(contentToShowIndex.remove(0));
|
||||
theHeader = this.contents.get(contentToShowIndex.remove(0));
|
||||
this.display.reduceContentLinesPerPage(1);
|
||||
}
|
||||
else {
|
||||
@ -63,16 +75,6 @@ public class ShowSelectedPage extends ShowPage {
|
||||
this.display.getSender().sendMessage(parsePaging());
|
||||
}
|
||||
|
||||
private boolean pageOutOfRange() {
|
||||
if (this.display.getPageToShow() < 0 || this.display.getPageToShow() > totalPages) {
|
||||
this.display.getSender().sendMessage((totalPages == 1)
|
||||
? "There is only 1 page."
|
||||
: String.format("Please enter a page from 1 to %s.", totalPages));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String parsePaging() {
|
||||
ContentFilter filter = this.display.getFilter();
|
||||
return (filter.hasFilter())
|
@ -18,7 +18,8 @@ import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ColourAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.PageDisplay;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.page.PageDisplay;
|
||||
import com.onarandombox.MultiverseCore.commandTools.PageFilter;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -81,33 +82,42 @@ public class AnchorCommand extends MultiverseCommand {
|
||||
public void onListAnchorCommand(@NotNull CommandSender sender,
|
||||
@NotNull PageFilter pageFilter) {
|
||||
|
||||
Set<String> anchors = (sender instanceof Player)
|
||||
? this.anchorManager.getAnchors((Player) sender)
|
||||
: this.anchorManager.getAllAnchors();
|
||||
|
||||
List<String> anchorContent = new ArrayList<>();
|
||||
for (String anchor : anchors) {
|
||||
Location anchorLocation = this.anchorManager.getAnchorLocation(anchor);
|
||||
World world = anchorLocation.getWorld(); // this.plugin.getMVWorldManager().getMVWorld();
|
||||
|
||||
String locationString = ChatColor.RED + "!!INVALID!!";
|
||||
if (world != null) {
|
||||
MultiverseWorld mvworld = this.plugin.getMVWorldManager().getMVWorld(world);
|
||||
locationString = (mvworld == null)
|
||||
? ChatColor.RED + world.getName() + "!!NOT MULTIVERSE WORLD!!"
|
||||
: mvworld.getColoredWorldString() + " - " + this.plugin.getLocationManipulation().strAxis(anchorLocation);
|
||||
}
|
||||
anchorContent.add(anchor + ": " + locationString);
|
||||
}
|
||||
|
||||
PageDisplay pageDisplay = new PageDisplay(
|
||||
this.plugin,
|
||||
sender,
|
||||
ChatColor.LIGHT_PURPLE + "====[ Multiverse Anchor List ]====",
|
||||
anchorContent,
|
||||
pageFilter,
|
||||
new ColourAlternator(ChatColor.YELLOW, ChatColor.DARK_AQUA)
|
||||
buildAnchorList(sender),
|
||||
pageFilter.getFilter(),
|
||||
new ColourAlternator(ChatColor.YELLOW, ChatColor.DARK_AQUA),
|
||||
pageFilter.getPage(),
|
||||
8
|
||||
);
|
||||
|
||||
pageDisplay.showContentAsync(this.plugin);
|
||||
pageDisplay.showContentAsync();
|
||||
}
|
||||
|
||||
private ContentCreator<List<String>> buildAnchorList(@NotNull CommandSender sender) {
|
||||
return () -> {
|
||||
Set<String> anchors = (sender instanceof Player)
|
||||
? this.anchorManager.getAnchors((Player) sender)
|
||||
: this.anchorManager.getAllAnchors();
|
||||
|
||||
List<String> anchorContent = new ArrayList<>();
|
||||
for (String anchor : anchors) {
|
||||
Location anchorLocation = this.anchorManager.getAnchorLocation(anchor);
|
||||
World world = anchorLocation.getWorld(); // this.plugin.getMVWorldManager().getMVWorld();
|
||||
|
||||
String locationString = ChatColor.RED + "!!INVALID!!";
|
||||
if (world != null) {
|
||||
MultiverseWorld mvworld = this.plugin.getMVWorldManager().getMVWorld(world);
|
||||
locationString = (mvworld == null)
|
||||
? ChatColor.RED + world.getName() + "!!NOT MULTIVERSE WORLD!!"
|
||||
: mvworld.getColoredWorldString() + " - " + this.plugin.getLocationManipulation().strAxis(anchorLocation);
|
||||
}
|
||||
anchorContent.add(anchor + ": " + locationString);
|
||||
}
|
||||
|
||||
return anchorContent;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,11 @@ import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import co.aikar.commands.annotation.Values;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ColourAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.kvpair.KeyValueDisplay;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -36,18 +41,21 @@ public class ConfigCommand extends MultiverseCommand {
|
||||
@Subcommand("list")
|
||||
@Description("Show multiverse config values.")
|
||||
public void onShowCommand(@NotNull CommandSender sender) {
|
||||
List<String> configList = new ArrayList<>();
|
||||
Map<String, Object> serializedConfig = this.plugin.getMVConfig().serialize();
|
||||
KeyValueDisplay display = new KeyValueDisplay(
|
||||
this.plugin,
|
||||
sender,
|
||||
ChatColor.LIGHT_PURPLE + "===[ Multiverse Config ]===",
|
||||
getConfigMap(),
|
||||
new ContentFilter("first"),
|
||||
new ColourAlternator(ChatColor.GREEN, ChatColor.GOLD),
|
||||
" = "
|
||||
);
|
||||
|
||||
for (Map.Entry<String, Object> entry : serializedConfig.entrySet()) {
|
||||
display.showContentAsync();
|
||||
}
|
||||
|
||||
configList.add(ChatColor.GREEN + entry.getKey()
|
||||
+ ChatColor.WHITE + " = "
|
||||
+ ChatColor.GOLD + entry.getValue().toString()
|
||||
+ ChatColor.WHITE);
|
||||
}
|
||||
|
||||
sender.sendMessage(String.join(", ", configList));
|
||||
private ContentCreator<Map<String, Object>> getConfigMap() {
|
||||
return () -> this.plugin.getMVConfig().serialize();
|
||||
}
|
||||
|
||||
@Subcommand("set")
|
||||
|
@ -18,7 +18,9 @@ import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ColourAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.PageDisplay;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.page.PageDisplay;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -51,94 +53,98 @@ public class InfoCommand extends MultiverseCommand {
|
||||
@Default("1") int page) {
|
||||
|
||||
PageDisplay pageDisplay = new PageDisplay(
|
||||
this.plugin,
|
||||
sender,
|
||||
null,
|
||||
buildWorldInfoContent(world),
|
||||
new ContentFilter(null),
|
||||
new ColourAlternator(ChatColor.YELLOW, ChatColor.AQUA),
|
||||
page,
|
||||
10,
|
||||
new ColourAlternator(ChatColor.YELLOW, ChatColor.AQUA)
|
||||
10
|
||||
);
|
||||
|
||||
pageDisplay.showContentAsync(this.plugin);
|
||||
pageDisplay.showContentAsync();
|
||||
}
|
||||
|
||||
private List<String> buildWorldInfoContent(MultiverseWorld world) {
|
||||
List<String> contents = new ArrayList<>(38);
|
||||
private ContentCreator<List<String>> buildWorldInfoContent(MultiverseWorld world) {
|
||||
return () -> {
|
||||
List<String> contents = new ArrayList<>(38);
|
||||
|
||||
// Page 1
|
||||
contents.add(parseHeader("General Info"));
|
||||
contents.add(String.format("World Name: %s%s", ChatColor.WHITE, world.getName()));
|
||||
contents.add(String.format("World Alias: %s%s", ChatColor.WHITE, world.getColoredWorldString()));
|
||||
contents.add(String.format("Game Mode: %s%s", ChatColor.WHITE, world.getGameMode().toString()));
|
||||
contents.add(String.format("Difficulty: %s%s", ChatColor.WHITE, world.getDifficulty().toString()));
|
||||
// Page 1
|
||||
contents.add(parseHeader("General Info"));
|
||||
contents.add(String.format("World Name: %s%s", ChatColor.WHITE, world.getName()));
|
||||
contents.add(String.format("World Alias: %s%s", ChatColor.WHITE, world.getColoredWorldString()));
|
||||
contents.add(String.format("Game Mode: %s%s", ChatColor.WHITE, world.getGameMode().toString()));
|
||||
contents.add(String.format("Difficulty: %s%s", ChatColor.WHITE, world.getDifficulty().toString()));
|
||||
|
||||
Location spawn = world.getSpawnLocation();
|
||||
contents.add(String.format("Spawn Location: %s%s", ChatColor.WHITE, this.plugin.getLocationManipulation().strCoords(spawn)));
|
||||
contents.add(String.format("World Scale: %s%s", ChatColor.WHITE, world.getScaling()));
|
||||
contents.add(String.format("World Seed: %s%s", ChatColor.WHITE, world.getSeed()));
|
||||
Location spawn = world.getSpawnLocation();
|
||||
contents.add(String.format("Spawn Location: %s%s", ChatColor.WHITE, this.plugin.getLocationManipulation().strCoords(spawn)));
|
||||
contents.add(String.format("World Scale: %s%s", ChatColor.WHITE, world.getScaling()));
|
||||
contents.add(String.format("World Seed: %s%s", ChatColor.WHITE, world.getSeed()));
|
||||
|
||||
String priceString = (world.getPrice() == 0)
|
||||
? ChatColor.GREEN + "FREE!"
|
||||
: plugin.getEconomist().formatPrice(-world.getPrice(), world.getCurrency());
|
||||
String priceString = (world.getPrice() == 0)
|
||||
? ChatColor.GREEN + "FREE!"
|
||||
: plugin.getEconomist().formatPrice(-world.getPrice(), world.getCurrency());
|
||||
|
||||
contents.add(String.format((world.getPrice() >= 0)
|
||||
? "Price to enter this world: %s%s"
|
||||
: "Reward for entering this world: %s%s", ChatColor.WHITE, priceString));
|
||||
contents.add(String.format((world.getPrice() >= 0)
|
||||
? "Price to enter this world: %s%s"
|
||||
: "Reward for entering this world: %s%s", ChatColor.WHITE, priceString));
|
||||
|
||||
World respawnWorld = world.getRespawnToWorld();
|
||||
if (respawnWorld != null) {
|
||||
MultiverseWorld respawn = this.plugin.getMVWorldManager().getMVWorld(respawnWorld);
|
||||
String respawnWorldString = (respawn != null)
|
||||
? respawn.getColoredWorldString()
|
||||
: ChatColor.RED + respawnWorld.getName() + " !!INVALID!!";
|
||||
World respawnWorld = world.getRespawnToWorld();
|
||||
if (respawnWorld != null) {
|
||||
MultiverseWorld respawn = this.plugin.getMVWorldManager().getMVWorld(respawnWorld);
|
||||
String respawnWorldString = (respawn != null)
|
||||
? respawn.getColoredWorldString()
|
||||
: ChatColor.RED + respawnWorld.getName() + " !!INVALID!!";
|
||||
|
||||
contents.add(String.format("Players will respawn in: %s%s", ChatColor.WHITE, respawnWorldString));
|
||||
}
|
||||
contents.add("%lf%");
|
||||
contents.add(String.format("Players will respawn in: %s%s", ChatColor.WHITE, respawnWorldString));
|
||||
}
|
||||
contents.add("%lf%");
|
||||
|
||||
// Page 2
|
||||
contents.add(parseHeader("More World Settings"));
|
||||
contents.add(String.format("World UID: %s%s", ChatColor.WHITE, world.getCBWorld().getUID()));
|
||||
contents.add(String.format("World Type: %s%s", ChatColor.WHITE, world.getWorldType().toString()));
|
||||
contents.add(String.format("Generator: %s%s", ChatColor.WHITE, world.getGenerator()));
|
||||
contents.add(String.format("Structures: %s%s", ChatColor.WHITE, world.getCBWorld().canGenerateStructures()));
|
||||
contents.add(String.format("Weather: %s%s", ChatColor.WHITE, world.isWeatherEnabled()));
|
||||
contents.add(String.format("Players will get hungry: %s%s", ChatColor.WHITE, world.getHunger()));
|
||||
contents.add(String.format("Keep spawn in memory: %s%s", ChatColor.WHITE, world.isKeepingSpawnInMemory()));
|
||||
contents.add("%lf%");
|
||||
// Page 2
|
||||
contents.add(parseHeader("More World Settings"));
|
||||
contents.add(String.format("World UID: %s%s", ChatColor.WHITE, world.getCBWorld().getUID()));
|
||||
contents.add(String.format("World Type: %s%s", ChatColor.WHITE, world.getWorldType().toString()));
|
||||
contents.add(String.format("Generator: %s%s", ChatColor.WHITE, world.getGenerator()));
|
||||
contents.add(String.format("Structures: %s%s", ChatColor.WHITE, world.getCBWorld().canGenerateStructures()));
|
||||
contents.add(String.format("Weather: %s%s", ChatColor.WHITE, world.isWeatherEnabled()));
|
||||
contents.add(String.format("Players will get hungry: %s%s", ChatColor.WHITE, world.getHunger()));
|
||||
contents.add(String.format("Keep spawn in memory: %s%s", ChatColor.WHITE, world.isKeepingSpawnInMemory()));
|
||||
contents.add("%lf%");
|
||||
|
||||
// Page 3
|
||||
contents.add(parseHeader("PVP Settings"));
|
||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.isPVPEnabled()));
|
||||
contents.add(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getPVP()));
|
||||
contents.add("%lf%");
|
||||
// Page 3
|
||||
contents.add(parseHeader("PVP Settings"));
|
||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.isPVPEnabled()));
|
||||
contents.add(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getPVP()));
|
||||
contents.add("%lf%");
|
||||
|
||||
// Page 4
|
||||
contents.add(parseHeader("Monster Settings"));
|
||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.canMonstersSpawn()));
|
||||
contents.add(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getAllowMonsters()));
|
||||
// Page 4
|
||||
contents.add(parseHeader("Monster Settings"));
|
||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.canMonstersSpawn()));
|
||||
contents.add(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getAllowMonsters()));
|
||||
|
||||
if (!world.getMonsterList().isEmpty()){
|
||||
contents.add(String.format((world.canMonstersSpawn())
|
||||
? "Monsters that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: %s%s"
|
||||
: "Monsters that" + ChatColor.GREEN + " CAN SPAWN: %s%s",
|
||||
ChatColor.WHITE, toCommaSeparated(world.getMonsterList())));
|
||||
}
|
||||
contents.add("%lf%");
|
||||
if (!world.getMonsterList().isEmpty()){
|
||||
contents.add(String.format((world.canMonstersSpawn())
|
||||
? "Monsters that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: %s%s"
|
||||
: "Monsters that" + ChatColor.GREEN + " CAN SPAWN: %s%s",
|
||||
ChatColor.WHITE, toCommaSeparated(world.getMonsterList())));
|
||||
}
|
||||
contents.add("%lf%");
|
||||
|
||||
// Page 5
|
||||
contents.add(parseHeader("Animal Settings"));
|
||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.canAnimalsSpawn()));
|
||||
contents.add(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getAllowAnimals()));
|
||||
// Page 5
|
||||
contents.add(parseHeader("Animal Settings"));
|
||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.canAnimalsSpawn()));
|
||||
contents.add(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getAllowAnimals()));
|
||||
|
||||
if (!world.getAnimalList().isEmpty()){
|
||||
contents.add(String.format((world.canMonstersSpawn())
|
||||
? "Animals that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: %s%s"
|
||||
: "Animals that" + ChatColor.GREEN + " CAN SPAWN: %s%s",
|
||||
ChatColor.WHITE, toCommaSeparated(world.getAnimalList())));
|
||||
}
|
||||
if (!world.getAnimalList().isEmpty()){
|
||||
contents.add(String.format((world.canMonstersSpawn())
|
||||
? "Animals that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: %s%s"
|
||||
: "Animals that" + ChatColor.GREEN + " CAN SPAWN: %s%s",
|
||||
ChatColor.WHITE, toCommaSeparated(world.getAnimalList())));
|
||||
}
|
||||
|
||||
return contents;
|
||||
return contents;
|
||||
};
|
||||
}
|
||||
|
||||
private String parseHeader(String header) {
|
||||
|
@ -15,7 +15,9 @@ import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.PageDisplay;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ColourAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.page.PageDisplay;
|
||||
import com.onarandombox.MultiverseCore.commandTools.PageFilter;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
@ -42,28 +44,39 @@ public class ListCommand extends MultiverseCommand {
|
||||
@Nullable @Optional Player player,
|
||||
@NotNull PageFilter pageFilter) {
|
||||
|
||||
List<String> worldList = new ArrayList<>();
|
||||
this.plugin.getMVWorldManager().getMVWorlds().stream()
|
||||
.filter(world -> player == null || this.plugin.getMVPerms().canEnterWorld(player, world))
|
||||
.filter(world -> canSeeHidden(player, world))
|
||||
.map(world -> hiddenText(world) + world.getColoredWorldString() + " - " + parseColouredEnvironment(world.getEnvironment()))
|
||||
.sorted()
|
||||
.forEach(worldList::add);
|
||||
|
||||
this.plugin.getMVWorldManager().getUnloadedWorlds().stream()
|
||||
.filter(world -> this.plugin.getMVPerms().hasPermission(sender, "multiverse.access." + world, true))
|
||||
.map(world -> ChatColor.GRAY + world + " - UNLOADED")
|
||||
.sorted()
|
||||
.forEach(worldList::add);
|
||||
|
||||
PageDisplay pageDisplay = new PageDisplay(
|
||||
this.plugin,
|
||||
sender,
|
||||
ChatColor.LIGHT_PURPLE + "====[ Multiverse World List ]====",
|
||||
worldList,
|
||||
pageFilter
|
||||
getListContents(sender, player),
|
||||
pageFilter.getFilter(),
|
||||
new ColourAlternator(ChatColor.WHITE, ChatColor.WHITE),
|
||||
pageFilter.getPage(),
|
||||
8
|
||||
);
|
||||
|
||||
pageDisplay.showContentAsync(this.plugin);
|
||||
pageDisplay.showContentAsync();
|
||||
}
|
||||
|
||||
private ContentCreator<List<String>> getListContents(@NotNull CommandSender sender,
|
||||
@Nullable @Optional Player player) {
|
||||
return () -> {
|
||||
List<String> worldList = new ArrayList<>();
|
||||
plugin.getMVWorldManager().getMVWorlds().stream()
|
||||
.filter(world -> player == null || plugin.getMVPerms().canEnterWorld(player, world))
|
||||
.filter(world -> canSeeHidden(player, world))
|
||||
.map(world -> hiddenText(world) + world.getColoredWorldString() + " - " + parseColouredEnvironment(world.getEnvironment()))
|
||||
.sorted()
|
||||
.forEach(worldList::add);
|
||||
|
||||
plugin.getMVWorldManager().getUnloadedWorlds().stream()
|
||||
.filter(world -> plugin.getMVPerms().hasPermission(sender, "multiverse.access." + world, true))
|
||||
.map(world -> ChatColor.GRAY + world + " - UNLOADED")
|
||||
.sorted()
|
||||
.forEach(worldList::add);
|
||||
|
||||
return worldList;
|
||||
};
|
||||
}
|
||||
|
||||
private boolean canSeeHidden(Player player, MultiverseWorld world) {
|
||||
|
Loading…
Reference in New Issue
Block a user