mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI.git
synced 2024-12-27 03:17:45 +01:00
Merge pull request #800 from PlaceholderAPI/feature/null-parse-option
Add --null argument for Parse command
This commit is contained in:
commit
7afb8ee36d
@ -22,6 +22,7 @@ package me.clip.placeholderapi;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
@ -185,7 +186,7 @@ public final class PlaceholderAPI {
|
||||
continue;
|
||||
}
|
||||
|
||||
String identifier = format.substring(0, index).toLowerCase();
|
||||
String identifier = format.substring(0, index).toLowerCase(Locale.ROOT);
|
||||
String params = format.substring(index + 1);
|
||||
final PlaceholderExpansion expansion = PlaceholderAPIPlugin.getInstance()
|
||||
.getLocalExpansionManager().getExpansion(identifier);
|
||||
|
@ -23,6 +23,7 @@ package me.clip.placeholderapi.commands;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
@ -61,7 +62,7 @@ public abstract class PlaceholderCommand {
|
||||
if (parameter == null) {
|
||||
possible.forEach(suggestions::add);
|
||||
} else {
|
||||
possible.filter(suggestion -> suggestion.toLowerCase().startsWith(parameter.toLowerCase()))
|
||||
possible.filter(suggestion -> suggestion.toLowerCase(Locale.ROOT).startsWith(parameter.toLowerCase(Locale.ROOT)))
|
||||
.forEach(suggestions::add);
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,20 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.impl.cloud.CommandECloud;
|
||||
import me.clip.placeholderapi.commands.impl.local.*;
|
||||
import me.clip.placeholderapi.commands.impl.local.CommandDump;
|
||||
import me.clip.placeholderapi.commands.impl.local.CommandExpansionRegister;
|
||||
import me.clip.placeholderapi.commands.impl.local.CommandExpansionUnregister;
|
||||
import me.clip.placeholderapi.commands.impl.local.CommandHelp;
|
||||
import me.clip.placeholderapi.commands.impl.local.CommandInfo;
|
||||
import me.clip.placeholderapi.commands.impl.local.CommandList;
|
||||
import me.clip.placeholderapi.commands.impl.local.CommandParse;
|
||||
import me.clip.placeholderapi.commands.impl.local.CommandReload;
|
||||
import me.clip.placeholderapi.commands.impl.local.CommandVersion;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -87,7 +96,7 @@ public final class PlaceholderCommandRouter implements CommandExecutor, TabCompl
|
||||
return true;
|
||||
}
|
||||
|
||||
final String search = args[0].toLowerCase();
|
||||
final String search = args[0].toLowerCase(Locale.ROOT);
|
||||
final PlaceholderCommand target = commands.get(search);
|
||||
|
||||
if (target == null) {
|
||||
@ -113,10 +122,10 @@ public final class PlaceholderCommandRouter implements CommandExecutor, TabCompl
|
||||
final List<String> suggestions = new ArrayList<>();
|
||||
|
||||
if (args.length > 1) {
|
||||
final PlaceholderCommand target = this.commands.get(args[0].toLowerCase());
|
||||
final PlaceholderCommand target = this.commands.get(args[0].toLowerCase(Locale.ROOT));
|
||||
|
||||
if (target != null) {
|
||||
target.complete(plugin, sender, args[0].toLowerCase(),
|
||||
target.complete(plugin, sender, args[0].toLowerCase(Locale.ROOT),
|
||||
Arrays.asList(Arrays.copyOfRange(args, 1, args.length)), suggestions);
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
@ -100,7 +101,7 @@ public final class CommandECloud extends PlaceholderCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
final String search = params.get(0).toLowerCase();
|
||||
final String search = params.get(0).toLowerCase(Locale.ROOT);
|
||||
final PlaceholderCommand target = commands.get(search);
|
||||
|
||||
if (target == null) {
|
||||
@ -136,7 +137,7 @@ public final class CommandECloud extends PlaceholderCommand {
|
||||
return; // send sub commands
|
||||
}
|
||||
|
||||
final String search = params.get(0).toLowerCase();
|
||||
final String search = params.get(0).toLowerCase(Locale.ROOT);
|
||||
final PlaceholderCommand target = commands.get(search);
|
||||
|
||||
if (target == null) {
|
||||
|
@ -87,7 +87,7 @@ public final class CommandECloudExpansionList extends PlaceholderCommand {
|
||||
@NotNull
|
||||
private static Collection<CloudExpansion> getExpansions(@NotNull final String target,
|
||||
@NotNull final PlaceholderAPIPlugin plugin) {
|
||||
switch (target.toLowerCase()) {
|
||||
switch (target.toLowerCase(Locale.ROOT)) {
|
||||
case "all":
|
||||
return plugin.getCloudExpansionManager().getCloudExpansions().values();
|
||||
case "installed":
|
||||
@ -112,7 +112,7 @@ public final class CommandECloudExpansionList extends PlaceholderCommand {
|
||||
|
||||
public static void addExpansionTitle(@NotNull final StringBuilder builder,
|
||||
@NotNull final String target, final int page) {
|
||||
switch (target.toLowerCase()) {
|
||||
switch (target.toLowerCase(Locale.ROOT)) {
|
||||
case "all":
|
||||
builder.append("&bAll Expansions");
|
||||
break;
|
||||
|
@ -41,7 +41,7 @@ public final class CommandECloudToggle extends PlaceholderCommand {
|
||||
final boolean desiredState;
|
||||
final boolean currentState = plugin.getPlaceholderAPIConfig().isCloudEnabled();
|
||||
|
||||
switch (alias.toLowerCase()) {
|
||||
switch (alias.toLowerCase(Locale.ROOT)) {
|
||||
case "enable":
|
||||
desiredState = true;
|
||||
break;
|
||||
|
@ -128,7 +128,7 @@ public final class CommandECloudUpdate extends PlaceholderCommand {
|
||||
installed.removeIf(expansion -> !expansion.shouldUpdate());
|
||||
|
||||
if (!installed.isEmpty() && (params.isEmpty() || "all"
|
||||
.startsWith(params.get(0).toLowerCase()))) {
|
||||
.startsWith(params.get(0).toLowerCase(Locale.ROOT)))) {
|
||||
suggestions.add("all");
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ public final class CommandDump extends PlaceholderCommand {
|
||||
|
||||
final String[] jars = plugin.getLocalExpansionManager()
|
||||
.getExpansionsFolder()
|
||||
.list((dir, name) -> name.toLowerCase().endsWith(".jar"));
|
||||
.list((dir, name) -> name.toLowerCase(Locale.ROOT).endsWith(".jar"));
|
||||
|
||||
for (final String jar : jars) {
|
||||
builder.append(" ")
|
||||
|
@ -45,9 +45,9 @@ public final class CommandHelp extends PlaceholderCommand {
|
||||
Msg.msg(sender,
|
||||
"&b&lPlaceholderAPI &8- &7Help Menu &8- &7(&f" + description.getVersion() + "&7)",
|
||||
" ",
|
||||
"&b/papi &fbcparse &9<me/player name> <message>",
|
||||
"&b/papi &fbcparse &9<me|--null|player name> <message>",
|
||||
" &7&oParse a message with placeholders and broadcast it",
|
||||
"&b/papi &fcmdparse &9<me/player> <command with placeholders>",
|
||||
"&b/papi &fcmdparse &9<me|player> <command with placeholders>",
|
||||
" &7&oParse a message with relational placeholders",
|
||||
"&b/papi &fdump",
|
||||
" &7&oDump all relevant information needed to help debug issues into a paste link.",
|
||||
@ -55,7 +55,7 @@ public final class CommandHelp extends PlaceholderCommand {
|
||||
" &7&oView information for a specific expansion",
|
||||
"&b/papi &flist",
|
||||
" &7&oList active expansions",
|
||||
"&b/papi &fparse &9<me/player name> <message>",
|
||||
"&b/papi &fparse &9<me|--null|player name> <message>",
|
||||
" &7&oParse a message with placeholders",
|
||||
"&b/papi &fparserel &9<player one> <player two> <message>",
|
||||
" &7&oParse a message with relational placeholders",
|
||||
|
@ -22,6 +22,7 @@ package me.clip.placeholderapi.commands.impl.local;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
@ -49,7 +50,7 @@ public final class CommandParse extends PlaceholderCommand {
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
switch (alias.toLowerCase()) {
|
||||
switch (alias.toLowerCase(Locale.ROOT)) {
|
||||
case "parserel":
|
||||
evaluateParseRelation(sender, params);
|
||||
break;
|
||||
@ -69,7 +70,7 @@ public final class CommandParse extends PlaceholderCommand {
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
switch (alias.toLowerCase()) {
|
||||
switch (alias.toLowerCase(Locale.ROOT)) {
|
||||
case "parserel":
|
||||
completeParseRelation(params, suggestions);
|
||||
break;
|
||||
@ -92,7 +93,7 @@ public final class CommandParse extends PlaceholderCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
@NotNull final OfflinePlayer player;
|
||||
OfflinePlayer player;
|
||||
|
||||
if ("me".equalsIgnoreCase(params.get(0))) {
|
||||
if (!(sender instanceof Player)) {
|
||||
@ -101,6 +102,8 @@ public final class CommandParse extends PlaceholderCommand {
|
||||
}
|
||||
|
||||
player = ((Player) sender);
|
||||
} else if ("--null".equalsIgnoreCase(params.get(0))) {
|
||||
player = null;
|
||||
} else {
|
||||
final OfflinePlayer target = resolvePlayer(params.get(0));
|
||||
if (target == null) {
|
||||
@ -161,10 +164,14 @@ public final class CommandParse extends PlaceholderCommand {
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() <= 1) {
|
||||
if (sender instanceof Player && (params.isEmpty() || "me"
|
||||
.startsWith(params.get(0).toLowerCase()))) {
|
||||
.startsWith(params.get(0).toLowerCase(Locale.ROOT)))) {
|
||||
suggestions.add("me");
|
||||
}
|
||||
|
||||
|
||||
if ("--null".startsWith(params.get(0).toLowerCase(Locale.ROOT))) {
|
||||
suggestions.add("--null");
|
||||
}
|
||||
|
||||
final Stream<String> names = Bukkit.getOnlinePlayers().stream().map(Player::getName);
|
||||
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
|
||||
|
||||
|
@ -37,6 +37,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@ -88,7 +89,7 @@ public final class CloudExpansionManager {
|
||||
|
||||
@NotNull
|
||||
private static String toIndexName(@NotNull final String name) {
|
||||
return name.toLowerCase().replace(' ', '_');
|
||||
return name.toLowerCase(Locale.ROOT).replace(' ', '_');
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -125,7 +125,7 @@ public final class LocalExpansionManager implements Listener {
|
||||
public PlaceholderExpansion getExpansion(@NotNull final String identifier) {
|
||||
expansionsLock.lock();
|
||||
try {
|
||||
return expansions.get(identifier.toLowerCase());
|
||||
return expansions.get(identifier.toLowerCase(Locale.ROOT));
|
||||
} finally {
|
||||
expansionsLock.unlock();
|
||||
}
|
||||
@ -193,7 +193,7 @@ public final class LocalExpansionManager implements Listener {
|
||||
|
||||
@ApiStatus.Internal
|
||||
public boolean register(@NotNull final PlaceholderExpansion expansion) {
|
||||
final String identifier = expansion.getIdentifier().toLowerCase();
|
||||
final String identifier = expansion.getIdentifier().toLowerCase(Locale.ROOT);
|
||||
|
||||
if (!expansion.canRegister()) {
|
||||
return false;
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
package me.clip.placeholderapi.replacer;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.function.Function;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -49,49 +50,6 @@ public final class CharsReplacer implements Replacer {
|
||||
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
final char l = chars[i];
|
||||
|
||||
if (l == '&' && ++i < chars.length) {
|
||||
final char c = Character.toLowerCase(chars[i]);
|
||||
|
||||
if (c != '0' && c != '1' && c != '2' && c != '3' && c != '4' && c != '5' && c != '6'
|
||||
&& c != '7' && c != '8' && c != '9' && c != 'a' && c != 'b' && c != 'c' && c != 'd'
|
||||
&& c != 'e' && c != 'f' && c != 'k' && c != 'l' && c != 'm' && c != 'n' && c != 'o' && c != 'r'
|
||||
&& c != 'x') {
|
||||
builder.append(l).append(chars[i]);
|
||||
} else {
|
||||
builder.append(ChatColor.COLOR_CHAR);
|
||||
|
||||
if (c != 'x') {
|
||||
builder.append(chars[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((i > 1 && chars[i - 2] == '\\') /*allow escaping &x*/) {
|
||||
builder.setLength(builder.length() - 2);
|
||||
builder.append('&').append(chars[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.append(c);
|
||||
|
||||
int j = 0;
|
||||
while (++j <= 6) {
|
||||
if (i + j >= chars.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
final char x = chars[i + j];
|
||||
builder.append(ChatColor.COLOR_CHAR).append(x);
|
||||
}
|
||||
|
||||
if (j == 7) {
|
||||
i += 6;
|
||||
} else {
|
||||
builder.setLength(builder.length() - (j * 2)); // undo &x parsing
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (l != closure.head || i + 1 >= chars.length) {
|
||||
builder.append(l);
|
||||
@ -99,7 +57,7 @@ public final class CharsReplacer implements Replacer {
|
||||
}
|
||||
|
||||
boolean identified = false;
|
||||
boolean oopsitsbad = true;
|
||||
boolean invalid = true;
|
||||
boolean hadSpace = false;
|
||||
|
||||
while (++i < chars.length) {
|
||||
@ -110,7 +68,7 @@ public final class CharsReplacer implements Replacer {
|
||||
break;
|
||||
}
|
||||
if (p == closure.tail) {
|
||||
oopsitsbad = false;
|
||||
invalid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -127,13 +85,13 @@ public final class CharsReplacer implements Replacer {
|
||||
}
|
||||
|
||||
final String identifierString = identifier.toString();
|
||||
final String lowercaseIdentifierString = identifierString.toLowerCase();
|
||||
final String lowercaseIdentifierString = identifierString.toLowerCase(Locale.ROOT);
|
||||
final String parametersString = parameters.toString();
|
||||
|
||||
identifier.setLength(0);
|
||||
parameters.setLength(0);
|
||||
|
||||
if (oopsitsbad) {
|
||||
if (invalid) {
|
||||
builder.append(closure.head).append(identifierString);
|
||||
|
||||
if (identified) {
|
||||
|
Loading…
Reference in New Issue
Block a user