mirror of
https://github.com/aikar/commands.git
synced 2026-06-15 20:20:36 +00:00
Finish moving all messages to a message key
This commit is contained in:
@@ -32,6 +32,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ACFBungeeUtil {
|
||||
|
||||
@@ -39,12 +40,11 @@ public class ACFBungeeUtil {
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
|
||||
public static void sendMsg(CommandIssuer issuer, MessageKey key, String... replacements) {
|
||||
sendMsg(issuer, MessageType.INFO, key, replacements);
|
||||
}
|
||||
public static void sendMsg(CommandIssuer issuer, MessageType type, MessageKey key, String... replacements) {
|
||||
issuer.sendMessage(type, key, replacements);
|
||||
}
|
||||
/**
|
||||
* Move to Message Keys on the CommandIssuer
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public static void sendMsg(CommandSender player, String message) {
|
||||
message = color(message);
|
||||
for (String msg : ACFPatterns.NEWLINE.split(message)) {
|
||||
@@ -110,8 +110,43 @@ public class ACFBungeeUtil {
|
||||
}
|
||||
|
||||
|
||||
public static ProxiedPlayer findPlayerSmart(CommandSender requester, String origName) {
|
||||
String name = ACFUtil.replace(origName, ":confirm", "");
|
||||
public static ProxiedPlayer findPlayerSmart(CommandIssuer issuer, String search) {
|
||||
CommandSender requester = issuer.getIssuer();
|
||||
String name = ACFUtil.replace(search, ":confirm", "");
|
||||
if (name.length() < 3) {
|
||||
issuer.sendError(BungeeMessageKeys.USERNAME_TOO_SHORT);
|
||||
return null;
|
||||
}
|
||||
if (!isValidName(name)) {
|
||||
issuer.sendError(BungeeMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name);
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ProxiedPlayer> matches = new ArrayList<>(ProxyServer.getInstance().matchPlayer(name));
|
||||
|
||||
if (matches.size() > 1) {
|
||||
String allMatches = matches.stream().map(ProxiedPlayer::getName).collect(Collectors.joining(", "));
|
||||
issuer.sendError(BungeeMessageKeys.MULTIPLE_PLAYERS_MATCH,
|
||||
"{search}", name, "{all}", allMatches);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (matches.isEmpty()) {
|
||||
issuer.sendError(BungeeMessageKeys.NO_PLAYER_FOUND_SERVER,
|
||||
"{search}", name);
|
||||
return null;
|
||||
}
|
||||
|
||||
return matches.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Please move to the CommandIssuer version
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public static ProxiedPlayer findPlayerSmart(CommandSender requester, String search) {
|
||||
String name = ACFUtil.replace(search, ":confirm", "");
|
||||
if (name.length() < 3) {
|
||||
requester.sendMessage("§cUsername too short, must be at least three characters");
|
||||
return null;
|
||||
|
||||
@@ -58,6 +58,7 @@ public class BungeeCommandContexts extends CommandContexts<BungeeCommandExecutio
|
||||
}
|
||||
return proxiedPlayer;
|
||||
});
|
||||
|
||||
registerContext(ChatColor.class, c -> {
|
||||
String first = c.popFirstArg();
|
||||
Stream<ChatColor> colors = Stream.of(ChatColor.values());
|
||||
@@ -74,8 +75,8 @@ public class BungeeCommandContexts extends CommandContexts<BungeeCommandExecutio
|
||||
ChatColor match = ACFUtil.simpleMatch(ChatColor.class, first);
|
||||
if (match == null) {
|
||||
String valid = colors
|
||||
.map(color -> ChatColor.YELLOW + ACFUtil.simplifyString(color.name()))
|
||||
.collect(Collectors.joining("<c2>,</c2> "));
|
||||
.map(color -> "<c2>" + ACFUtil.simplifyString(color.name()) + "</c2>")
|
||||
.collect(Collectors.joining("<c1>,</c1> "));
|
||||
|
||||
throw new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_ONE_OF, "{valid}", valid);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package co.aikar.commands;
|
||||
|
||||
import co.aikar.locales.MessageKey;
|
||||
|
||||
public enum BungeeMessageKeys implements MessageKeyProvider {
|
||||
USERNAME_TOO_SHORT,
|
||||
IS_NOT_A_VALID_NAME,
|
||||
MULTIPLE_PLAYERS_MATCH,
|
||||
NO_PLAYER_FOUND_SERVER,
|
||||
NO_PLAYER_FOUND
|
||||
;
|
||||
|
||||
private final MessageKey key = MessageKey.of(this.name().toLowerCase());
|
||||
public MessageKey getMessageKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user