mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 20:16:06 +01:00
Add ContentFilter to commands, and some cleanup.
This commit is contained in:
parent
c8432b9b57
commit
ef073b0403
@ -55,6 +55,7 @@ public class MVCommandContexts extends PaperCommandContexts {
|
||||
registerIssuerAwareContext(Location.class, this::deriveLocation);
|
||||
registerIssuerAwareContext(PasteServiceType.class, this::derivePasteServiceType);
|
||||
registerOptionalContext(String.class, this::deriveString);
|
||||
registerIssuerAwareContext(ContentFilter.class, this::deriveContentFilter);
|
||||
registerOptionalContext(PageFilter.class, this::derivePageFilter);
|
||||
}
|
||||
|
||||
@ -412,12 +413,16 @@ public class MVCommandContexts extends PaperCommandContexts {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ContentFilter deriveContentFilter(@NotNull BukkitCommandExecutionContext context) {
|
||||
return new ContentFilter(context.popFirstArg());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PageFilter derivePageFilter(@NotNull BukkitCommandExecutionContext context) {
|
||||
final int argLength = context.getArgs().size();
|
||||
if (argLength == 0) {
|
||||
return new PageFilter(new ContentFilter(null), 1);
|
||||
return new PageFilter(ContentFilter.EMPTY, 1);
|
||||
}
|
||||
if (argLength == 1) {
|
||||
String pageOrFilter = context.popFirstArg();
|
||||
|
@ -14,6 +14,11 @@ public class ContentFilter {
|
||||
private boolean exactMatch;
|
||||
|
||||
private static final Pattern REGEX_SPECIAL_CHARS = Pattern.compile("[.+*?\\[^\\]$(){}=!<>|:-\\\\]");
|
||||
public static ContentFilter EMPTY = new ContentFilter();
|
||||
|
||||
public ContentFilter() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public ContentFilter(@Nullable String filterString) {
|
||||
this(filterString, false);
|
||||
@ -66,10 +71,6 @@ public class ContentFilter {
|
||||
: filterPattern.matcher(text).find();
|
||||
}
|
||||
|
||||
public void setExactMatch(boolean exactMatch) {
|
||||
this.exactMatch = exactMatch;
|
||||
}
|
||||
|
||||
public boolean hasFilter() {
|
||||
return filterString != null;
|
||||
}
|
||||
|
@ -37,7 +37,8 @@ public class ShowKeyValue extends ShowRunnable<Map<String, Object>> {
|
||||
.append(ChatColor.WHITE)
|
||||
.append(this.display.getOperator())
|
||||
.append(this.display.getColours().getColorThat())
|
||||
.append(entry.getValue());
|
||||
.append(entry.getValue())
|
||||
.append(ChatColor.WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,14 +39,17 @@ public class ConfigCommand extends MultiverseCommand {
|
||||
}
|
||||
|
||||
@Subcommand("list")
|
||||
@Syntax("[filter]")
|
||||
@Description("Show multiverse config values.")
|
||||
public void onShowCommand(@NotNull CommandSender sender) {
|
||||
public void onShowCommand(@NotNull CommandSender sender,
|
||||
@NotNull ContentFilter filter) {
|
||||
|
||||
KeyValueDisplay display = new KeyValueDisplay(
|
||||
this.plugin,
|
||||
sender,
|
||||
ChatColor.LIGHT_PURPLE + "===[ Multiverse Config ]===",
|
||||
getConfigMap(),
|
||||
new ContentFilter("first"),
|
||||
filter,
|
||||
new ColourAlternator(ChatColor.GREEN, ChatColor.GOLD),
|
||||
" = "
|
||||
);
|
||||
|
@ -43,21 +43,23 @@ public class GameRuleCommand extends MultiverseCommand {
|
||||
|
||||
@Subcommand("list")
|
||||
@CommandPermission("multiverse.core.gamerule.list")
|
||||
@Syntax("[world]")
|
||||
@Syntax("[world] [filter]")
|
||||
@CommandCompletion("@MVWorlds")
|
||||
@Description("See the list gamerules values for a given world.")
|
||||
public void onGameRulesCommand(@NotNull CommandSender sender,
|
||||
|
||||
@Syntax("[world]")
|
||||
@Description("World you want to see game rule info.")
|
||||
@NotNull @Flags("other,defaultself") MultiverseWorld world) {
|
||||
@NotNull @Flags("other,defaultself, fallbackself") MultiverseWorld world,
|
||||
|
||||
@NotNull ContentFilter filter) {
|
||||
|
||||
KeyValueDisplay display = new KeyValueDisplay(
|
||||
this.plugin,
|
||||
sender,
|
||||
"=== Gamerules for " + ChatColor.AQUA + world.getName() + ChatColor.WHITE + " ===",
|
||||
getGameRuleMap(world),
|
||||
new ContentFilter(null),
|
||||
filter,
|
||||
new ColourAlternator(ChatColor.GREEN, ChatColor.GOLD),
|
||||
": "
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user