mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-26 04:25:37 +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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public abstract class ContentDisplay {
|
public abstract class ContentDisplay<T> {
|
||||||
|
|
||||||
|
protected final Plugin plugin;
|
||||||
protected final CommandSender sender;
|
protected final CommandSender sender;
|
||||||
protected final String header;
|
protected final String header;
|
||||||
|
protected final ContentCreator<T> creator;
|
||||||
protected final ContentFilter filter;
|
protected final ContentFilter filter;
|
||||||
protected final ColourAlternator colours;
|
protected final ColourAlternator colours;
|
||||||
|
|
||||||
public ContentDisplay(@NotNull CommandSender sender,
|
public ContentDisplay(Plugin plugin, @NotNull CommandSender sender,
|
||||||
@Nullable String header,
|
@Nullable String header,
|
||||||
|
@NotNull ContentCreator<T> creator,
|
||||||
@NotNull ContentFilter filter,
|
@NotNull ContentFilter filter,
|
||||||
@Nullable ColourAlternator colours) {
|
@Nullable ColourAlternator colours) {
|
||||||
|
|
||||||
|
this.plugin = plugin;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.header = header;
|
this.header = header;
|
||||||
|
this.creator = creator;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
this.colours = colours;
|
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() {
|
public CommandSender getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
@ -35,6 +46,10 @@ public abstract class ContentDisplay {
|
|||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ContentCreator<T> getCreator() {
|
||||||
|
return creator;
|
||||||
|
}
|
||||||
|
|
||||||
public ContentFilter getFilter() {
|
public ContentFilter getFilter() {
|
||||||
return filter;
|
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 {
|
public class ShowAllPage extends ShowPage {
|
||||||
|
|
||||||
@ -9,10 +13,10 @@ public class ShowAllPage extends ShowPage {
|
|||||||
@Override
|
@Override
|
||||||
public void calculateContent() {
|
public void calculateContent() {
|
||||||
int index = -1;
|
int index = -1;
|
||||||
for (String line : this.display.getContents()) {
|
for (String line : this.contents) {
|
||||||
index++;
|
index++;
|
||||||
if (PageDisplay.LINE_BREAK_PLACEHOLDER.equals(line)
|
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);
|
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 com.onarandombox.MultiverseCore.commandTools.display.ColourAlternator;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import com.onarandombox.MultiverseCore.commandTools.display.ShowRunnable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class ShowPage extends BukkitRunnable {
|
public abstract class ShowPage extends ShowRunnable<List<String>> {
|
||||||
|
|
||||||
protected PageDisplay display;
|
protected PageDisplay display;
|
||||||
protected final List<Integer> contentToShowIndex;
|
protected final List<Integer> contentToShowIndex;
|
||||||
|
|
||||||
public ShowPage(PageDisplay display) {
|
public ShowPage(PageDisplay display) {
|
||||||
|
super(display);
|
||||||
this.display = display;
|
this.display = display;
|
||||||
this.contentToShowIndex = new ArrayList<>();
|
this.contentToShowIndex = new ArrayList<>();
|
||||||
|
|
||||||
@ -33,22 +34,12 @@ public abstract class ShowPage extends BukkitRunnable {
|
|||||||
display();
|
display();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display() {
|
@Override
|
||||||
showHeader();
|
|
||||||
showContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void calculateContent();
|
|
||||||
|
|
||||||
public abstract boolean validateContent();
|
|
||||||
|
|
||||||
public abstract void showHeader();
|
|
||||||
|
|
||||||
public void showContent() {
|
public void showContent() {
|
||||||
ColourAlternator colours = this.display.getColours();
|
ColourAlternator colours = this.display.getColours();
|
||||||
|
|
||||||
contentToShowIndex.stream()
|
contentToShowIndex.stream()
|
||||||
.map(this.display.getContents()::get)
|
.map(this.contents::get)
|
||||||
.map(line -> line.equals(PageDisplay.LINE_BREAK_PLACEHOLDER)
|
.map(line -> line.equals(PageDisplay.LINE_BREAK_PLACEHOLDER)
|
||||||
? ""
|
? ""
|
||||||
: line.replace(PageDisplay.PAGE_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;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@ -20,7 +22,7 @@ public class ShowSelectedPage extends ShowPage {
|
|||||||
public void calculateContent() {
|
public void calculateContent() {
|
||||||
int lineCount = 0;
|
int lineCount = 0;
|
||||||
int index = -1;
|
int index = -1;
|
||||||
for (String line : this.display.getContents()) {
|
for (String line : this.contents) {
|
||||||
index++;
|
index++;
|
||||||
if (PageDisplay.LINE_BREAK_PLACEHOLDER.equals(line)) {
|
if (PageDisplay.LINE_BREAK_PLACEHOLDER.equals(line)) {
|
||||||
lineCount = this.display.getContentLinesPerPage();
|
lineCount = this.display.getContentLinesPerPage();
|
||||||
@ -44,11 +46,21 @@ public class ShowSelectedPage extends ShowPage {
|
|||||||
return !pageOutOfRange();
|
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
|
@Override
|
||||||
public void showHeader() {
|
public void showHeader() {
|
||||||
String theHeader;
|
String theHeader;
|
||||||
if (this.display.getHeader() == null) {
|
if (this.display.getHeader() == null) {
|
||||||
theHeader = this.display.getContents().get(contentToShowIndex.remove(0));
|
theHeader = this.contents.get(contentToShowIndex.remove(0));
|
||||||
this.display.reduceContentLinesPerPage(1);
|
this.display.reduceContentLinesPerPage(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -63,16 +75,6 @@ public class ShowSelectedPage extends ShowPage {
|
|||||||
this.display.getSender().sendMessage(parsePaging());
|
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() {
|
private String parsePaging() {
|
||||||
ContentFilter filter = this.display.getFilter();
|
ContentFilter filter = this.display.getFilter();
|
||||||
return (filter.hasFilter())
|
return (filter.hasFilter())
|
@ -18,7 +18,8 @@ import co.aikar.commands.annotation.Syntax;
|
|||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||||
import com.onarandombox.MultiverseCore.commandTools.display.ColourAlternator;
|
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.commandTools.PageFilter;
|
||||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -81,33 +82,42 @@ public class AnchorCommand extends MultiverseCommand {
|
|||||||
public void onListAnchorCommand(@NotNull CommandSender sender,
|
public void onListAnchorCommand(@NotNull CommandSender sender,
|
||||||
@NotNull PageFilter pageFilter) {
|
@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(
|
PageDisplay pageDisplay = new PageDisplay(
|
||||||
|
this.plugin,
|
||||||
sender,
|
sender,
|
||||||
ChatColor.LIGHT_PURPLE + "====[ Multiverse Anchor List ]====",
|
ChatColor.LIGHT_PURPLE + "====[ Multiverse Anchor List ]====",
|
||||||
anchorContent,
|
buildAnchorList(sender),
|
||||||
pageFilter,
|
pageFilter.getFilter(),
|
||||||
new ColourAlternator(ChatColor.YELLOW, ChatColor.DARK_AQUA)
|
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.Syntax;
|
||||||
import co.aikar.commands.annotation.Values;
|
import co.aikar.commands.annotation.Values;
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
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.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -36,18 +41,21 @@ public class ConfigCommand extends MultiverseCommand {
|
|||||||
@Subcommand("list")
|
@Subcommand("list")
|
||||||
@Description("Show multiverse config values.")
|
@Description("Show multiverse config values.")
|
||||||
public void onShowCommand(@NotNull CommandSender sender) {
|
public void onShowCommand(@NotNull CommandSender sender) {
|
||||||
List<String> configList = new ArrayList<>();
|
KeyValueDisplay display = new KeyValueDisplay(
|
||||||
Map<String, Object> serializedConfig = this.plugin.getMVConfig().serialize();
|
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()
|
private ContentCreator<Map<String, Object>> getConfigMap() {
|
||||||
+ ChatColor.WHITE + " = "
|
return () -> this.plugin.getMVConfig().serialize();
|
||||||
+ ChatColor.GOLD + entry.getValue().toString()
|
|
||||||
+ ChatColor.WHITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(String.join(", ", configList));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subcommand("set")
|
@Subcommand("set")
|
||||||
|
@ -18,7 +18,9 @@ import co.aikar.commands.annotation.Syntax;
|
|||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||||
import com.onarandombox.MultiverseCore.commandTools.display.ColourAlternator;
|
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.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -51,94 +53,98 @@ public class InfoCommand extends MultiverseCommand {
|
|||||||
@Default("1") int page) {
|
@Default("1") int page) {
|
||||||
|
|
||||||
PageDisplay pageDisplay = new PageDisplay(
|
PageDisplay pageDisplay = new PageDisplay(
|
||||||
|
this.plugin,
|
||||||
sender,
|
sender,
|
||||||
null,
|
null,
|
||||||
buildWorldInfoContent(world),
|
buildWorldInfoContent(world),
|
||||||
|
new ContentFilter(null),
|
||||||
|
new ColourAlternator(ChatColor.YELLOW, ChatColor.AQUA),
|
||||||
page,
|
page,
|
||||||
10,
|
10
|
||||||
new ColourAlternator(ChatColor.YELLOW, ChatColor.AQUA)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
pageDisplay.showContentAsync(this.plugin);
|
pageDisplay.showContentAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> buildWorldInfoContent(MultiverseWorld world) {
|
private ContentCreator<List<String>> buildWorldInfoContent(MultiverseWorld world) {
|
||||||
List<String> contents = new ArrayList<>(38);
|
return () -> {
|
||||||
|
List<String> contents = new ArrayList<>(38);
|
||||||
|
|
||||||
// Page 1
|
// Page 1
|
||||||
contents.add(parseHeader("General Info"));
|
contents.add(parseHeader("General Info"));
|
||||||
contents.add(String.format("World Name: %s%s", ChatColor.WHITE, world.getName()));
|
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("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("Game Mode: %s%s", ChatColor.WHITE, world.getGameMode().toString()));
|
||||||
contents.add(String.format("Difficulty: %s%s", ChatColor.WHITE, world.getDifficulty().toString()));
|
contents.add(String.format("Difficulty: %s%s", ChatColor.WHITE, world.getDifficulty().toString()));
|
||||||
|
|
||||||
Location spawn = world.getSpawnLocation();
|
Location spawn = world.getSpawnLocation();
|
||||||
contents.add(String.format("Spawn Location: %s%s", ChatColor.WHITE, this.plugin.getLocationManipulation().strCoords(spawn)));
|
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 Scale: %s%s", ChatColor.WHITE, world.getScaling()));
|
||||||
contents.add(String.format("World Seed: %s%s", ChatColor.WHITE, world.getSeed()));
|
contents.add(String.format("World Seed: %s%s", ChatColor.WHITE, world.getSeed()));
|
||||||
|
|
||||||
String priceString = (world.getPrice() == 0)
|
String priceString = (world.getPrice() == 0)
|
||||||
? ChatColor.GREEN + "FREE!"
|
? ChatColor.GREEN + "FREE!"
|
||||||
: plugin.getEconomist().formatPrice(-world.getPrice(), world.getCurrency());
|
: plugin.getEconomist().formatPrice(-world.getPrice(), world.getCurrency());
|
||||||
|
|
||||||
contents.add(String.format((world.getPrice() >= 0)
|
contents.add(String.format((world.getPrice() >= 0)
|
||||||
? "Price to enter this world: %s%s"
|
? "Price to enter this world: %s%s"
|
||||||
: "Reward for entering this world: %s%s", ChatColor.WHITE, priceString));
|
: "Reward for entering this world: %s%s", ChatColor.WHITE, priceString));
|
||||||
|
|
||||||
World respawnWorld = world.getRespawnToWorld();
|
World respawnWorld = world.getRespawnToWorld();
|
||||||
if (respawnWorld != null) {
|
if (respawnWorld != null) {
|
||||||
MultiverseWorld respawn = this.plugin.getMVWorldManager().getMVWorld(respawnWorld);
|
MultiverseWorld respawn = this.plugin.getMVWorldManager().getMVWorld(respawnWorld);
|
||||||
String respawnWorldString = (respawn != null)
|
String respawnWorldString = (respawn != null)
|
||||||
? respawn.getColoredWorldString()
|
? respawn.getColoredWorldString()
|
||||||
: ChatColor.RED + respawnWorld.getName() + " !!INVALID!!";
|
: ChatColor.RED + respawnWorld.getName() + " !!INVALID!!";
|
||||||
|
|
||||||
contents.add(String.format("Players will respawn in: %s%s", ChatColor.WHITE, respawnWorldString));
|
contents.add(String.format("Players will respawn in: %s%s", ChatColor.WHITE, respawnWorldString));
|
||||||
}
|
}
|
||||||
contents.add("%lf%");
|
contents.add("%lf%");
|
||||||
|
|
||||||
// Page 2
|
// Page 2
|
||||||
contents.add(parseHeader("More World Settings"));
|
contents.add(parseHeader("More World Settings"));
|
||||||
contents.add(String.format("World UID: %s%s", ChatColor.WHITE, world.getCBWorld().getUID()));
|
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("World Type: %s%s", ChatColor.WHITE, world.getWorldType().toString()));
|
||||||
contents.add(String.format("Generator: %s%s", ChatColor.WHITE, world.getGenerator()));
|
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("Structures: %s%s", ChatColor.WHITE, world.getCBWorld().canGenerateStructures()));
|
||||||
contents.add(String.format("Weather: %s%s", ChatColor.WHITE, world.isWeatherEnabled()));
|
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("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(String.format("Keep spawn in memory: %s%s", ChatColor.WHITE, world.isKeepingSpawnInMemory()));
|
||||||
contents.add("%lf%");
|
contents.add("%lf%");
|
||||||
|
|
||||||
// Page 3
|
// Page 3
|
||||||
contents.add(parseHeader("PVP Settings"));
|
contents.add(parseHeader("PVP Settings"));
|
||||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.isPVPEnabled()));
|
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(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getPVP()));
|
||||||
contents.add("%lf%");
|
contents.add("%lf%");
|
||||||
|
|
||||||
// Page 4
|
// Page 4
|
||||||
contents.add(parseHeader("Monster Settings"));
|
contents.add(parseHeader("Monster Settings"));
|
||||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.canMonstersSpawn()));
|
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()));
|
contents.add(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getAllowMonsters()));
|
||||||
|
|
||||||
if (!world.getMonsterList().isEmpty()){
|
if (!world.getMonsterList().isEmpty()){
|
||||||
contents.add(String.format((world.canMonstersSpawn())
|
contents.add(String.format((world.canMonstersSpawn())
|
||||||
? "Monsters that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: %s%s"
|
? "Monsters that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: %s%s"
|
||||||
: "Monsters that" + ChatColor.GREEN + " CAN SPAWN: %s%s",
|
: "Monsters that" + ChatColor.GREEN + " CAN SPAWN: %s%s",
|
||||||
ChatColor.WHITE, toCommaSeparated(world.getMonsterList())));
|
ChatColor.WHITE, toCommaSeparated(world.getMonsterList())));
|
||||||
}
|
}
|
||||||
contents.add("%lf%");
|
contents.add("%lf%");
|
||||||
|
|
||||||
// Page 5
|
// Page 5
|
||||||
contents.add(parseHeader("Animal Settings"));
|
contents.add(parseHeader("Animal Settings"));
|
||||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.canAnimalsSpawn()));
|
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()));
|
contents.add(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getAllowAnimals()));
|
||||||
|
|
||||||
if (!world.getAnimalList().isEmpty()){
|
if (!world.getAnimalList().isEmpty()){
|
||||||
contents.add(String.format((world.canMonstersSpawn())
|
contents.add(String.format((world.canMonstersSpawn())
|
||||||
? "Animals that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: %s%s"
|
? "Animals that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: %s%s"
|
||||||
: "Animals that" + ChatColor.GREEN + " CAN SPAWN: %s%s",
|
: "Animals that" + ChatColor.GREEN + " CAN SPAWN: %s%s",
|
||||||
ChatColor.WHITE, toCommaSeparated(world.getAnimalList())));
|
ChatColor.WHITE, toCommaSeparated(world.getAnimalList())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return contents;
|
return contents;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private String parseHeader(String header) {
|
private String parseHeader(String header) {
|
||||||
|
@ -15,7 +15,9 @@ import co.aikar.commands.annotation.Subcommand;
|
|||||||
import co.aikar.commands.annotation.Syntax;
|
import co.aikar.commands.annotation.Syntax;
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
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 com.onarandombox.MultiverseCore.commandTools.PageFilter;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -42,28 +44,39 @@ public class ListCommand extends MultiverseCommand {
|
|||||||
@Nullable @Optional Player player,
|
@Nullable @Optional Player player,
|
||||||
@NotNull PageFilter pageFilter) {
|
@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(
|
PageDisplay pageDisplay = new PageDisplay(
|
||||||
|
this.plugin,
|
||||||
sender,
|
sender,
|
||||||
ChatColor.LIGHT_PURPLE + "====[ Multiverse World List ]====",
|
ChatColor.LIGHT_PURPLE + "====[ Multiverse World List ]====",
|
||||||
worldList,
|
getListContents(sender, player),
|
||||||
pageFilter
|
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) {
|
private boolean canSeeHidden(Player player, MultiverseWorld world) {
|
||||||
|
Loading…
Reference in New Issue
Block a user