mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 20:16:06 +01:00
Remove old display implemetations.
This commit is contained in:
parent
c10cd5c45a
commit
139ddd1bb2
@ -15,13 +15,12 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandtools.contexts.RequiredPlayer;
|
||||
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
|
||||
import com.onarandombox.MultiverseCore.commandtools.contexts.GameRuleProperty;
|
||||
import com.onarandombox.MultiverseCore.commandtools.contexts.PageFilter;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.page.PageDisplay;
|
||||
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
|
||||
import com.onarandombox.MultiverseCore.commandtools.contexts.RequiredPlayer;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -381,20 +380,20 @@ public class MVCommandContexts extends PaperCommandContexts {
|
||||
@NotNull
|
||||
private ContentFilter deriveContentFilter(@NotNull BukkitCommandExecutionContext context) {
|
||||
String filterString = context.popFirstArg();
|
||||
return (filterString == null) ? ContentFilter.EMPTY : new ContentFilter(filterString);
|
||||
return (filterString == null) ? ContentFilter.DEFAULT : new ContentFilter(filterString);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PageFilter derivePageFilter(@NotNull BukkitCommandExecutionContext context) {
|
||||
int argLength = context.getArgs().size();
|
||||
if (argLength == 0) {
|
||||
return new PageFilter(ContentFilter.EMPTY, 1);
|
||||
return new PageFilter(ContentFilter.DEFAULT, 1);
|
||||
}
|
||||
if (argLength == 1) {
|
||||
String pageOrFilter = context.popFirstArg();
|
||||
Optional<Integer> page = tryParseInt(pageOrFilter);
|
||||
return page.map(pgNum -> new PageFilter(ContentFilter.EMPTY, pgNum))
|
||||
.orElseGet(() -> new PageFilter(new ContentFilter(pageOrFilter), PageDisplay.FIST_PAGE));
|
||||
return page.map(pageNum -> new PageFilter(ContentFilter.DEFAULT, pageNum))
|
||||
.orElseGet(() -> new PageFilter(new ContentFilter(pageOrFilter), 1));
|
||||
}
|
||||
|
||||
String filter = context.popFirstArg();
|
||||
|
@ -13,8 +13,6 @@ import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.HelpEntry;
|
||||
import co.aikar.commands.PaperCommandManager;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager;
|
||||
import com.onarandombox.MultiverseCore.commands.AnchorCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.BedCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.CheckCommand;
|
||||
@ -48,6 +46,8 @@ import com.onarandombox.MultiverseCore.commands.UnloadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.UsageCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.VersionCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.WhoCommand;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
@ -266,7 +266,8 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
@NotNull String rootCmd) {
|
||||
|
||||
sender.sendMessage(String.format("%s%s %s| %sv%s",
|
||||
color.getThis(), description.getName(), ChatColor.DARK_GRAY, color.getThat(), description.getVersion()));
|
||||
color.getThisColor(), description.getName(), ChatColor.DARK_GRAY,
|
||||
color.getThatColor(), description.getVersion()));
|
||||
|
||||
sender.sendMessage(String.format("%sSee %s/%s help %sfor commands available.",
|
||||
ChatColor.DARK_GREEN, ChatColor.GREEN, rootCmd, ChatColor.DARK_GREEN));
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commandtools.contexts;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -1,64 +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 org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Some helper class to alternate between 2 colours.
|
||||
*/
|
||||
public class ColorAlternator {
|
||||
|
||||
private boolean switcher;
|
||||
private final ChatColor thisColour;
|
||||
private final ChatColor thatColour;
|
||||
|
||||
public ColorAlternator() {
|
||||
this(ChatColor.WHITE, ChatColor.WHITE);
|
||||
}
|
||||
|
||||
public ColorAlternator(@NotNull ChatColor colorThis,
|
||||
@NotNull ChatColor colorThat) {
|
||||
|
||||
this.thisColour = colorThis;
|
||||
this.thatColour = colorThat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives you {@link ColorAlternator#thisColour} or {@link ColorAlternator#thatColour}.
|
||||
*
|
||||
* @return Opposite of the previous colour.
|
||||
*/
|
||||
public @NotNull ChatColor get() {
|
||||
return (switcher ^= true) ? thisColour : thatColour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set back to be {@link ColorAlternator#thisColour} when {@link ColorAlternator#get()} is called.
|
||||
*/
|
||||
public void reset() {
|
||||
switcher = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {@link ColorAlternator#thisColour}.
|
||||
*/
|
||||
public @NotNull ChatColor getThis() {
|
||||
return thisColour;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {@link ColorAlternator#thatColour}.
|
||||
*/
|
||||
public @NotNull ChatColor getThat() {
|
||||
return thatColour;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Generate content for displaying with {@link ContentDisplay}.
|
||||
*
|
||||
* @param <T> Type of content to create.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ContentCreator<T> {
|
||||
@NotNull T generateContent();
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Displays various types of content to sender.
|
||||
*
|
||||
* @param <C> Subclass that inherited this abstract class.
|
||||
* @param <T> Type of content to display.
|
||||
*/
|
||||
public abstract class ContentDisplay<C extends ContentDisplay<?, T>, T> {
|
||||
|
||||
protected CommandSender sender;
|
||||
protected String header;
|
||||
protected ContentCreator<T> creator;
|
||||
protected ContentFilter filter = ContentFilter.EMPTY;
|
||||
protected ColorAlternator colours;
|
||||
protected String emptyMessage = DEFAULT_EMPTY_MESSAGE;
|
||||
|
||||
public static final String DEFAULT_EMPTY_MESSAGE = "No matching content to display.";
|
||||
|
||||
/**
|
||||
* Build into a runnable for showing of content.
|
||||
*
|
||||
* @return {@link ShowRunnable}.
|
||||
*/
|
||||
public ShowRunnable<C, T> build() {
|
||||
buildValidation();
|
||||
return getShowRunnable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults if null and ensure that required fields are not null, else throw exception.
|
||||
*/
|
||||
protected void buildValidation() {
|
||||
if (this.colours == null) {
|
||||
this.colours = new ColorAlternator();
|
||||
}
|
||||
if (sender == null || creator == null) {
|
||||
throw new IllegalStateException("Incomplete ContentDisplay fields.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runnable used to format and display contents to {@link ContentDisplay#sender}
|
||||
*
|
||||
* @return {@link ShowRunnable}
|
||||
*/
|
||||
protected abstract @NotNull ShowRunnable<C, T> getShowRunnable();
|
||||
|
||||
public @NotNull C withSender(@NotNull CommandSender sender) {
|
||||
this.sender = sender;
|
||||
return (C) this;
|
||||
}
|
||||
|
||||
public @NotNull C withHeader(@NotNull String header) {
|
||||
this.header = header;
|
||||
return (C) this;
|
||||
}
|
||||
|
||||
public @NotNull C withCreator(@NotNull ContentCreator<T> creator) {
|
||||
this.creator = creator;
|
||||
return (C) this;
|
||||
}
|
||||
|
||||
public @NotNull C withFilter(@NotNull ContentFilter filter) {
|
||||
this.filter = filter;
|
||||
return (C) this;
|
||||
}
|
||||
|
||||
public @NotNull C withColors(@NotNull ColorAlternator colours) {
|
||||
this.colours = colours;
|
||||
return (C) this;
|
||||
}
|
||||
|
||||
public @NotNull C withEmptyMessage(@NotNull String emptyMessage) {
|
||||
this.emptyMessage = emptyMessage;
|
||||
return (C) this;
|
||||
}
|
||||
|
||||
public @NotNull CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public @Nullable String getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public @NotNull ContentCreator<T> getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
public @NotNull ContentFilter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public @NotNull ColorAlternator getColours() {
|
||||
return colours;
|
||||
}
|
||||
|
||||
public @NotNull String getEmptyMessage() {
|
||||
return emptyMessage;
|
||||
}
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
/**
|
||||
* Filter content and text based on regex.
|
||||
*/
|
||||
public class ContentFilter {
|
||||
private String filterString;
|
||||
private Pattern filterPattern;
|
||||
private boolean exactMatch;
|
||||
|
||||
private static final Pattern REGEX_SPECIAL_CHARS = Pattern.compile("[.+*?\\[^\\]$(){}=!<>|:-\\\\]");
|
||||
|
||||
/**
|
||||
* Empty filter that matches everything.
|
||||
*/
|
||||
public static ContentFilter EMPTY = new ContentFilter();
|
||||
|
||||
public ContentFilter() {
|
||||
}
|
||||
|
||||
public ContentFilter(@NotNull String filterString) {
|
||||
this(filterString, false);
|
||||
}
|
||||
|
||||
public ContentFilter(@NotNull String filterString,
|
||||
boolean exactMatch) {
|
||||
|
||||
this.filterString = filterString;
|
||||
this.exactMatch = exactMatch;
|
||||
parseFilter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile regex pattern based on {@link ContentFilter#filterString}.
|
||||
* When prefixed with 'r=', use {@link ContentFilter#filterString} as the full regex pattern.
|
||||
* Else, set to any match that contains the {@link ContentFilter#filterString}.
|
||||
*/
|
||||
private void parseFilter() {
|
||||
if (filterString == null) {
|
||||
return;
|
||||
}
|
||||
if (filterString.startsWith("r=")) {
|
||||
convertToMatcher(filterString.substring(2));
|
||||
return;
|
||||
}
|
||||
String cleanedFilter = REGEX_SPECIAL_CHARS.matcher(filterString.toLowerCase()).replaceAll("\\\\$0");
|
||||
convertToMatcher("(?i).*" + cleanedFilter + ".*");
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile and store the regex into a {@link Pattern}.
|
||||
*/
|
||||
private void convertToMatcher(@NotNull String regex) {
|
||||
try {
|
||||
this.filterPattern = Pattern.compile(regex);
|
||||
Logging.finest("Parsed regex pattern: %s", this.filterPattern.toString());
|
||||
}
|
||||
catch (PatternSyntaxException ignored) {
|
||||
Logging.warning("Error parsing regex: %s", filterString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do regex matching.
|
||||
*
|
||||
* @param text String to check regex on.
|
||||
* @return True of matches regex pattern, false otherwise.
|
||||
*/
|
||||
public boolean checkMatch(@Nullable String text) {
|
||||
if (!hasFilter()) {
|
||||
return true;
|
||||
}
|
||||
if (text == null || !hasValidPattern()) {
|
||||
return false;
|
||||
}
|
||||
text = ChatColor.stripColor(text);
|
||||
return (exactMatch)
|
||||
? filterPattern.matcher(text).matches()
|
||||
: filterPattern.matcher(text).find();
|
||||
}
|
||||
|
||||
public boolean hasFilter() {
|
||||
return filterString != null;
|
||||
}
|
||||
|
||||
public boolean hasValidPattern() {
|
||||
return filterPattern != null;
|
||||
}
|
||||
|
||||
public @Nullable String getString() {
|
||||
return filterString;
|
||||
}
|
||||
|
||||
public @Nullable Pattern getPattern() {
|
||||
return filterPattern;
|
||||
}
|
||||
|
||||
public boolean isExactMatch() {
|
||||
return exactMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nicely format the filter string to be used for showing the sender.
|
||||
*
|
||||
* @return formatted filter string.
|
||||
*/
|
||||
public @NotNull String getFormattedString() {
|
||||
return String.format("%sFilter: '%s'%s", ChatColor.ITALIC, filterString, ChatColor.RESET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ContentFilter{" +
|
||||
"filterString='" + filterString + '\'' +
|
||||
", filterPattern=" + filterPattern +
|
||||
", exactMatch=" + exactMatch +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <C> {@link ContentDisplay} type that is targted to.
|
||||
* @param <T> Type of content its displaying.
|
||||
*/
|
||||
public abstract class ShowRunnable<C extends ContentDisplay<?, T>, T> extends BukkitRunnable {
|
||||
|
||||
protected final C display;
|
||||
protected T contents;
|
||||
|
||||
protected ShowRunnable(@NotNull C display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the showing of a {@link ContentDisplay}.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
this.contents = this.display.getCreator().generateContent();
|
||||
calculateContent();
|
||||
if (!validateContent()) {
|
||||
return;
|
||||
}
|
||||
display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show header and contents to sender.
|
||||
*/
|
||||
protected void display() {
|
||||
showHeader();
|
||||
if (!hasContentToShow()) {
|
||||
this.display.getSender().sendMessage(this.display.getEmptyMessage());
|
||||
return;
|
||||
}
|
||||
showContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the content to show based on filter, pages or other factors depending on implementation.
|
||||
*/
|
||||
protected abstract void calculateContent();
|
||||
|
||||
/**
|
||||
* Check if there is anything to show after {@link ShowRunnable#calculateContent()}.
|
||||
*
|
||||
* @return True if there is content to show, false otherwise.
|
||||
*/
|
||||
protected abstract boolean hasContentToShow();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return True if valid, false otherwise.
|
||||
*/
|
||||
protected abstract boolean validateContent();
|
||||
|
||||
/**
|
||||
* Displays header to the sender.
|
||||
*/
|
||||
protected abstract void showHeader();
|
||||
|
||||
/**
|
||||
* Displays content to the sender.
|
||||
*/
|
||||
protected abstract void showContent();
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display.inline;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentDisplay;
|
||||
|
||||
public abstract class InlineDisplay<C extends InlineDisplay<?, T>, T> extends ContentDisplay<C, T> {
|
||||
|
||||
protected String prefix = "";
|
||||
protected String suffix = "";
|
||||
protected String separator = DEFAULT_SEPARATOR;
|
||||
|
||||
public static final String DEFAULT_SEPARATOR = ", ";
|
||||
|
||||
public C withPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
return (C) this;
|
||||
}
|
||||
|
||||
public C withSuffix(String suffix) {
|
||||
this.suffix = suffix;
|
||||
return (C) this;
|
||||
}
|
||||
|
||||
public C withSeparator(String separator) {
|
||||
this.separator = separator;
|
||||
return (C) this;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public String getSuffix() {
|
||||
return suffix;
|
||||
}
|
||||
|
||||
public String getSeparator() {
|
||||
return separator;
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display.inline;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Used to display config/property values pair, each separated with a comma.
|
||||
*/
|
||||
public class KeyValueDisplay extends InlineDisplay<KeyValueDisplay, Map<String, Object>> {
|
||||
|
||||
private String operator = DEFAULT_OPERATOR;
|
||||
|
||||
public static final String DEFAULT_OPERATOR = " = ";
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected @NotNull ShowKeyValue getShowRunnable() {
|
||||
return new ShowKeyValue(this);
|
||||
}
|
||||
|
||||
public @NotNull KeyValueDisplay withOperator(@NotNull String operator) {
|
||||
this.operator = operator;
|
||||
return this;
|
||||
}
|
||||
|
||||
public @NotNull String getOperator() {
|
||||
return operator;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display.inline;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Used to display a list, each separated with a comma.
|
||||
*/
|
||||
public class ListDisplay extends InlineDisplay<ListDisplay, List<String>> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected @NotNull ShowList getShowRunnable() {
|
||||
return new ShowList(this);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display.inline;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ShowRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Show the content inline, separated by comma.
|
||||
*
|
||||
* @param <C> A Display that extends {@link InlineDisplay}
|
||||
* @param <T> Content type to show.
|
||||
*/
|
||||
public abstract class ShowInline<C extends InlineDisplay<?, T>, T> extends ShowRunnable<C, T> {
|
||||
|
||||
protected final StringBuilder contentBuilder;
|
||||
|
||||
public ShowInline(@NotNull C display) {
|
||||
super(display);
|
||||
this.contentBuilder = new StringBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected boolean hasContentToShow() {
|
||||
return contentBuilder.length() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected boolean validateContent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void showHeader() {
|
||||
if (this.display.getHeader() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.display.getSender().sendMessage(this.display.getHeader());
|
||||
|
||||
ContentFilter filter = this.display.getFilter();
|
||||
if (filter.hasFilter()) {
|
||||
this.display.getSender().sendMessage(String.format("[ %s ]", filter.getFormattedString()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void showContent() {
|
||||
this.display.getSender().sendMessage(String.format("%s%s%s",
|
||||
this.display.getPrefix(), this.contentBuilder.toString(), this.display.getSuffix()));
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display.inline;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentFilter;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Shows a Map inline, with each key value pair separated by a comma.
|
||||
*/
|
||||
public class ShowKeyValue extends ShowInline<KeyValueDisplay, Map<String, Object>> {
|
||||
|
||||
public ShowKeyValue(@NotNull KeyValueDisplay display) {
|
||||
super(display);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected 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(this.display.getSeparator());
|
||||
}
|
||||
contentBuilder.append(this.display.getColours().getThis())
|
||||
.append(entry.getKey())
|
||||
.append(ChatColor.WHITE)
|
||||
.append(this.display.getOperator())
|
||||
.append(this.display.getColours().getThat())
|
||||
.append(entry.getValue())
|
||||
.append(ChatColor.WHITE);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display.inline;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Show list separated by a comma.
|
||||
*/
|
||||
public class ShowList extends ShowInline<ListDisplay, List<String>> {
|
||||
|
||||
public ShowList(@NotNull ListDisplay display) {
|
||||
super(display);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void calculateContent() {
|
||||
boolean isFirst = true;
|
||||
for (String element : this.contents) {
|
||||
if (!this.display.getFilter().checkMatch(element)) {
|
||||
continue;
|
||||
}
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
}
|
||||
else {
|
||||
contentBuilder.append(this.display.getSeparator());
|
||||
}
|
||||
contentBuilder.append(this.display.getColours().get())
|
||||
.append(element);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Content are displayed inline, separated with a comma.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.commandtools.display.inline;
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Stores classes that help display content to sender in various formatting.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.commandtools.display;
|
@ -1,67 +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.page;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandtools.contexts.PageFilter;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentDisplay;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Used to display list of multiple lines with paging and filter.
|
||||
*/
|
||||
public class PageDisplay extends ContentDisplay<PageDisplay, List<String>> {
|
||||
|
||||
private int pageToShow = FIST_PAGE;
|
||||
private int contentLinesPerPage = DEFAULT_LINES_PER_PAGE; // 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%";
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected @NotNull ShowPage getShowRunnable() {
|
||||
return (this.sender instanceof ConsoleCommandSender)
|
||||
? new ShowAllPage(this)
|
||||
: new ShowSelectedPage(this);
|
||||
}
|
||||
|
||||
public @NotNull PageDisplay withPageFilter(@NotNull PageFilter pageFilter) {
|
||||
this.pageToShow = pageFilter.getPage();
|
||||
this.filter = pageFilter.getFilter();
|
||||
return this;
|
||||
}
|
||||
|
||||
public @NotNull PageDisplay withPage(int pageToShow) {
|
||||
this.pageToShow = pageToShow;
|
||||
return this;
|
||||
}
|
||||
|
||||
public @NotNull PageDisplay withLinesPerPage(int contentLinesPerPage) {
|
||||
this.contentLinesPerPage = contentLinesPerPage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void reduceContentLinesPerPage(int by) {
|
||||
this.contentLinesPerPage -= by;
|
||||
}
|
||||
|
||||
public int getPageToShow() {
|
||||
return pageToShow;
|
||||
}
|
||||
|
||||
public int getContentLinesPerPage() {
|
||||
return contentLinesPerPage;
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display.page;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentFilter;
|
||||
|
||||
/**
|
||||
* Show a everything from a multi-line content.
|
||||
*/
|
||||
public class ShowAllPage extends ShowPage {
|
||||
|
||||
public ShowAllPage(PageDisplay display) {
|
||||
super(display);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void calculateContent() {
|
||||
int index = -1;
|
||||
for (String line : this.contents) {
|
||||
index++;
|
||||
if (PageDisplay.LINE_BREAK_PLACEHOLDER.equals(line)
|
||||
|| this.display.getFilter().checkMatch(this.contents.get(index))) {
|
||||
contentToShowIndex.add(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected boolean validateContent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void showHeader() {
|
||||
if (this.display.getHeader() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.display.getSender().sendMessage(this.display.getHeader().replace(PageDisplay.PAGE_PLACEHOLDER, ""));
|
||||
|
||||
ContentFilter filter = this.display.getFilter();
|
||||
if (filter.hasFilter()) {
|
||||
this.display.getSender().sendMessage(String.format("[ %s ]", filter.getFormattedString()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display.page;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ShowRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Show multi-line contents.
|
||||
*/
|
||||
public abstract class ShowPage extends ShowRunnable<PageDisplay, List<String>> {
|
||||
|
||||
protected final List<Integer> contentToShowIndex;
|
||||
|
||||
public ShowPage(PageDisplay display) {
|
||||
super(display);
|
||||
this.contentToShowIndex = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected boolean hasContentToShow() {
|
||||
return !contentToShowIndex.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void showContent() {
|
||||
ColorAlternator colours = this.display.getColours();
|
||||
colours.reset();
|
||||
|
||||
contentToShowIndex.stream()
|
||||
.map(this.contents::get)
|
||||
.map(line -> line.equals(PageDisplay.LINE_BREAK_PLACEHOLDER)
|
||||
? ""
|
||||
: line.replace(PageDisplay.PAGE_PLACEHOLDER, ""))
|
||||
.map(line -> colours.get() + line)
|
||||
.forEach(this.display.getSender()::sendMessage);
|
||||
}
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.display.page;
|
||||
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentFilter;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* Show a single page from a multi-line content.
|
||||
*/
|
||||
public class ShowSelectedPage extends ShowPage {
|
||||
|
||||
private int totalPages = 1;
|
||||
|
||||
public ShowSelectedPage(PageDisplay display) {
|
||||
super(display);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void display() {
|
||||
super.display();
|
||||
doEndPadding();
|
||||
}
|
||||
|
||||
private void doEndPadding() {
|
||||
IntStream.range(0, this.display.getContentLinesPerPage() - contentToShowIndex.size())
|
||||
.unordered()
|
||||
.mapToObj(i -> " ")
|
||||
.forEach(this.display.getSender()::sendMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void calculateContent() {
|
||||
int lineCount = 0;
|
||||
int index = -1;
|
||||
for (String line : this.contents) {
|
||||
index++;
|
||||
if (PageDisplay.LINE_BREAK_PLACEHOLDER.equals(line)) {
|
||||
lineCount = this.display.getContentLinesPerPage();
|
||||
continue;
|
||||
}
|
||||
if (!this.display.getFilter().checkMatch(line)) {
|
||||
continue;
|
||||
}
|
||||
if (++lineCount > this.display.getContentLinesPerPage()) {
|
||||
totalPages++;
|
||||
lineCount = 1;
|
||||
}
|
||||
if (this.display.getPageToShow() == totalPages) {
|
||||
contentToShowIndex.add(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected boolean validateContent() {
|
||||
return !pageOutOfRange();
|
||||
}
|
||||
|
||||
private boolean pageOutOfRange() {
|
||||
if (this.display.getPageToShow() < 1 || 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void showHeader() {
|
||||
String header = getHeader();
|
||||
|
||||
// Paging inline with header
|
||||
if (header.contains(PageDisplay.PAGE_PLACEHOLDER)) {
|
||||
this.display.getSender().sendMessage(header.replace(PageDisplay.PAGE_PLACEHOLDER, parsePaging()));
|
||||
return;
|
||||
}
|
||||
|
||||
this.display.getSender().sendMessage(header);
|
||||
this.display.getSender().sendMessage(parsePaging());
|
||||
}
|
||||
|
||||
private String getHeader() {
|
||||
if (this.display.getHeader() != null) {
|
||||
return this.display.getHeader();
|
||||
}
|
||||
// Let first content line be the header.
|
||||
this.display.reduceContentLinesPerPage(1);
|
||||
return this.contents.get(contentToShowIndex.remove(0));
|
||||
}
|
||||
|
||||
private String parsePaging() {
|
||||
ContentFilter filter = this.display.getFilter();
|
||||
return (filter.hasFilter())
|
||||
? String.format("[ Page %s of %s, %s ]", this.display.getPageToShow(), totalPages, filter.getFormattedString())
|
||||
: String.format("[ Page %s of %s ]", this.display.getPageToShow(), totalPages);
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Multi line content with paging support.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.commandtools.display.page;
|
@ -17,11 +17,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.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandtools.contexts.PageFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplaySettings;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
|
@ -16,9 +16,9 @@ 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.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -48,7 +48,7 @@ public class ConfigCommand extends MultiverseCoreCommand {
|
||||
.emptyMessage("No config values found.")
|
||||
.displayHandler(DisplayHandlers.INLINE_MAP)
|
||||
.colorTool(ColorAlternator.with(ChatColor.GREEN, ChatColor.GOLD))
|
||||
//TODO: Filter
|
||||
.filter(filter)
|
||||
.display();
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,12 @@ import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandtools.contexts.GameRuleProperty;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.inline.KeyValueDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplaySetting;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplaySettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -53,20 +55,20 @@ public class GameRuleCommand extends MultiverseCoreCommand {
|
||||
|
||||
@NotNull ContentFilter filter) {
|
||||
|
||||
new KeyValueDisplay().withSender(sender)
|
||||
.withHeader(String.format("=== Gamerules for %s%s%s ===", ChatColor.AQUA, world.getName(), ChatColor.WHITE))
|
||||
.withCreator(getGameRuleMap(world))
|
||||
.withFilter(filter)
|
||||
.withColors(new ColorAlternator(ChatColor.GREEN, ChatColor.GOLD))
|
||||
.withOperator(": ")
|
||||
.build()
|
||||
.runTaskAsynchronously(this.plugin);
|
||||
new ContentDisplay.Builder<Map<String, Object>>()
|
||||
.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, ": ")
|
||||
.filter(filter)
|
||||
.display();
|
||||
}
|
||||
|
||||
private ContentCreator<Map<String, Object>> getGameRuleMap(MultiverseWorld world) {
|
||||
return () -> new HashMap<String, Object>() {{
|
||||
private Map<String, Object> getGameRuleMap(MultiverseWorld world) {
|
||||
return new HashMap<String, Object>() {{
|
||||
Arrays.stream(GameRule.values())
|
||||
.unordered()
|
||||
.forEach(gr -> {
|
||||
Object value = world.getCBWorld().getGameRuleValue(gr);
|
||||
if (value != null) {
|
||||
|
@ -18,9 +18,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.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.inline.KeyValueDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -201,16 +201,17 @@ public class ModifyCommand extends MultiverseCoreCommand {
|
||||
|
||||
@NotNull ContentFilter filter) {
|
||||
|
||||
new KeyValueDisplay().withSender(sender)
|
||||
.withHeader(String.format("%s===[ Property Values for %s%s ]===", ChatColor.GOLD, world.getColoredWorldString(), ChatColor.GOLD))
|
||||
.withCreator(generatorModifyList(world))
|
||||
.withFilter(filter)
|
||||
.build()
|
||||
.runTaskAsynchronously(this.plugin);
|
||||
new ContentDisplay.Builder<Map<String, Object>>()
|
||||
.sender(sender)
|
||||
.header("%s===[ Property Values for %s%s ]===", ChatColor.GOLD, world.getColoredWorldString(), ChatColor.GOLD)
|
||||
.contents(generateModifyList(world))
|
||||
.emptyMessage("No properties found.")
|
||||
.displayHandler(DisplayHandlers.INLINE_MAP)
|
||||
.filter(filter)
|
||||
.display();
|
||||
}
|
||||
|
||||
private ContentCreator<Map<String, Object>> generatorModifyList(MultiverseWorld world) {
|
||||
return () -> {
|
||||
private Map<String, Object> generateModifyList(MultiverseWorld world) {
|
||||
Collection<String> properties = world.getAllPropertyTypes();
|
||||
Map<String, Object> propMap = new HashMap<>(properties.size());
|
||||
for (String property : properties) {
|
||||
@ -223,7 +224,6 @@ public class ModifyCommand extends MultiverseCoreCommand {
|
||||
propMap.put(property, value);
|
||||
}
|
||||
return propMap;
|
||||
};
|
||||
}
|
||||
|
||||
private void saveWorldConfig() {
|
||||
|
@ -2,7 +2,7 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -18,7 +18,7 @@ public class RootCommand extends MultiverseCoreCommand {
|
||||
this.plugin.getMVCommandManager().showPluginInfo(
|
||||
sender,
|
||||
this.plugin.getDescription(),
|
||||
new ColorAlternator(ChatColor.GOLD, ChatColor.YELLOW),
|
||||
ColorAlternator.with(ChatColor.GOLD, ChatColor.YELLOW),
|
||||
"mv"
|
||||
);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.HelpCommand;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -25,7 +25,7 @@ public class SubModulesCommand {
|
||||
suggestDownload(
|
||||
sender,
|
||||
"Multiverse-NetherPortals",
|
||||
new ColorAlternator(ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE),
|
||||
ColorAlternator.with(ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE),
|
||||
"https://dev.bukkit.org/projects/multiverse-netherportals"
|
||||
);
|
||||
}
|
||||
@ -43,7 +43,7 @@ public class SubModulesCommand {
|
||||
suggestDownload(
|
||||
sender,
|
||||
"Multiverse-Portals",
|
||||
new ColorAlternator(ChatColor.DARK_RED, ChatColor.RED),
|
||||
ColorAlternator.with(ChatColor.DARK_RED, ChatColor.RED),
|
||||
"https://dev.bukkit.org/projects/multiverse-portals"
|
||||
);
|
||||
}
|
||||
@ -61,7 +61,7 @@ public class SubModulesCommand {
|
||||
suggestDownload(
|
||||
sender,
|
||||
"Multiverse-Inventories",
|
||||
new ColorAlternator(ChatColor.DARK_AQUA, ChatColor.AQUA),
|
||||
ColorAlternator.with(ChatColor.DARK_AQUA, ChatColor.AQUA),
|
||||
"https://dev.bukkit.org/projects/multiverse-inventories"
|
||||
);
|
||||
}
|
||||
@ -73,7 +73,7 @@ public class SubModulesCommand {
|
||||
@NotNull String downloadLink) {
|
||||
|
||||
sender.sendMessage(String.format("%s%s%s is not installed on this server. You can learn more and download it at:",
|
||||
colours.getThis(), pluginName, ChatColor.WHITE));
|
||||
sender.sendMessage(String.format("%s%s", colours.getThat(), downloadLink));
|
||||
colours.getThisColor(), pluginName, ChatColor.WHITE));
|
||||
sender.sendMessage(String.format("%s%s", colours.getThatColor(), downloadLink));
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,12 @@ 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.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandtools.display.inline.ListDisplay;
|
||||
import com.onarandombox.MultiverseCore.commandtools.contexts.PageFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplaySetting;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplaySettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -45,40 +46,23 @@ public class WhoCommand extends MultiverseCoreCommand {
|
||||
@CommandPermission("multiverse.core.list.who.all")
|
||||
@Syntax("[filter]")
|
||||
public void onWhoAllCommand(@NotNull CommandSender sender,
|
||||
@Nullable @Optional Player player,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[filter]")
|
||||
@Description("Filter the player names.")
|
||||
ContentFilter filter) {
|
||||
@Syntax("[filter] [page]")
|
||||
@Description("Filter and paging.")
|
||||
PageFilter pageFilter) {
|
||||
|
||||
Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||
Set<Player> visiblePlayers = getVisiblePlayers(player);
|
||||
|
||||
sender.sendMessage(String.format("%s--- Worlds and their players --- %s%s/%s",
|
||||
ChatColor.GOLD, ChatColor.AQUA, visiblePlayers.size(), this.plugin.getServer().getMaxPlayers()));
|
||||
if (filter.hasFilter()) {
|
||||
sender.sendMessage(String.format("[ %s ]", filter.getFormattedString()));
|
||||
}
|
||||
|
||||
ListDisplay display = new ListDisplay().withSender(sender)
|
||||
.withFilter(filter);
|
||||
|
||||
this.plugin.getMVWorldManager().getMVWorlds().stream()
|
||||
.filter(world -> player == null || this.plugin.getMVPerms().canEnterWorld(player, world))
|
||||
.forEach(world -> showPLayersInWorld(world, display, visiblePlayers));
|
||||
}
|
||||
|
||||
private void showPLayersInWorld(@NotNull MultiverseWorld world,
|
||||
@NotNull ListDisplay display,
|
||||
@NotNull Set<Player> visiblePlayers) {
|
||||
|
||||
String prefix = String.format("%s%s - ", world.getColoredWorldString(), ChatColor.WHITE);
|
||||
|
||||
display.withCreator(() -> buildPlayerList(world, visiblePlayers))
|
||||
.withPrefix(prefix)
|
||||
.withEmptyMessage(String.format("%s%sNo players found.", prefix, ChatColor.GRAY))
|
||||
.build()
|
||||
.run();
|
||||
new ContentDisplay.Builder<Collection<String>>()
|
||||
.sender(sender)
|
||||
.header("%s--- Worlds and their players --- %s%s/%s", ChatColor.GOLD, ChatColor.AQUA, visiblePlayers.size(), this.plugin.getServer().getMaxPlayers())
|
||||
.contents(buildAllWorlds(player, visiblePlayers))
|
||||
.displayHandler(DisplayHandlers.PAGE_LIST)
|
||||
.filter(pageFilter.getFilter())
|
||||
.setting(DisplaySettings.SHOW_PAGE, pageFilter.getPage())
|
||||
.display();
|
||||
}
|
||||
|
||||
@Subcommand("who")
|
||||
@ -111,6 +95,22 @@ public class WhoCommand extends MultiverseCoreCommand {
|
||||
.display();
|
||||
}
|
||||
|
||||
private List<String> buildAllWorlds(@Nullable Player player,
|
||||
@NotNull Set<Player> visiblePlayers) {
|
||||
|
||||
return this.plugin.getMVWorldManager().getMVWorlds().stream()
|
||||
.filter(world -> player == null || this.plugin.getMVPerms().canEnterWorld(player, world))
|
||||
.map(world -> getPLayersInWorld(world, visiblePlayers))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String getPLayersInWorld(@NotNull MultiverseWorld world,
|
||||
@NotNull Set<Player> visiblePlayers) {
|
||||
|
||||
return String.format("%s%s - %s",
|
||||
world.getColoredWorldString(), ChatColor.WHITE, buildPlayerList(world, visiblePlayers));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<String> buildPlayerList(@NotNull MultiverseWorld world,
|
||||
@NotNull Set<Player> visiblePlayers) {
|
||||
|
@ -30,4 +30,12 @@ public class ColorAlternator implements ColorTool {
|
||||
public ChatColor get() {
|
||||
return (this.switcher ^= true) ? this.thisColor : this.thatColor;
|
||||
}
|
||||
|
||||
public ChatColor getThisColor() {
|
||||
return thisColor;
|
||||
}
|
||||
|
||||
public ChatColor getThatColor() {
|
||||
return thatColor;
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class ContentDisplay<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
public Builder<T> header(@NotNull String header, Object...replacements) {
|
||||
this.display.header = String.format(header, replacements);
|
||||
return this;
|
||||
|
Loading…
Reference in New Issue
Block a user