diff --git a/docs/acf-bukkit/co/aikar/commands/BukkitCommandManager.html b/docs/acf-bukkit/co/aikar/commands/BukkitCommandManager.html index 3f6c3bec..28692138 100644 --- a/docs/acf-bukkit/co/aikar/commands/BukkitCommandManager.html +++ b/docs/acf-bukkit/co/aikar/commands/BukkitCommandManager.html @@ -113,7 +113,7 @@ var activeTableTab = "activeTableTab";


  • -
    public class BukkitCommandManager
    +
    public class BukkitCommandManager
     extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>
  • @@ -365,7 +365,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • plugin

    -
    protected final org.bukkit.plugin.Plugin plugin
    +
    protected final org.bukkit.plugin.Plugin plugin
  • @@ -374,7 +374,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • mcMinorVersion

    -
    public final Integer mcMinorVersion
    +
    public final Integer mcMinorVersion
  • @@ -383,7 +383,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • mcPatchVersion

    -
    public final Integer mcPatchVersion
    +
    public final Integer mcPatchVersion
  • @@ -392,7 +392,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • knownCommands

    -
    protected Map<String,org.bukkit.command.Command> knownCommands
    +
    protected Map<String,org.bukkit.command.Command> knownCommands
  • @@ -401,7 +401,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • registeredCommands

    -
    protected Map<String,BukkitRootCommand> registeredCommands
    +
    protected Map<String,BukkitRootCommand> registeredCommands
  • @@ -410,7 +410,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • contexts

    -
    protected BukkitCommandContexts contexts
    +
    protected BukkitCommandContexts contexts
  • @@ -419,7 +419,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • completions

    -
    protected BukkitCommandCompletions completions
    +
    protected BukkitCommandCompletions completions
  • @@ -428,7 +428,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • locales

    -
    protected BukkitLocales locales
    +
    protected BukkitLocales locales
  • @@ -437,7 +437,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • autoDetectFromClient

    -
    protected boolean autoDetectFromClient
    +
    protected boolean autoDetectFromClient
  • @@ -454,7 +454,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • BukkitCommandManager

    -
    public BukkitCommandManager(org.bukkit.plugin.Plugin plugin)
    +
    public BukkitCommandManager(org.bukkit.plugin.Plugin plugin)
  • @@ -471,7 +471,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • getPlugin

    -
    public org.bukkit.plugin.Plugin getPlugin()
    +
    public org.bukkit.plugin.Plugin getPlugin()
  • @@ -480,7 +480,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • isCommandIssuer

    -
    public boolean isCommandIssuer(Class<?> type)
    +
    public boolean isCommandIssuer(Class<?> type)
    Specified by:
    isCommandIssuer in class co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>
    @@ -493,7 +493,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • getCommandContexts

    -
    public co.aikar.commands.CommandContexts<BukkitCommandExecutionContextgetCommandContexts()
    +
    public co.aikar.commands.CommandContexts<BukkitCommandExecutionContextgetCommandContexts()
    Specified by:
    getCommandContexts in class co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>
    @@ -506,7 +506,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • getCommandCompletions

    -
    public co.aikar.commands.CommandCompletions<BukkitCommandCompletionContextgetCommandCompletions()
    +
    public co.aikar.commands.CommandCompletions<BukkitCommandCompletionContextgetCommandCompletions()
    Specified by:
    getCommandCompletions in class co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>
    @@ -519,7 +519,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • getLocales

    -
    public BukkitLocales getLocales()
    +
    public BukkitLocales getLocales()
    Specified by:
    getLocales in class co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>
    @@ -532,7 +532,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • hasRegisteredCommands

    -
    public boolean hasRegisteredCommands()
    +
    public boolean hasRegisteredCommands()
    Specified by:
    hasRegisteredCommands in class co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>
    @@ -545,7 +545,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • registerCommand

    -
    public void registerCommand(co.aikar.commands.BaseCommand command,
    +
    public void registerCommand(co.aikar.commands.BaseCommand command,
                                 boolean force)
  • @@ -555,7 +555,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • registerCommand

    -
    public void registerCommand(co.aikar.commands.BaseCommand command)
    +
    public void registerCommand(co.aikar.commands.BaseCommand command)
    Specified by:
    registerCommand in class co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>
    @@ -568,7 +568,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,
  • unregisterCommand

    -
    public void unregisterCommand(co.aikar.commands.BaseCommand command)
    +
    public void unregisterCommand(co.aikar.commands.BaseCommand command)
  • @@ -578,7 +578,7 @@ extends co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,

    unregisterCommand

    @Deprecated
    -public void unregisterCommand(BukkitRootCommand command)
    +public void unregisterCommand(BukkitRootCommand command)
    Deprecated. Use unregisterCommand(BaseCommand) - this will be visibility reduced later.
    Parameters:
    @@ -592,7 +592,7 @@ public void 
  • unregisterCommands

    -
    public void unregisterCommands()
    +
    public void unregisterCommands()
  • @@ -601,7 +601,7 @@ public void 
  • setPlayerLocale

    -
    public Locale setPlayerLocale(org.bukkit.entity.Player player,
    +
    public Locale setPlayerLocale(org.bukkit.entity.Player player,
                                   Locale locale)
  • @@ -611,7 +611,7 @@ public void 
  • getTimings

    -
    public co.aikar.timings.lib.TimingManager getTimings()
    +
    public co.aikar.timings.lib.TimingManager getTimings()
  • @@ -620,7 +620,7 @@ public void 
  • createRootCommand

    -
    public co.aikar.commands.RootCommand createRootCommand(String cmd)
    +
    public co.aikar.commands.RootCommand createRootCommand(String cmd)
    Specified by:
    createRootCommand in class co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>
    @@ -633,7 +633,7 @@ public void 
  • getRegisteredRootCommands

    -
    public Collection<co.aikar.commands.RootCommand> getRegisteredRootCommands()
    +
    public Collection<co.aikar.commands.RootCommand> getRegisteredRootCommands()
    Specified by:
    getRegisteredRootCommands in class co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>
    @@ -646,7 +646,7 @@ public void 
  • getCommandIssuer

    -
    public BukkitCommandIssuer getCommandIssuer(Object issuer)
    +
    public BukkitCommandIssuer getCommandIssuer(Object issuer)
    Specified by:
    getCommandIssuer in class co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>
    @@ -659,7 +659,7 @@ public void 
  • createCommandContext

    -
    public BukkitCommandExecutionContext createCommandContext(co.aikar.commands.RegisteredCommand command,
    +
    public BukkitCommandExecutionContext createCommandContext(co.aikar.commands.RegisteredCommand command,
                                                               co.aikar.commands.CommandParameter parameter,
                                                               co.aikar.commands.CommandIssuer sender,
                                                               List<String> args,
    @@ -677,7 +677,7 @@ public void 
     
  • createCompletionContext

    -
    public BukkitCommandCompletionContext createCompletionContext(co.aikar.commands.RegisteredCommand command,
    +
    public BukkitCommandCompletionContext createCompletionContext(co.aikar.commands.RegisteredCommand command,
                                                                   co.aikar.commands.CommandIssuer sender,
                                                                   String input,
                                                                   String config,
    @@ -694,7 +694,7 @@ public void 
     
  • createRegisteredCommand

    -
    public co.aikar.commands.RegisteredCommand createRegisteredCommand(co.aikar.commands.BaseCommand command,
    +
    public co.aikar.commands.RegisteredCommand createRegisteredCommand(co.aikar.commands.BaseCommand command,
                                                                        String cmdName,
                                                                        Method method,
                                                                        String prefSubCommand)
    @@ -710,7 +710,7 @@ public void 
  • createConditionContext

    -
    public BukkitConditionContext createConditionContext(co.aikar.commands.CommandIssuer issuer,
    +
    public BukkitConditionContext createConditionContext(co.aikar.commands.CommandIssuer issuer,
                                                          String config)
    Overrides:
    @@ -724,7 +724,7 @@ public void 
  • log

    -
    public void log(co.aikar.commands.LogLevel level,
    +
    public void log(co.aikar.commands.LogLevel level,
                     String message,
                     Throwable throwable)
    @@ -739,7 +739,7 @@ public void 
  • usePerIssuerLocale

    -
    public boolean usePerIssuerLocale(boolean usePerIssuerLocale,
    +
    public boolean usePerIssuerLocale(boolean usePerIssuerLocale,
                                       boolean autoDetectFromClient)
  • @@ -749,7 +749,7 @@ public void 
  • getCommandPrefix

    -
    public String getCommandPrefix(co.aikar.commands.CommandIssuer issuer)
    +
    public String getCommandPrefix(co.aikar.commands.CommandIssuer issuer)
    Overrides:
    getCommandPrefix in class co.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>
    @@ -762,7 +762,7 @@ public void 
  • handleUncaughtException

    -
    protected boolean handleUncaughtException(co.aikar.commands.BaseCommand scope,
    +
    protected boolean handleUncaughtException(co.aikar.commands.BaseCommand scope,
                                               co.aikar.commands.RegisteredCommand registeredCommand,
                                               co.aikar.commands.CommandIssuer sender,
                                               List<String> args,
    diff --git a/docs/acf-bukkit/co/aikar/commands/BukkitLocales.html b/docs/acf-bukkit/co/aikar/commands/BukkitLocales.html
    index ea49fc07..ae0fbaad 100644
    --- a/docs/acf-bukkit/co/aikar/commands/BukkitLocales.html
    +++ b/docs/acf-bukkit/co/aikar/commands/BukkitLocales.html
    @@ -132,7 +132,7 @@ extends co.aikar.commands.Locales

    Fields inherited from class co.aikar.commands.Locales

    -AFRIKAANS, ARABIC, BULGARIAN, CHINESE, CZECH, DANISH, DUTCH, ENGLISH, FINNISH, FRENCH, GERMAN, GREEK, HEBREW, HINDI, ITALIAN, JAPANESE, KOREAN, LATIN, NORWEGIAN_BOKMAAL, NORWEGIAN_NYNORSK, POLISH, PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED_CHINESE, SPANISH, SWEDISH, THAI, TRADITIONAL_CHINESE, TURKISH, UKRANIAN, VIETNAMESE, WELSH
  • +AFRIKAANS, ARABIC, BULGARIAN, CHINESE, CZECH, DANISH, DUTCH, ENGLISH, FINNISH, FRENCH, GERMAN, GREEK, HEBREW, HINDI, HUNGARIAN, ITALIAN, JAPANESE, KOREAN, LATIN, NORWEGIAN_BOKMAAL, NORWEGIAN_NYNORSK, POLISH, PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED_CHINESE, SPANISH, SWEDISH, THAI, TRADITIONAL_CHINESE, TURKISH, UKRANIAN, VIETNAMESE, WELSH
  • diff --git a/docs/acf-bukkit/src-html/co/aikar/commands/BukkitCommandManager.html b/docs/acf-bukkit/src-html/co/aikar/commands/BukkitCommandManager.html index 79d93b61..6279c4d1 100644 --- a/docs/acf-bukkit/src-html/co/aikar/commands/BukkitCommandManager.html +++ b/docs/acf-bukkit/src-html/co/aikar/commands/BukkitCommandManager.html @@ -60,355 +60,357 @@ 052import java.util.Collection; 053import java.util.Collections; 054import java.util.HashMap; -055import java.util.List; -056import java.util.Locale; -057import java.util.Map; -058import java.util.Objects; -059import java.util.logging.Level; -060import java.util.logging.Logger; -061import java.util.regex.Matcher; -062import java.util.regex.Pattern; -063 -064@SuppressWarnings("WeakerAccess") -065public class BukkitCommandManager extends CommandManager< -066 CommandSender, -067 BukkitCommandIssuer, -068 ChatColor, -069 BukkitMessageFormatter, -070 BukkitCommandExecutionContext, -071 BukkitConditionContext -072 > { -073 -074 @SuppressWarnings("WeakerAccess") -075 protected final Plugin plugin; -076 private final CommandMap commandMap; -077 private final TimingManager timingManager; -078 private final BukkitTask localeTask; -079 private final Logger logger; -080 public final Integer mcMinorVersion; -081 public final Integer mcPatchVersion; -082 protected Map<String, Command> knownCommands = new HashMap<>(); -083 protected Map<String, BukkitRootCommand> registeredCommands = new HashMap<>(); -084 protected BukkitCommandContexts contexts; -085 protected BukkitCommandCompletions completions; -086 MCTiming commandTiming; -087 protected BukkitLocales locales; -088 private boolean cantReadLocale = false; -089 protected boolean autoDetectFromClient = true; -090 -091 @SuppressWarnings("JavaReflectionMemberAccess") -092 public BukkitCommandManager(Plugin plugin) { -093 this.plugin = plugin; -094 this.logger = Logger.getLogger(this.plugin.getName()); -095 this.timingManager = TimingManager.of(plugin); -096 this.commandTiming = this.timingManager.of("Commands"); -097 this.commandMap = hookCommandMap(); -098 this.formatters.put(MessageType.ERROR, defaultFormatter = new BukkitMessageFormatter(ChatColor.RED, ChatColor.YELLOW, ChatColor.RED)); -099 this.formatters.put(MessageType.SYNTAX, new BukkitMessageFormatter(ChatColor.YELLOW, ChatColor.GREEN, ChatColor.WHITE)); -100 this.formatters.put(MessageType.INFO, new BukkitMessageFormatter(ChatColor.BLUE, ChatColor.DARK_GREEN, ChatColor.GREEN)); -101 this.formatters.put(MessageType.HELP, new BukkitMessageFormatter(ChatColor.AQUA, ChatColor.GREEN, ChatColor.YELLOW)); -102 Pattern versionPattern = Pattern.compile("\\(MC: (\\d)\\.(\\d+)\\.?(\\d+?)?\\)"); -103 Matcher matcher = versionPattern.matcher(Bukkit.getVersion()); -104 if (matcher.find()) { -105 this.mcMinorVersion = ACFUtil.parseInt(matcher.toMatchResult().group(2), 0); -106 this.mcPatchVersion = ACFUtil.parseInt(matcher.toMatchResult().group(3), 0); -107 } else { -108 this.mcMinorVersion = -1; -109 this.mcPatchVersion = -1; -110 } -111 Bukkit.getHelpMap().registerHelpTopicFactory(BukkitRootCommand.class, command -> { -112 if (hasUnstableAPI("help")) { -113 return new ACFBukkitHelpTopic(this, (BukkitRootCommand) command); -114 } else { -115 return new GenericCommandHelpTopic(command); -116 } -117 }); -118 -119 Bukkit.getPluginManager().registerEvents(new ACFBukkitListener(this, plugin), plugin); -120 -121 getLocales(); // auto load locales -122 this.localeTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> { -123 if (this.cantReadLocale || !this.autoDetectFromClient) { -124 return; -125 } -126 Bukkit.getOnlinePlayers().forEach(this::readPlayerLocale); -127 }, 5, 5); -128 -129 registerDependency(plugin.getClass(), plugin); -130 registerDependency(Logger.class, plugin.getLogger()); -131 registerDependency(FileConfiguration.class, plugin.getConfig()); -132 registerDependency(FileConfiguration.class, "config", plugin.getConfig()); -133 registerDependency(Plugin.class, plugin); -134 registerDependency(JavaPlugin.class, plugin); -135 registerDependency(PluginManager.class, Bukkit.getPluginManager()); -136 registerDependency(Server.class, Bukkit.getServer()); -137 registerDependency(BukkitScheduler.class, Bukkit.getScheduler()); -138 registerDependency(ScoreboardManager.class, Bukkit.getScoreboardManager()); -139 registerDependency(ItemFactory.class, Bukkit.getItemFactory()); -140 } -141 -142 @NotNull -143 private CommandMap hookCommandMap() { -144 CommandMap commandMap = null; -145 try { -146 Server server = Bukkit.getServer(); -147 Method getCommandMap = server.getClass().getDeclaredMethod("getCommandMap"); -148 getCommandMap.setAccessible(true); -149 commandMap = (CommandMap) getCommandMap.invoke(server); -150 if (!SimpleCommandMap.class.isAssignableFrom(commandMap.getClass())) { -151 this.log(LogLevel.ERROR, "ERROR: CommandMap has been hijacked! Offending command map is located at: " + commandMap.getClass().getName()); -152 this.log(LogLevel.ERROR, "We are going to try to hijack it back and resolve this, but you are now in dangerous territory."); -153 this.log(LogLevel.ERROR, "We can not guarantee things are going to work."); -154 Field cmField = server.getClass().getDeclaredField("commandMap"); -155 commandMap = new ProxyCommandMap(this, commandMap); -156 cmField.set(server, commandMap); -157 this.log(LogLevel.INFO, "Injected Proxy Command Map... good luck..."); -158 } -159 Field knownCommands = SimpleCommandMap.class.getDeclaredField("knownCommands"); -160 knownCommands.setAccessible(true); -161 //noinspection unchecked -162 this.knownCommands = (Map<String, Command>) knownCommands.get(commandMap); -163 } catch (Exception e) { -164 this.log(LogLevel.ERROR, "Failed to get Command Map. ACF will not function."); -165 ACFUtil.sneaky(e); -166 } -167 return commandMap; -168 } -169 -170 public Plugin getPlugin() { -171 return this.plugin; -172 } -173 -174 @Override -175 public boolean isCommandIssuer(Class<?> type) { -176 return CommandSender.class.isAssignableFrom(type); -177 } -178 -179 @Override -180 public synchronized CommandContexts<BukkitCommandExecutionContext> getCommandContexts() { -181 if (this.contexts == null) { -182 this.contexts = new BukkitCommandContexts(this); -183 } -184 return contexts; -185 } -186 -187 @Override -188 public synchronized CommandCompletions<BukkitCommandCompletionContext> getCommandCompletions() { -189 if (this.completions == null) { -190 this.completions = new BukkitCommandCompletions(this); -191 } -192 return completions; -193 } -194 +055import java.util.HashSet; +056import java.util.List; +057import java.util.Locale; +058import java.util.Map; +059import java.util.Objects; +060import java.util.logging.Level; +061import java.util.logging.Logger; +062import java.util.regex.Matcher; +063import java.util.regex.Pattern; +064 +065@SuppressWarnings("WeakerAccess") +066public class BukkitCommandManager extends CommandManager< +067 CommandSender, +068 BukkitCommandIssuer, +069 ChatColor, +070 BukkitMessageFormatter, +071 BukkitCommandExecutionContext, +072 BukkitConditionContext +073 > { +074 +075 @SuppressWarnings("WeakerAccess") +076 protected final Plugin plugin; +077 private final CommandMap commandMap; +078 private final TimingManager timingManager; +079 private final BukkitTask localeTask; +080 private final Logger logger; +081 public final Integer mcMinorVersion; +082 public final Integer mcPatchVersion; +083 protected Map<String, Command> knownCommands = new HashMap<>(); +084 protected Map<String, BukkitRootCommand> registeredCommands = new HashMap<>(); +085 protected BukkitCommandContexts contexts; +086 protected BukkitCommandCompletions completions; +087 MCTiming commandTiming; +088 protected BukkitLocales locales; +089 private boolean cantReadLocale = false; +090 protected boolean autoDetectFromClient = true; +091 +092 @SuppressWarnings("JavaReflectionMemberAccess") +093 public BukkitCommandManager(Plugin plugin) { +094 this.plugin = plugin; +095 this.logger = Logger.getLogger(this.plugin.getName()); +096 this.timingManager = TimingManager.of(plugin); +097 this.commandTiming = this.timingManager.of("Commands"); +098 this.commandMap = hookCommandMap(); +099 this.formatters.put(MessageType.ERROR, defaultFormatter = new BukkitMessageFormatter(ChatColor.RED, ChatColor.YELLOW, ChatColor.RED)); +100 this.formatters.put(MessageType.SYNTAX, new BukkitMessageFormatter(ChatColor.YELLOW, ChatColor.GREEN, ChatColor.WHITE)); +101 this.formatters.put(MessageType.INFO, new BukkitMessageFormatter(ChatColor.BLUE, ChatColor.DARK_GREEN, ChatColor.GREEN)); +102 this.formatters.put(MessageType.HELP, new BukkitMessageFormatter(ChatColor.AQUA, ChatColor.GREEN, ChatColor.YELLOW)); +103 Pattern versionPattern = Pattern.compile("\\(MC: (\\d)\\.(\\d+)\\.?(\\d+?)?\\)"); +104 Matcher matcher = versionPattern.matcher(Bukkit.getVersion()); +105 if (matcher.find()) { +106 this.mcMinorVersion = ACFUtil.parseInt(matcher.toMatchResult().group(2), 0); +107 this.mcPatchVersion = ACFUtil.parseInt(matcher.toMatchResult().group(3), 0); +108 } else { +109 this.mcMinorVersion = -1; +110 this.mcPatchVersion = -1; +111 } +112 Bukkit.getHelpMap().registerHelpTopicFactory(BukkitRootCommand.class, command -> { +113 if (hasUnstableAPI("help")) { +114 return new ACFBukkitHelpTopic(this, (BukkitRootCommand) command); +115 } else { +116 return new GenericCommandHelpTopic(command); +117 } +118 }); +119 +120 Bukkit.getPluginManager().registerEvents(new ACFBukkitListener(this, plugin), plugin); +121 +122 getLocales(); // auto load locales +123 this.localeTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> { +124 if (this.cantReadLocale || !this.autoDetectFromClient) { +125 return; +126 } +127 Bukkit.getOnlinePlayers().forEach(this::readPlayerLocale); +128 }, 5, 5); +129 +130 registerDependency(plugin.getClass(), plugin); +131 registerDependency(Logger.class, plugin.getLogger()); +132 registerDependency(FileConfiguration.class, plugin.getConfig()); +133 registerDependency(FileConfiguration.class, "config", plugin.getConfig()); +134 registerDependency(Plugin.class, plugin); +135 registerDependency(JavaPlugin.class, plugin); +136 registerDependency(PluginManager.class, Bukkit.getPluginManager()); +137 registerDependency(Server.class, Bukkit.getServer()); +138 registerDependency(BukkitScheduler.class, Bukkit.getScheduler()); +139 registerDependency(ScoreboardManager.class, Bukkit.getScoreboardManager()); +140 registerDependency(ItemFactory.class, Bukkit.getItemFactory()); +141 } +142 +143 @NotNull +144 private CommandMap hookCommandMap() { +145 CommandMap commandMap = null; +146 try { +147 Server server = Bukkit.getServer(); +148 Method getCommandMap = server.getClass().getDeclaredMethod("getCommandMap"); +149 getCommandMap.setAccessible(true); +150 commandMap = (CommandMap) getCommandMap.invoke(server); +151 if (!SimpleCommandMap.class.isAssignableFrom(commandMap.getClass())) { +152 this.log(LogLevel.ERROR, "ERROR: CommandMap has been hijacked! Offending command map is located at: " + commandMap.getClass().getName()); +153 this.log(LogLevel.ERROR, "We are going to try to hijack it back and resolve this, but you are now in dangerous territory."); +154 this.log(LogLevel.ERROR, "We can not guarantee things are going to work."); +155 Field cmField = server.getClass().getDeclaredField("commandMap"); +156 commandMap = new ProxyCommandMap(this, commandMap); +157 cmField.set(server, commandMap); +158 this.log(LogLevel.INFO, "Injected Proxy Command Map... good luck..."); +159 } +160 Field knownCommands = SimpleCommandMap.class.getDeclaredField("knownCommands"); +161 knownCommands.setAccessible(true); +162 //noinspection unchecked +163 this.knownCommands = (Map<String, Command>) knownCommands.get(commandMap); +164 } catch (Exception e) { +165 this.log(LogLevel.ERROR, "Failed to get Command Map. ACF will not function."); +166 ACFUtil.sneaky(e); +167 } +168 return commandMap; +169 } +170 +171 public Plugin getPlugin() { +172 return this.plugin; +173 } +174 +175 @Override +176 public boolean isCommandIssuer(Class<?> type) { +177 return CommandSender.class.isAssignableFrom(type); +178 } +179 +180 @Override +181 public synchronized CommandContexts<BukkitCommandExecutionContext> getCommandContexts() { +182 if (this.contexts == null) { +183 this.contexts = new BukkitCommandContexts(this); +184 } +185 return contexts; +186 } +187 +188 @Override +189 public synchronized CommandCompletions<BukkitCommandCompletionContext> getCommandCompletions() { +190 if (this.completions == null) { +191 this.completions = new BukkitCommandCompletions(this); +192 } +193 return completions; +194 } 195 -196 @Override -197 public BukkitLocales getLocales() { -198 if (this.locales == null) { -199 this.locales = new BukkitLocales(this); -200 this.locales.loadLanguages(); -201 } -202 return locales; -203 } -204 +196 +197 @Override +198 public BukkitLocales getLocales() { +199 if (this.locales == null) { +200 this.locales = new BukkitLocales(this); +201 this.locales.loadLanguages(); +202 } +203 return locales; +204 } 205 -206 @Override -207 public boolean hasRegisteredCommands() { -208 return !registeredCommands.isEmpty(); -209 } -210 -211 public void registerCommand(BaseCommand command, boolean force) { -212 final String plugin = this.plugin.getName().toLowerCase(); -213 command.onRegister(this); -214 for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) { -215 String commandName = entry.getKey().toLowerCase(); -216 BukkitRootCommand bukkitCommand = (BukkitRootCommand) entry.getValue(); -217 if (!bukkitCommand.isRegistered) { -218 Command oldCommand = commandMap.getCommand(commandName); -219 if (oldCommand instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) oldCommand).getPlugin() == this.plugin) { -220 knownCommands.remove(commandName); -221 oldCommand.unregister(commandMap); -222 } else if (oldCommand != null && force) { -223 knownCommands.remove(commandName); -224 for (Map.Entry<String, Command> ce : knownCommands.entrySet()) { -225 String key = ce.getKey(); -226 Command value = ce.getValue(); -227 if (key.contains(":") && oldCommand.equals(value)) { -228 String[] split = ACFPatterns.COLON.split(key, 2); -229 if (split.length > 1) { -230 oldCommand.unregister(commandMap); -231 oldCommand.setLabel(split[0] + ":" + command.getName()); -232 oldCommand.register(commandMap); -233 } -234 } -235 } -236 } -237 commandMap.register(commandName, plugin, bukkitCommand); -238 } -239 bukkitCommand.isRegistered = true; -240 registeredCommands.put(commandName, bukkitCommand); -241 } -242 } -243 -244 @Override -245 public void registerCommand(BaseCommand command) { -246 registerCommand(command, false); -247 } -248 -249 public void unregisterCommand(BaseCommand command) { -250 for (RootCommand rootcommand : command.registeredCommands.values()) { -251 BukkitRootCommand bukkitCommand = (BukkitRootCommand) rootcommand; -252 bukkitCommand.getSubCommands().values().removeAll(command.subCommands.values()); -253 if (bukkitCommand.isRegistered && bukkitCommand.getSubCommands().isEmpty()) { -254 unregisterCommand(bukkitCommand); -255 bukkitCommand.isRegistered = false; -256 } -257 } -258 } -259 -260 /** -261 * @param command -262 * @deprecated Use unregisterCommand(BaseCommand) - this will be visibility reduced later. -263 */ -264 @Deprecated -265 public void unregisterCommand(BukkitRootCommand command) { -266 final String plugin = this.plugin.getName().toLowerCase(); -267 command.unregister(commandMap); -268 String key = command.getName(); -269 Command registered = knownCommands.get(key); -270 if (command.equals(registered)) { -271 knownCommands.remove(key); -272 } -273 knownCommands.remove(plugin + ":" + key); -274 } -275 -276 public void unregisterCommands() { -277 for (Map.Entry<String, BukkitRootCommand> entry : registeredCommands.entrySet()) { -278 unregisterCommand(entry.getValue()); -279 } -280 this.registeredCommands.clear(); -281 } -282 +206 +207 @Override +208 public boolean hasRegisteredCommands() { +209 return !registeredCommands.isEmpty(); +210 } +211 +212 public void registerCommand(BaseCommand command, boolean force) { +213 final String plugin = this.plugin.getName().toLowerCase(); +214 command.onRegister(this); +215 for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) { +216 String commandName = entry.getKey().toLowerCase(); +217 BukkitRootCommand bukkitCommand = (BukkitRootCommand) entry.getValue(); +218 if (!bukkitCommand.isRegistered) { +219 Command oldCommand = commandMap.getCommand(commandName); +220 if (oldCommand instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) oldCommand).getPlugin() == this.plugin) { +221 knownCommands.remove(commandName); +222 oldCommand.unregister(commandMap); +223 } else if (oldCommand != null && force) { +224 knownCommands.remove(commandName); +225 for (Map.Entry<String, Command> ce : knownCommands.entrySet()) { +226 String key = ce.getKey(); +227 Command value = ce.getValue(); +228 if (key.contains(":") && oldCommand.equals(value)) { +229 String[] split = ACFPatterns.COLON.split(key, 2); +230 if (split.length > 1) { +231 oldCommand.unregister(commandMap); +232 oldCommand.setLabel(split[0] + ":" + command.getName()); +233 oldCommand.register(commandMap); +234 } +235 } +236 } +237 } +238 commandMap.register(commandName, plugin, bukkitCommand); +239 } +240 bukkitCommand.isRegistered = true; +241 registeredCommands.put(commandName, bukkitCommand); +242 } +243 } +244 +245 @Override +246 public void registerCommand(BaseCommand command) { +247 registerCommand(command, false); +248 } +249 +250 public void unregisterCommand(BaseCommand command) { +251 for (RootCommand rootcommand : command.registeredCommands.values()) { +252 BukkitRootCommand bukkitCommand = (BukkitRootCommand) rootcommand; +253 bukkitCommand.getSubCommands().values().removeAll(command.subCommands.values()); +254 if (bukkitCommand.isRegistered && bukkitCommand.getSubCommands().isEmpty()) { +255 unregisterCommand(bukkitCommand); +256 bukkitCommand.isRegistered = false; +257 } +258 } +259 } +260 +261 /** +262 * @param command +263 * @deprecated Use unregisterCommand(BaseCommand) - this will be visibility reduced later. +264 */ +265 @Deprecated +266 public void unregisterCommand(BukkitRootCommand command) { +267 final String plugin = this.plugin.getName().toLowerCase(); +268 command.unregister(commandMap); +269 String key = command.getName(); +270 Command registered = knownCommands.get(key); +271 if (command.equals(registered)) { +272 knownCommands.remove(key); +273 } +274 knownCommands.remove(plugin + ":" + key); +275 registeredCommands.remove(key); +276 } +277 +278 public void unregisterCommands() { +279 for (String key : new HashSet<>(registeredCommands.keySet())) { +280 unregisterCommand(registeredCommands.get(key)); +281 } +282 } 283 -284 private Field getEntityField(Player player) throws NoSuchFieldException { -285 Class cls = player.getClass(); -286 while (cls != Object.class) { -287 if (cls.getName().endsWith("CraftEntity")) { -288 Field field = cls.getDeclaredField("entity"); -289 field.setAccessible(true); -290 return field; -291 } -292 cls = cls.getSuperclass(); -293 } -294 return null; -295 } -296 -297 public Locale setPlayerLocale(Player player, Locale locale) { -298 return this.setIssuerLocale(player, locale); -299 } -300 -301 void readPlayerLocale(Player player) { -302 if (!player.isOnline() || cantReadLocale) { -303 return; -304 } -305 try { -306 Field entityField = getEntityField(player); -307 if (entityField == null) { -308 return; -309 } -310 Object nmsPlayer = entityField.get(player); -311 if (nmsPlayer != null) { -312 Field localeField = nmsPlayer.getClass().getDeclaredField("locale"); -313 Object localeString = localeField.get(nmsPlayer); -314 if (localeString instanceof String) { -315 String[] split = ACFPatterns.UNDERSCORE.split((String) localeString); -316 Locale locale = split.length > 1 ? new Locale(split[0], split[1]) : new Locale(split[0]); -317 Locale prev = issuersLocale.put(player.getUniqueId(), locale); -318 if (!Objects.equals(locale, prev)) { -319 this.notifyLocaleChange(getCommandIssuer(player), prev, locale); -320 } -321 } -322 } -323 } catch (Exception e) { -324 cantReadLocale = true; -325 this.localeTask.cancel(); -326 this.log(LogLevel.INFO, "Can't read players locale, you will be unable to automatically detect players language. Only Bukkit 1.7+ is supported for this.", e); -327 } -328 } -329 -330 public TimingManager getTimings() { -331 return timingManager; -332 } -333 -334 @Override -335 public RootCommand createRootCommand(String cmd) { -336 return new BukkitRootCommand(this, cmd); -337 } -338 -339 @Override -340 public Collection<RootCommand> getRegisteredRootCommands() { -341 return Collections.unmodifiableCollection(registeredCommands.values()); -342 } -343 -344 @Override -345 public BukkitCommandIssuer getCommandIssuer(Object issuer) { -346 if (!(issuer instanceof CommandSender)) { -347 throw new IllegalArgumentException(issuer.getClass().getName() + " is not a Command Issuer."); -348 } -349 return new BukkitCommandIssuer(this, (CommandSender) issuer); -350 } -351 -352 @Override -353 public BukkitCommandExecutionContext createCommandContext(RegisteredCommand command, CommandParameter parameter, CommandIssuer sender, List<String> args, int i, Map<String, Object> passedArgs) { -354 return new BukkitCommandExecutionContext(command, parameter, (BukkitCommandIssuer) sender, args, i, passedArgs); -355 } -356 -357 @Override -358 public BukkitCommandCompletionContext createCompletionContext(RegisteredCommand command, CommandIssuer sender, String input, String config, String[] args) { -359 return new BukkitCommandCompletionContext(command, (BukkitCommandIssuer) sender, input, config, args); -360 } -361 -362 @Override -363 public RegisteredCommand createRegisteredCommand(BaseCommand command, String cmdName, Method method, String prefSubCommand) { -364 return new BukkitRegisteredCommand(command, cmdName, method, prefSubCommand); -365 } -366 -367 @Override -368 public BukkitConditionContext createConditionContext(CommandIssuer issuer, String config) { -369 return new BukkitConditionContext((BukkitCommandIssuer) issuer, config); -370 } -371 -372 -373 @Override -374 public void log(LogLevel level, String message, Throwable throwable) { -375 Level logLevel = level == LogLevel.INFO ? Level.INFO : Level.SEVERE; -376 logger.log(logLevel, LogLevel.LOG_PREFIX + message); -377 if (throwable != null) { -378 for (String line : ACFPatterns.NEWLINE.split(ApacheCommonsExceptionUtil.getFullStackTrace(throwable))) { -379 logger.log(logLevel, LogLevel.LOG_PREFIX + line); -380 } -381 } -382 } -383 -384 public boolean usePerIssuerLocale(boolean usePerIssuerLocale, boolean autoDetectFromClient) { -385 boolean old = this.usePerIssuerLocale; -386 this.usePerIssuerLocale = usePerIssuerLocale; -387 this.autoDetectFromClient = autoDetectFromClient; -388 return old; -389 } -390 -391 @Override -392 public String getCommandPrefix(CommandIssuer issuer) { -393 return issuer.isPlayer() ? "/" : ""; -394 } -395 -396 @Override -397 protected boolean handleUncaughtException(BaseCommand scope, RegisteredCommand registeredCommand, CommandIssuer sender, List<String> args, Throwable t) { -398 if (t instanceof CommandException && t.getCause() != null && t.getMessage().startsWith("Unhandled exception")) { -399 t = t.getCause(); -400 } -401 return super.handleUncaughtException(scope, registeredCommand, sender, args, t); -402 } -403} +284 +285 private Field getEntityField(Player player) throws NoSuchFieldException { +286 Class cls = player.getClass(); +287 while (cls != Object.class) { +288 if (cls.getName().endsWith("CraftEntity")) { +289 Field field = cls.getDeclaredField("entity"); +290 field.setAccessible(true); +291 return field; +292 } +293 cls = cls.getSuperclass(); +294 } +295 return null; +296 } +297 +298 public Locale setPlayerLocale(Player player, Locale locale) { +299 return this.setIssuerLocale(player, locale); +300 } +301 +302 void readPlayerLocale(Player player) { +303 if (!player.isOnline() || cantReadLocale) { +304 return; +305 } +306 try { +307 Field entityField = getEntityField(player); +308 if (entityField == null) { +309 return; +310 } +311 Object nmsPlayer = entityField.get(player); +312 if (nmsPlayer != null) { +313 Field localeField = nmsPlayer.getClass().getDeclaredField("locale"); +314 localeField.setAccessible(true); +315 Object localeString = localeField.get(nmsPlayer); +316 if (localeString instanceof String) { +317 String[] split = ACFPatterns.UNDERSCORE.split((String) localeString); +318 Locale locale = split.length > 1 ? new Locale(split[0], split[1]) : new Locale(split[0]); +319 Locale prev = issuersLocale.put(player.getUniqueId(), locale); +320 if (!Objects.equals(locale, prev)) { +321 this.notifyLocaleChange(getCommandIssuer(player), prev, locale); +322 } +323 } +324 } +325 } catch (Exception e) { +326 cantReadLocale = true; +327 this.localeTask.cancel(); +328 this.log(LogLevel.INFO, "Can't read players locale, you will be unable to automatically detect players language. Only Bukkit 1.7+ is supported for this.", e); +329 } +330 } +331 +332 public TimingManager getTimings() { +333 return timingManager; +334 } +335 +336 @Override +337 public RootCommand createRootCommand(String cmd) { +338 return new BukkitRootCommand(this, cmd); +339 } +340 +341 @Override +342 public Collection<RootCommand> getRegisteredRootCommands() { +343 return Collections.unmodifiableCollection(registeredCommands.values()); +344 } +345 +346 @Override +347 public BukkitCommandIssuer getCommandIssuer(Object issuer) { +348 if (!(issuer instanceof CommandSender)) { +349 throw new IllegalArgumentException(issuer.getClass().getName() + " is not a Command Issuer."); +350 } +351 return new BukkitCommandIssuer(this, (CommandSender) issuer); +352 } +353 +354 @Override +355 public BukkitCommandExecutionContext createCommandContext(RegisteredCommand command, CommandParameter parameter, CommandIssuer sender, List<String> args, int i, Map<String, Object> passedArgs) { +356 return new BukkitCommandExecutionContext(command, parameter, (BukkitCommandIssuer) sender, args, i, passedArgs); +357 } +358 +359 @Override +360 public BukkitCommandCompletionContext createCompletionContext(RegisteredCommand command, CommandIssuer sender, String input, String config, String[] args) { +361 return new BukkitCommandCompletionContext(command, (BukkitCommandIssuer) sender, input, config, args); +362 } +363 +364 @Override +365 public RegisteredCommand createRegisteredCommand(BaseCommand command, String cmdName, Method method, String prefSubCommand) { +366 return new BukkitRegisteredCommand(command, cmdName, method, prefSubCommand); +367 } +368 +369 @Override +370 public BukkitConditionContext createConditionContext(CommandIssuer issuer, String config) { +371 return new BukkitConditionContext((BukkitCommandIssuer) issuer, config); +372 } +373 +374 +375 @Override +376 public void log(LogLevel level, String message, Throwable throwable) { +377 Level logLevel = level == LogLevel.INFO ? Level.INFO : Level.SEVERE; +378 logger.log(logLevel, LogLevel.LOG_PREFIX + message); +379 if (throwable != null) { +380 for (String line : ACFPatterns.NEWLINE.split(ApacheCommonsExceptionUtil.getFullStackTrace(throwable))) { +381 logger.log(logLevel, LogLevel.LOG_PREFIX + line); +382 } +383 } +384 } +385 +386 public boolean usePerIssuerLocale(boolean usePerIssuerLocale, boolean autoDetectFromClient) { +387 boolean old = this.usePerIssuerLocale; +388 this.usePerIssuerLocale = usePerIssuerLocale; +389 this.autoDetectFromClient = autoDetectFromClient; +390 return old; +391 } +392 +393 @Override +394 public String getCommandPrefix(CommandIssuer issuer) { +395 return issuer.isPlayer() ? "/" : ""; +396 } +397 +398 @Override +399 protected boolean handleUncaughtException(BaseCommand scope, RegisteredCommand registeredCommand, CommandIssuer sender, List<String> args, Throwable t) { +400 if (t instanceof CommandException && t.getCause() != null && t.getMessage().startsWith("Unhandled exception")) { +401 t = t.getCause(); +402 } +403 return super.handleUncaughtException(scope, registeredCommand, sender, args, t); +404 } +405} diff --git a/docs/acf-bungee/co/aikar/commands/ACFBungeeUtil.html b/docs/acf-bungee/co/aikar/commands/ACFBungeeUtil.html index 124ea939..ff656167 100644 --- a/docs/acf-bungee/co/aikar/commands/ACFBungeeUtil.html +++ b/docs/acf-bungee/co/aikar/commands/ACFBungeeUtil.html @@ -249,7 +249,7 @@ extends
  • COLOR_CHAR

    -
    public static final char COLOR_CHAR
    +
    public static final char COLOR_CHAR
    See Also:
    Constant Field Values
    @@ -297,7 +297,7 @@ extends

    sendMsg

    @Deprecated
    -public static void sendMsg(net.md_5.bungee.api.CommandSender player,
    +public static void sendMsg(net.md_5.bungee.api.CommandSender player,
                                            String message)
    Deprecated. 
    Move to Message Keys on the CommandIssuer
    @@ -309,7 +309,7 @@ public static void 
  • removeColors

    -
    public static String removeColors(String msg)
    +
    public static String removeColors(String msg)
  • @@ -318,7 +318,7 @@ public static void 
  • replaceChatString

    -
    public static String replaceChatString(String message,
    +
    public static String replaceChatString(String message,
                                            String replace,
                                            String with)
  • @@ -329,7 +329,7 @@ public static void 
  • replaceChatString

    -
    public static String replaceChatString(String message,
    +
    public static String replaceChatString(String message,
                                            Pattern replace,
                                            String with)
  • @@ -340,7 +340,7 @@ public static void 
  • getLastColors

    -
    public static String getLastColors(String input)
    +
    public static String getLastColors(String input)
  • @@ -349,7 +349,7 @@ public static void 
  • isChatColorAColor

    -
    public static boolean isChatColorAColor(net.md_5.bungee.api.ChatColor chatColor)
    +
    public static boolean isChatColorAColor(net.md_5.bungee.api.ChatColor chatColor)
  • @@ -358,7 +358,7 @@ public static void 
  • findPlayerSmart

    -
    public static net.md_5.bungee.api.connection.ProxiedPlayer findPlayerSmart(co.aikar.commands.CommandIssuer issuer,
    +
    public static net.md_5.bungee.api.connection.ProxiedPlayer findPlayerSmart(co.aikar.commands.CommandIssuer issuer,
                                                                                String search)
  • @@ -368,7 +368,7 @@ public static void 
  • findPlayerSmart

    -
    public static net.md_5.bungee.api.connection.ProxiedPlayer findPlayerSmart(net.md_5.bungee.api.CommandSender requester,
    +
    public static net.md_5.bungee.api.connection.ProxiedPlayer findPlayerSmart(net.md_5.bungee.api.CommandSender requester,
                                                                                String search)
    Deprecated. 
    Please move to the CommandIssuer version
    @@ -380,7 +380,7 @@ public static void 
  • isValidName

    -
    public static boolean isValidName(String name)
    +
    public static boolean isValidName(String name)
  • @@ -391,7 +391,7 @@ public static void 
  • validate

    -
    public static <T> T validate(T object,
    +
    public static <T> T validate(T object,
                                  String message,
                                  Object... values)
  • diff --git a/docs/acf-bungee/co/aikar/commands/BungeeLocales.html b/docs/acf-bungee/co/aikar/commands/BungeeLocales.html index cd5e7e13..8aad3dd1 100644 --- a/docs/acf-bungee/co/aikar/commands/BungeeLocales.html +++ b/docs/acf-bungee/co/aikar/commands/BungeeLocales.html @@ -18,7 +18,7 @@ catch(err) { } //--> -var methods = {"i0":10}; +var methods = {"i0":10,"i1":10,"i2":10,"i3":10}; var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; var altColor = "altColor"; var rowColor = "rowColor"; @@ -113,7 +113,7 @@ var activeTableTab = "activeTableTab";


  • -
    public class BungeeLocales
    +
    public class BungeeLocales
     extends co.aikar.commands.Locales
  • @@ -132,7 +132,7 @@ extends co.aikar.commands.Locales

    Fields inherited from class co.aikar.commands.Locales

    -AFRIKAANS, ARABIC, BULGARIAN, CHINESE, CZECH, DANISH, DUTCH, ENGLISH, FINNISH, FRENCH, GERMAN, GREEK, HEBREW, HINDI, ITALIAN, JAPANESE, KOREAN, LATIN, NORWEGIAN_BOKMAAL, NORWEGIAN_NYNORSK, POLISH, PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED_CHINESE, SPANISH, SWEDISH, THAI, TRADITIONAL_CHINESE, TURKISH, UKRANIAN, VIETNAMESE, WELSH
  • +AFRIKAANS, ARABIC, BULGARIAN, CHINESE, CZECH, DANISH, DUTCH, ENGLISH, FINNISH, FRENCH, GERMAN, GREEK, HEBREW, HINDI, HUNGARIAN, ITALIAN, JAPANESE, KOREAN, LATIN, NORWEGIAN_BOKMAAL, NORWEGIAN_NYNORSK, POLISH, PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED_CHINESE, SPANISH, SWEDISH, THAI, TRADITIONAL_CHINESE, TURKISH, UKRANIAN, VIETNAMESE, WELSH
  • @@ -166,9 +166,30 @@ extends co.aikar.commands.Locales
    Method and Description +boolean +loadLanguage(net.md_5.bungee.config.Configuration config, + Locale locale) +
    Loads every message from the Configuration object.
    + + + void loadLanguages()  + +boolean +loadYamlLanguageFile(File file, + Locale locale) +
    Loads the given file
    + + + +boolean +loadYamlLanguageFile(String file, + Locale locale) +
    Loads a file out of the plugins data folder by the given name
    + +
  • @@ -218,16 +239,77 @@ extends co.aikar.commands.Locales
    -
      +
      • loadLanguages

        -
        public void loadLanguages()
        +
        public void loadLanguages()
        Overrides:
        loadLanguages in class co.aikar.commands.Locales
      + + + + + + + +
        +
      • +

        loadYamlLanguageFile

        +
        public boolean loadYamlLanguageFile(String file,
        +                                    Locale locale)
        +                             throws IOException
        +
        Loads a file out of the plugins data folder by the given name
        +
        +
        Parameters:
        +
        file -
        +
        locale -
        +
        Returns:
        +
        If any language keys were added
        +
        Throws:
        +
        IOException
        +
        +
      • +
      + + + +
        +
      • +

        loadLanguage

        +
        public boolean loadLanguage(net.md_5.bungee.config.Configuration config,
        +                            Locale locale)
        +
        Loads every message from the Configuration object. Any nested values will be treated as namespace + so acf-core:\n\tfoo: bar will be acf-core.foo = bar
        +
        +
        Parameters:
        +
        config -
        +
        locale -
        +
        Returns:
        +
        If any language keys were added
        +
        +
      • +
  • diff --git a/docs/acf-bungee/index-all.html b/docs/acf-bungee/index-all.html index 01e929dd..7581de0c 100644 --- a/docs/acf-bungee/index-all.html +++ b/docs/acf-bungee/index-all.html @@ -265,8 +265,20 @@

    L

    +
    loadLanguage(Configuration, Locale) - Method in class co.aikar.commands.BungeeLocales
    +
    +
    Loads every message from the Configuration object.
    +
    loadLanguages() - Method in class co.aikar.commands.BungeeLocales
     
    +
    loadYamlLanguageFile(File, Locale) - Method in class co.aikar.commands.BungeeLocales
    +
    +
    Loads the given file
    +
    +
    loadYamlLanguageFile(String, Locale) - Method in class co.aikar.commands.BungeeLocales
    +
    +
    Loads a file out of the plugins data folder by the given name
    +
    locales - Variable in class co.aikar.commands.BungeeCommandManager
     
    log(LogLevel, String, Throwable) - Method in class co.aikar.commands.BungeeCommandManager
    diff --git a/docs/acf-bungee/src-html/co/aikar/commands/ACFBungeeUtil.html b/docs/acf-bungee/src-html/co/aikar/commands/ACFBungeeUtil.html index 3503876e..c33ec4f3 100644 --- a/docs/acf-bungee/src-html/co/aikar/commands/ACFBungeeUtil.html +++ b/docs/acf-bungee/src-html/co/aikar/commands/ACFBungeeUtil.html @@ -49,129 +49,127 @@ 041 042 /** 043 * Move to Message Keys on the CommandIssuer -044 * @deprecated -045 */ -046 @Deprecated -047 public static void sendMsg(CommandSender player, String message) { -048 message = color(message); -049 for (String msg : ACFPatterns.NEWLINE.split(message)) { -050 player.sendMessage(msg); -051 } -052 } -053 -054 public static String removeColors(String msg) { -055 return ChatColor.stripColor(color(msg)); -056 } -057 -058 public static String replaceChatString(String message, String replace, String with) { -059 return replaceChatString(message, Pattern.compile(Pattern.quote(replace), Pattern.CASE_INSENSITIVE), with); -060 } -061 -062 public static String replaceChatString(String message, Pattern replace, String with) { -063 final String[] split = replace.split(message + "1"); -064 -065 if (split.length < 2) { -066 return replace.matcher(message).replaceAll(with); -067 } -068 message = split[0]; -069 -070 for (int i = 1; i < split.length; i++) { -071 final String prev = getLastColors(message); -072 message += with + prev + split[i]; -073 } -074 return message.substring(0, message.length() - 1); -075 } -076 -077 //Imported from org.bukkit.ChatColor -078 -079 public static final char COLOR_CHAR = '\u00A7'; -080 -081 public static String getLastColors(String input) { -082 StringBuilder result = new StringBuilder(); -083 int length = input.length(); -084 -085 // Search backwards from the end as it is faster -086 for (int index = length - 1; index > -1; index--) { -087 char section = input.charAt(index); -088 if (section == COLOR_CHAR && index < length - 1) { -089 char c = input.charAt(index + 1); -090 ChatColor color = ChatColor.getByChar(c); -091 -092 if (color != null) { -093 result.insert(0, color.toString()); -094 -095 // Once we find a color or reset we can stop searching -096 if (isChatColorAColor(color) || color.equals(ChatColor.RESET)) { -097 break; -098 } -099 } -100 } -101 } -102 return result.toString(); -103 } -104 -105 public static boolean isChatColorAColor(ChatColor chatColor) { -106 return chatColor != ChatColor.MAGIC && chatColor != ChatColor.BOLD -107 && chatColor != ChatColor.STRIKETHROUGH && chatColor != ChatColor.UNDERLINE -108 && chatColor != ChatColor.ITALIC; -109 } -110 +044 * +045 * @deprecated +046 */ +047 @Deprecated +048 public static void sendMsg(CommandSender player, String message) { +049 message = color(message); +050 for (String msg : ACFPatterns.NEWLINE.split(message)) { +051 player.sendMessage(msg); +052 } +053 } +054 +055 public static String removeColors(String msg) { +056 return ChatColor.stripColor(color(msg)); +057 } +058 +059 public static String replaceChatString(String message, String replace, String with) { +060 return replaceChatString(message, Pattern.compile(Pattern.quote(replace), Pattern.CASE_INSENSITIVE), with); +061 } +062 +063 public static String replaceChatString(String message, Pattern replace, String with) { +064 final String[] split = replace.split(message + "1"); +065 +066 if (split.length < 2) { +067 return replace.matcher(message).replaceAll(with); +068 } +069 message = split[0]; +070 +071 for (int i = 1; i < split.length; i++) { +072 final String prev = getLastColors(message); +073 message += with + prev + split[i]; +074 } +075 return message.substring(0, message.length() - 1); +076 } +077 +078 //Imported from org.bukkit.ChatColor +079 +080 public static final char COLOR_CHAR = '\u00A7'; +081 +082 public static String getLastColors(String input) { +083 StringBuilder result = new StringBuilder(); +084 int length = input.length(); +085 +086 // Search backwards from the end as it is faster +087 for (int index = length - 1; index > -1; index--) { +088 char section = input.charAt(index); +089 if (section == COLOR_CHAR && index < length - 1) { +090 char c = input.charAt(index + 1); +091 ChatColor color = ChatColor.getByChar(c); +092 +093 if (color != null) { +094 result.insert(0, color.toString()); +095 +096 // Once we find a color or reset we can stop searching +097 if (isChatColorAColor(color) || color.equals(ChatColor.RESET)) { +098 break; +099 } +100 } +101 } +102 } +103 return result.toString(); +104 } +105 +106 public static boolean isChatColorAColor(ChatColor chatColor) { +107 return chatColor != ChatColor.MAGIC && chatColor != ChatColor.BOLD +108 && chatColor != ChatColor.STRIKETHROUGH && chatColor != ChatColor.UNDERLINE +109 && chatColor != ChatColor.ITALIC; +110 } 111 -112 public static ProxiedPlayer findPlayerSmart(CommandIssuer issuer, String search) { -113 CommandSender requester = issuer.getIssuer(); -114 String name = ACFUtil.replace(search, ":confirm", ""); -115 if (name.length() < 3) { -116 issuer.sendError(MinecraftMessageKeys.USERNAME_TOO_SHORT); -117 return null; -118 } -119 if (!isValidName(name)) { -120 issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name); -121 return null; -122 } -123 -124 List<ProxiedPlayer> matches = new ArrayList<>(ProxyServer.getInstance().matchPlayer(name)); -125 -126 if (matches.size() > 1) { -127 String allMatches = matches.stream().map(ProxiedPlayer::getName).collect(Collectors.joining(", ")); -128 issuer.sendError(MinecraftMessageKeys.MULTIPLE_PLAYERS_MATCH, -129 "{search}", name, "{all}", allMatches); -130 return null; -131 } -132 -133 if (matches.isEmpty()) { -134 issuer.sendError(MinecraftMessageKeys.NO_PLAYER_FOUND_SERVER, -135 "{search}", name); -136 return null; -137 } +112 +113 public static ProxiedPlayer findPlayerSmart(CommandIssuer issuer, String search) { +114 CommandSender requester = issuer.getIssuer(); +115 String name = ACFUtil.replace(search, ":confirm", ""); +116 if (!isValidName(name)) { +117 issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name); +118 return null; +119 } +120 +121 List<ProxiedPlayer> matches = new ArrayList<>(ProxyServer.getInstance().matchPlayer(name)); +122 +123 if (matches.size() > 1) { +124 String allMatches = matches.stream().map(ProxiedPlayer::getName).collect(Collectors.joining(", ")); +125 issuer.sendError(MinecraftMessageKeys.MULTIPLE_PLAYERS_MATCH, +126 "{search}", name, "{all}", allMatches); +127 return null; +128 } +129 +130 if (matches.isEmpty()) { +131 issuer.sendError(MinecraftMessageKeys.NO_PLAYER_FOUND_SERVER, +132 "{search}", name); +133 return null; +134 } +135 +136 return matches.get(0); +137 } 138 -139 return matches.get(0); -140 } -141 -142 /** -143 * Please move to the CommandIssuer version -144 * @deprecated -145 */ -146 public static ProxiedPlayer findPlayerSmart(CommandSender requester, String search) { -147 CommandManager manager = CommandManager.getCurrentCommandManager(); -148 if (manager != null) { -149 return findPlayerSmart(manager.getCommandIssuer(requester), search); -150 } -151 throw new IllegalStateException("You may not use the ACFBungeeUtil#findPlayerSmart(CommandSender) async to the command execution."); -152 } -153 -154 public static boolean isValidName(String name) { -155 return name != null && !name.isEmpty() && ACFPatterns.VALID_NAME_PATTERN.matcher(name).matches(); -156 } -157 -158 public static <T> T validate(T object, String message, Object... values) { -159 if (object == null) { -160 throw new NullPointerException(String.format(message, values)); -161 } -162 return object; -163 } -164 -165 -166} +139 /** +140 * Please move to the CommandIssuer version +141 * +142 * @deprecated +143 */ +144 public static ProxiedPlayer findPlayerSmart(CommandSender requester, String search) { +145 CommandManager manager = CommandManager.getCurrentCommandManager(); +146 if (manager != null) { +147 return findPlayerSmart(manager.getCommandIssuer(requester), search); +148 } +149 throw new IllegalStateException("You may not use the ACFBungeeUtil#findPlayerSmart(CommandSender) async to the command execution."); +150 } +151 +152 public static boolean isValidName(String name) { +153 return name != null && !name.isEmpty() && ACFPatterns.VALID_NAME_PATTERN.matcher(name).matches(); +154 } +155 +156 public static <T> T validate(T object, String message, Object... values) { +157 if (object == null) { +158 throw new NullPointerException(String.format(message, values)); +159 } +160 return object; +161 } +162 +163 +164} diff --git a/docs/acf-bungee/src-html/co/aikar/commands/BungeeLocales.html b/docs/acf-bungee/src-html/co/aikar/commands/BungeeLocales.html index 38ba89f2..054d9b04 100644 --- a/docs/acf-bungee/src-html/co/aikar/commands/BungeeLocales.html +++ b/docs/acf-bungee/src-html/co/aikar/commands/BungeeLocales.html @@ -8,23 +8,85 @@
    001package co.aikar.commands;
     002
    -003public class BungeeLocales extends Locales {
    -004    private final BungeeCommandManager manager;
    -005
    -006    public BungeeLocales(BungeeCommandManager manager) {
    -007        super(manager);
    -008
    -009        this.manager = manager;
    -010        this.addBundleClassLoader(this.manager.getPlugin().getClass().getClassLoader());
    -011    }
    -012
    -013    @Override
    -014    public void loadLanguages() {
    -015        super.loadLanguages();
    -016        String pluginName = "acf-" + manager.plugin.getDescription().getName();
    -017        addMessageBundles("acf-minecraft", pluginName, pluginName.toLowerCase());
    -018    }
    -019}
    +003import co.aikar.locales.MessageKey;
    +004import net.md_5.bungee.config.Configuration;
    +005import net.md_5.bungee.config.ConfigurationProvider;
    +006import net.md_5.bungee.config.YamlConfiguration;
    +007
    +008import java.io.File;
    +009import java.io.IOException;
    +010import java.util.Locale;
    +011
    +012public class BungeeLocales extends Locales {
    +013    private final BungeeCommandManager manager;
    +014
    +015    public BungeeLocales(BungeeCommandManager manager) {
    +016        super(manager);
    +017
    +018        this.manager = manager;
    +019        this.addBundleClassLoader(this.manager.getPlugin().getClass().getClassLoader());
    +020    }
    +021
    +022    @Override
    +023    public void loadLanguages() {
    +024        super.loadLanguages();
    +025        String pluginName = "acf-" + manager.plugin.getDescription().getName();
    +026        addMessageBundles("acf-minecraft", pluginName, pluginName.toLowerCase());
    +027    }
    +028
    +029    /**
    +030     * Loads the given file
    +031     *
    +032     * @param file
    +033     * @param locale
    +034     * @return If any language keys were added
    +035     * @throws IOException
    +036     */
    +037    public boolean loadYamlLanguageFile(File file, Locale locale) throws IOException {
    +038        Configuration yamlConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
    +039        return loadLanguage(yamlConfiguration, locale);
    +040    }
    +041
    +042    /**
    +043     * Loads a file out of the plugins data folder by the given name
    +044     *
    +045     * @param file
    +046     * @param locale
    +047     * @return If any language keys were added
    +048     * @throws IOException
    +049     */
    +050    public boolean loadYamlLanguageFile(String file, Locale locale) throws IOException {
    +051        Configuration yamlConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(this.manager.plugin.getDataFolder(), file));
    +052        return loadLanguage(yamlConfiguration, locale);
    +053    }
    +054
    +055
    +056    /**
    +057     * Loads every message from the Configuration object. Any nested values will be treated as namespace
    +058     * so acf-core:\n\tfoo: bar will be acf-core.foo = bar
    +059     *
    +060     * @param config
    +061     * @param locale
    +062     * @return If any language keys were added
    +063     */
    +064    public boolean loadLanguage(Configuration config, Locale locale) {
    +065        boolean loaded = false;
    +066        for (String parentKey : config.getKeys()) {
    +067            Configuration inner = config.getSection(parentKey);
    +068            if (inner == null) {
    +069                continue;
    +070            }
    +071            for (String key : inner.getKeys()) {
    +072                String value = inner.getString(key);
    +073                if (value != null && !value.isEmpty()) {
    +074                    addMessage(locale, MessageKey.of(parentKey + "." + key), value);
    +075                    loaded = true;
    +076                }
    +077            }
    +078        }
    +079        return loaded;
    +080    }
    +081}
     
     
     
    diff --git a/docs/acf-core/co/aikar/commands/CommandCompletions.AsyncCommandCompletionHandler.html b/docs/acf-core/co/aikar/commands/CommandCompletions.AsyncCommandCompletionHandler.html
    index 03ffbfab..3d157975 100644
    --- a/docs/acf-core/co/aikar/commands/CommandCompletions.AsyncCommandCompletionHandler.html
    +++ b/docs/acf-core/co/aikar/commands/CommandCompletions.AsyncCommandCompletionHandler.html
    @@ -102,7 +102,7 @@
     


    -
    public static interface CommandCompletions.AsyncCommandCompletionHandler<C extends CommandCompletionContext>
    +
    public static interface CommandCompletions.AsyncCommandCompletionHandler<C extends CommandCompletionContext>
     extends CommandCompletions.CommandCompletionHandler<C>
  • diff --git a/docs/acf-core/co/aikar/commands/CommandCompletions.CommandCompletionHandler.html b/docs/acf-core/co/aikar/commands/CommandCompletions.CommandCompletionHandler.html index 23154375..c843d26f 100644 --- a/docs/acf-core/co/aikar/commands/CommandCompletions.CommandCompletionHandler.html +++ b/docs/acf-core/co/aikar/commands/CommandCompletions.CommandCompletionHandler.html @@ -108,7 +108,7 @@ var activeTableTab = "activeTableTab";


    -
    public static interface CommandCompletions.CommandCompletionHandler<C extends CommandCompletionContext>
    +
    public static interface CommandCompletions.CommandCompletionHandler<C extends CommandCompletionContext>
  • @@ -154,7 +154,7 @@ var activeTableTab = "activeTableTab";
  • diff --git a/docs/acf-core/co/aikar/commands/CommandContexts.html b/docs/acf-core/co/aikar/commands/CommandContexts.html index 4aee3c1b..e0d78247 100644 --- a/docs/acf-core/co/aikar/commands/CommandContexts.html +++ b/docs/acf-core/co/aikar/commands/CommandContexts.html @@ -249,7 +249,7 @@ extends

    registerSenderAwareContext

    @Deprecated
    -public <T> void registerSenderAwareContext(Class<T> context,
    +public <T> void registerSenderAwareContext(Class<T> context,
                                                            IssuerAwareContextResolver<T,R> supplier)
    Deprecated. Please switch to registerIssuerAwareContext(Class, IssuerAwareContextResolver) as the core wants to use the platform agnostic term of "Issuer" instead of Sender
    @@ -265,7 +265,7 @@ public <T> void 
  • registerIssuerAwareContext

    -
    public <T> void registerIssuerAwareContext(Class<T> context,
    +
    public <T> void registerIssuerAwareContext(Class<T> context,
                                                IssuerAwareContextResolver<T,R> supplier)
    Registers a context resolver that may conditionally consume input, falling back to using the context of the issuer to potentially fulfill this context. @@ -279,7 +279,7 @@ public <T> void 
  • registerIssuerOnlyContext

    -
    public <T> void registerIssuerOnlyContext(Class<T> context,
    +
    public <T> void registerIssuerOnlyContext(Class<T> context,
                                               IssuerOnlyContextResolver<T,R> supplier)
    Registers a context resolver that will never consume input. It will always satisfy its context based on the issuer of the command, so it will not appear in syntax strings.
    @@ -291,7 +291,7 @@ public <T> void 
  • registerOptionalContext

    -
    public <T> void registerOptionalContext(Class<T> context,
    +
    public <T> void registerOptionalContext(Class<T> context,
                                             OptionalContextResolver<T,R> supplier)
    Registers a context that can safely accept a null input from the command issuer to resolve. This resolver should always call CommandExecutionContext.popFirstArg()
    @@ -303,7 +303,7 @@ public <T> void 
  • registerContext

    -
    public <T> void registerContext(Class<T> context,
    +
    public <T> void registerContext(Class<T> context,
                                     ContextResolver<T,R> supplier)
    Registers a context that requires input from the command issuer to resolve. This resolver should always call CommandExecutionContext.popFirstArg()
    @@ -315,7 +315,7 @@ public <T> void 
  • getResolver

    -
    public ContextResolver<?,RgetResolver(Class<?> type)
    +
    public ContextResolver<?,RgetResolver(Class<?> type)
  • diff --git a/docs/acf-core/co/aikar/commands/Locales.html b/docs/acf-core/co/aikar/commands/Locales.html index 0ab66b0a..ed45dda9 100644 --- a/docs/acf-core/co/aikar/commands/Locales.html +++ b/docs/acf-core/co/aikar/commands/Locales.html @@ -186,77 +186,81 @@ extends static Locale -ITALIAN  +HUNGARIAN  static Locale +ITALIAN  + + +static Locale JAPANESE  - + static Locale KOREAN  - + static Locale LATIN  - + static Locale NORWEGIAN_BOKMAAL  - + static Locale NORWEGIAN_NYNORSK  - + static Locale POLISH  - + static Locale PORTUGUESE  - + static Locale ROMANIAN  - + static Locale RUSSIAN  - + static Locale SIMPLIFIED_CHINESE  - + static Locale SPANISH  - + static Locale SWEDISH  - + static Locale THAI  - + static Locale TRADITIONAL_CHINESE  - + static Locale TURKISH  - + static Locale UKRANIAN  - + static Locale VIETNAMESE  - + static Locale WELSH  @@ -667,12 +671,21 @@ extends - @@ -687,7 +700,7 @@ extends
  • Locales

    -
    public Locales(CommandManager manager)
    +
    public Locales(CommandManager manager)
  • @@ -704,7 +717,7 @@ extends
  • loadLanguages

    -
    public void loadLanguages()
    +
    public void loadLanguages()
  • @@ -713,7 +726,7 @@ extends
  • getDefaultLocale

    -
    public Locale getDefaultLocale()
    +
    public Locale getDefaultLocale()
  • @@ -722,7 +735,7 @@ extends
  • setDefaultLocale

    -
    public Locale setDefaultLocale(Locale locale)
    +
    public Locale setDefaultLocale(Locale locale)
  • @@ -731,7 +744,7 @@ extends
  • loadMissingBundles

    -
    public void loadMissingBundles()
    +
    public void loadMissingBundles()
    Looks for all previously loaded bundles, and if any new Supported Languages have been added, load them.
  • @@ -741,7 +754,7 @@ extends
  • addMessageBundles

    -
    public void addMessageBundles(String... bundleNames)
    +
    public void addMessageBundles(String... bundleNames)
  • @@ -750,7 +763,7 @@ extends
  • addMessageBundle

    -
    public boolean addMessageBundle(String bundleName,
    +
    public boolean addMessageBundle(String bundleName,
                                     Locale locale)
  • @@ -760,7 +773,7 @@ extends
  • addMessageBundle

    -
    public boolean addMessageBundle(ClassLoader classLoader,
    +
    public boolean addMessageBundle(ClassLoader classLoader,
                                     String bundleName,
                                     Locale locale)
  • @@ -771,7 +784,7 @@ extends
  • addMessageStrings

    -
    public void addMessageStrings(Locale locale,
    +
    public void addMessageStrings(Locale locale,
                                   @NotNull
                                   @NotNull Map<String,String> messages)
  • @@ -782,7 +795,7 @@ extends
  • addMessages

    -
    public void addMessages(Locale locale,
    +
    public void addMessages(Locale locale,
                             @NotNull
                             @NotNull Map<? extends co.aikar.locales.MessageKeyProvider,String> messages)
  • @@ -793,7 +806,7 @@ extends
  • addMessage

    -
    public String addMessage(Locale locale,
    +
    public String addMessage(Locale locale,
                              co.aikar.locales.MessageKeyProvider key,
                              String message)
  • @@ -804,7 +817,7 @@ extends
  • getMessage

    -
    public String getMessage(CommandIssuer issuer,
    +
    public String getMessage(CommandIssuer issuer,
                              co.aikar.locales.MessageKeyProvider key)
  • @@ -814,7 +827,7 @@ extends
  • replaceI18NStrings

    -
    public String replaceI18NStrings(String message)
    +
    public String replaceI18NStrings(String message)
  • @@ -823,7 +836,7 @@ extends
  • addBundleClassLoader

    -
    public boolean addBundleClassLoader(ClassLoader classLoader)
    +
    public boolean addBundleClassLoader(ClassLoader classLoader)
  • diff --git a/docs/acf-core/index-all.html b/docs/acf-core/index-all.html index a15f5113..6e5fe18b 100644 --- a/docs/acf-core/index-all.html +++ b/docs/acf-core/index-all.html @@ -990,6 +990,8 @@
     
    HINDI - Static variable in class co.aikar.commands.Locales
     
    +
    HUNGARIAN - Static variable in class co.aikar.commands.Locales
    +
     
  • diff --git a/docs/acf-core/src-html/co/aikar/commands/BaseCommand.html b/docs/acf-core/src-html/co/aikar/commands/BaseCommand.html index 7ef565fb..479a30c1 100644 --- a/docs/acf-core/src-html/co/aikar/commands/BaseCommand.html +++ b/docs/acf-core/src-html/co/aikar/commands/BaseCommand.html @@ -693,7 +693,7 @@ 685 * @return All results to complete the command. 686 */ 687 private List<String> completeCommand(CommandIssuer issuer, RegisteredCommand cmd, String[] args, String commandLabel, boolean isAsync) { -688 if (!cmd.hasPermission(issuer) || args.length == 0) { +688 if (!cmd.hasPermission(issuer) || args.length == 0 || cmd.parameters.length == 0) { 689 return Collections.emptyList(); 690 } 691 diff --git a/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.AsyncCommandCompletionHandler.html b/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.AsyncCommandCompletionHandler.html index 5f2010a5..f2dc2c4c 100644 --- a/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.AsyncCommandCompletionHandler.html +++ b/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.AsyncCommandCompletionHandler.html @@ -271,49 +271,50 @@ 263 && args.length > ACFPatterns.SPACE.split(command.complete).length) { 264 String start = String.join(" ", args); 265 completions = completions.stream() -266 .filter(s -> s != null && s.split(" ").length >= args.length) -267 .filter(s -> ApacheCommonsLangUtil.startsWithIgnoreCase(s, start)) -268 .map(s -> { -269 String[] completionArgs = s.split(" "); -270 return String.join(" ", -271 Arrays.copyOfRange(completionArgs, args.length - 1, completionArgs.length)); -272 }).collect(Collectors.toList()); -273 } -274 -275 if (completions != null) { -276 allCompletions.addAll(completions); -277 continue; -278 } -279 //noinspection ConstantIfStatement,ConstantConditions -280 if (false) { // Hack to fool compiler. since its sneakily thrown. -281 throw new CommandCompletionTextLookupException(); -282 } -283 } catch (CommandCompletionTextLookupException ignored) { -284 // This should only happen if some other feedback error occured. -285 } catch (Exception e) { -286 command.handleException(sender, Arrays.asList(args), e); -287 } -288 // Something went wrong in lookup, fall back to input -289 return Collections.singletonList(input); -290 } else { -291 // Plaintext value -292 allCompletions.add(value); -293 } -294 } -295 return allCompletions; -296 } -297 -298 public interface CommandCompletionHandler<C extends CommandCompletionContext> { -299 Collection<String> getCompletions(C context) throws InvalidCommandArgument; -300 } -301 -302 public interface AsyncCommandCompletionHandler<C extends CommandCompletionContext> extends CommandCompletionHandler<C> { -303 } -304 -305 public static class SyncCompletionRequired extends RuntimeException { -306 } -307 -308} +266 .map(s -> { +267 if (s != null && s.split(" ").length >= args.length && ApacheCommonsLangUtil.startsWithIgnoreCase(s, start)) { +268 String[] completionArgs = s.split(" "); +269 return String.join(" ", Arrays.copyOfRange(completionArgs, args.length - 1, completionArgs.length)); +270 } else { +271 return s; +272 } +273 }).collect(Collectors.toList()); +274 } +275 +276 if (completions != null) { +277 allCompletions.addAll(completions); +278 continue; +279 } +280 //noinspection ConstantIfStatement,ConstantConditions +281 if (false) { // Hack to fool compiler. since its sneakily thrown. +282 throw new CommandCompletionTextLookupException(); +283 } +284 } catch (CommandCompletionTextLookupException ignored) { +285 // This should only happen if some other feedback error occured. +286 } catch (Exception e) { +287 command.handleException(sender, Arrays.asList(args), e); +288 } +289 // Something went wrong in lookup, fall back to input +290 return Collections.singletonList(input); +291 } else { +292 // Plaintext value +293 allCompletions.add(value); +294 } +295 } +296 return allCompletions; +297 } +298 +299 public interface CommandCompletionHandler<C extends CommandCompletionContext> { +300 Collection<String> getCompletions(C context) throws InvalidCommandArgument; +301 } +302 +303 public interface AsyncCommandCompletionHandler<C extends CommandCompletionContext> extends CommandCompletionHandler<C> { +304 } +305 +306 public static class SyncCompletionRequired extends RuntimeException { +307 } +308 +309} diff --git a/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.CommandCompletionHandler.html b/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.CommandCompletionHandler.html index 5f2010a5..f2dc2c4c 100644 --- a/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.CommandCompletionHandler.html +++ b/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.CommandCompletionHandler.html @@ -271,49 +271,50 @@ 263 && args.length > ACFPatterns.SPACE.split(command.complete).length) { 264 String start = String.join(" ", args); 265 completions = completions.stream() -266 .filter(s -> s != null && s.split(" ").length >= args.length) -267 .filter(s -> ApacheCommonsLangUtil.startsWithIgnoreCase(s, start)) -268 .map(s -> { -269 String[] completionArgs = s.split(" "); -270 return String.join(" ", -271 Arrays.copyOfRange(completionArgs, args.length - 1, completionArgs.length)); -272 }).collect(Collectors.toList()); -273 } -274 -275 if (completions != null) { -276 allCompletions.addAll(completions); -277 continue; -278 } -279 //noinspection ConstantIfStatement,ConstantConditions -280 if (false) { // Hack to fool compiler. since its sneakily thrown. -281 throw new CommandCompletionTextLookupException(); -282 } -283 } catch (CommandCompletionTextLookupException ignored) { -284 // This should only happen if some other feedback error occured. -285 } catch (Exception e) { -286 command.handleException(sender, Arrays.asList(args), e); -287 } -288 // Something went wrong in lookup, fall back to input -289 return Collections.singletonList(input); -290 } else { -291 // Plaintext value -292 allCompletions.add(value); -293 } -294 } -295 return allCompletions; -296 } -297 -298 public interface CommandCompletionHandler<C extends CommandCompletionContext> { -299 Collection<String> getCompletions(C context) throws InvalidCommandArgument; -300 } -301 -302 public interface AsyncCommandCompletionHandler<C extends CommandCompletionContext> extends CommandCompletionHandler<C> { -303 } -304 -305 public static class SyncCompletionRequired extends RuntimeException { -306 } -307 -308} +266 .map(s -> { +267 if (s != null && s.split(" ").length >= args.length && ApacheCommonsLangUtil.startsWithIgnoreCase(s, start)) { +268 String[] completionArgs = s.split(" "); +269 return String.join(" ", Arrays.copyOfRange(completionArgs, args.length - 1, completionArgs.length)); +270 } else { +271 return s; +272 } +273 }).collect(Collectors.toList()); +274 } +275 +276 if (completions != null) { +277 allCompletions.addAll(completions); +278 continue; +279 } +280 //noinspection ConstantIfStatement,ConstantConditions +281 if (false) { // Hack to fool compiler. since its sneakily thrown. +282 throw new CommandCompletionTextLookupException(); +283 } +284 } catch (CommandCompletionTextLookupException ignored) { +285 // This should only happen if some other feedback error occured. +286 } catch (Exception e) { +287 command.handleException(sender, Arrays.asList(args), e); +288 } +289 // Something went wrong in lookup, fall back to input +290 return Collections.singletonList(input); +291 } else { +292 // Plaintext value +293 allCompletions.add(value); +294 } +295 } +296 return allCompletions; +297 } +298 +299 public interface CommandCompletionHandler<C extends CommandCompletionContext> { +300 Collection<String> getCompletions(C context) throws InvalidCommandArgument; +301 } +302 +303 public interface AsyncCommandCompletionHandler<C extends CommandCompletionContext> extends CommandCompletionHandler<C> { +304 } +305 +306 public static class SyncCompletionRequired extends RuntimeException { +307 } +308 +309} diff --git a/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.SyncCompletionRequired.html b/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.SyncCompletionRequired.html index 5f2010a5..f2dc2c4c 100644 --- a/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.SyncCompletionRequired.html +++ b/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.SyncCompletionRequired.html @@ -271,49 +271,50 @@ 263 && args.length > ACFPatterns.SPACE.split(command.complete).length) { 264 String start = String.join(" ", args); 265 completions = completions.stream() -266 .filter(s -> s != null && s.split(" ").length >= args.length) -267 .filter(s -> ApacheCommonsLangUtil.startsWithIgnoreCase(s, start)) -268 .map(s -> { -269 String[] completionArgs = s.split(" "); -270 return String.join(" ", -271 Arrays.copyOfRange(completionArgs, args.length - 1, completionArgs.length)); -272 }).collect(Collectors.toList()); -273 } -274 -275 if (completions != null) { -276 allCompletions.addAll(completions); -277 continue; -278 } -279 //noinspection ConstantIfStatement,ConstantConditions -280 if (false) { // Hack to fool compiler. since its sneakily thrown. -281 throw new CommandCompletionTextLookupException(); -282 } -283 } catch (CommandCompletionTextLookupException ignored) { -284 // This should only happen if some other feedback error occured. -285 } catch (Exception e) { -286 command.handleException(sender, Arrays.asList(args), e); -287 } -288 // Something went wrong in lookup, fall back to input -289 return Collections.singletonList(input); -290 } else { -291 // Plaintext value -292 allCompletions.add(value); -293 } -294 } -295 return allCompletions; -296 } -297 -298 public interface CommandCompletionHandler<C extends CommandCompletionContext> { -299 Collection<String> getCompletions(C context) throws InvalidCommandArgument; -300 } -301 -302 public interface AsyncCommandCompletionHandler<C extends CommandCompletionContext> extends CommandCompletionHandler<C> { -303 } -304 -305 public static class SyncCompletionRequired extends RuntimeException { -306 } -307 -308} +266 .map(s -> { +267 if (s != null && s.split(" ").length >= args.length && ApacheCommonsLangUtil.startsWithIgnoreCase(s, start)) { +268 String[] completionArgs = s.split(" "); +269 return String.join(" ", Arrays.copyOfRange(completionArgs, args.length - 1, completionArgs.length)); +270 } else { +271 return s; +272 } +273 }).collect(Collectors.toList()); +274 } +275 +276 if (completions != null) { +277 allCompletions.addAll(completions); +278 continue; +279 } +280 //noinspection ConstantIfStatement,ConstantConditions +281 if (false) { // Hack to fool compiler. since its sneakily thrown. +282 throw new CommandCompletionTextLookupException(); +283 } +284 } catch (CommandCompletionTextLookupException ignored) { +285 // This should only happen if some other feedback error occured. +286 } catch (Exception e) { +287 command.handleException(sender, Arrays.asList(args), e); +288 } +289 // Something went wrong in lookup, fall back to input +290 return Collections.singletonList(input); +291 } else { +292 // Plaintext value +293 allCompletions.add(value); +294 } +295 } +296 return allCompletions; +297 } +298 +299 public interface CommandCompletionHandler<C extends CommandCompletionContext> { +300 Collection<String> getCompletions(C context) throws InvalidCommandArgument; +301 } +302 +303 public interface AsyncCommandCompletionHandler<C extends CommandCompletionContext> extends CommandCompletionHandler<C> { +304 } +305 +306 public static class SyncCompletionRequired extends RuntimeException { +307 } +308 +309} diff --git a/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.html b/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.html index 5f2010a5..f2dc2c4c 100644 --- a/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.html +++ b/docs/acf-core/src-html/co/aikar/commands/CommandCompletions.html @@ -271,49 +271,50 @@ 263 && args.length > ACFPatterns.SPACE.split(command.complete).length) { 264 String start = String.join(" ", args); 265 completions = completions.stream() -266 .filter(s -> s != null && s.split(" ").length >= args.length) -267 .filter(s -> ApacheCommonsLangUtil.startsWithIgnoreCase(s, start)) -268 .map(s -> { -269 String[] completionArgs = s.split(" "); -270 return String.join(" ", -271 Arrays.copyOfRange(completionArgs, args.length - 1, completionArgs.length)); -272 }).collect(Collectors.toList()); -273 } -274 -275 if (completions != null) { -276 allCompletions.addAll(completions); -277 continue; -278 } -279 //noinspection ConstantIfStatement,ConstantConditions -280 if (false) { // Hack to fool compiler. since its sneakily thrown. -281 throw new CommandCompletionTextLookupException(); -282 } -283 } catch (CommandCompletionTextLookupException ignored) { -284 // This should only happen if some other feedback error occured. -285 } catch (Exception e) { -286 command.handleException(sender, Arrays.asList(args), e); -287 } -288 // Something went wrong in lookup, fall back to input -289 return Collections.singletonList(input); -290 } else { -291 // Plaintext value -292 allCompletions.add(value); -293 } -294 } -295 return allCompletions; -296 } -297 -298 public interface CommandCompletionHandler<C extends CommandCompletionContext> { -299 Collection<String> getCompletions(C context) throws InvalidCommandArgument; -300 } -301 -302 public interface AsyncCommandCompletionHandler<C extends CommandCompletionContext> extends CommandCompletionHandler<C> { -303 } -304 -305 public static class SyncCompletionRequired extends RuntimeException { -306 } -307 -308} +266 .map(s -> { +267 if (s != null && s.split(" ").length >= args.length && ApacheCommonsLangUtil.startsWithIgnoreCase(s, start)) { +268 String[] completionArgs = s.split(" "); +269 return String.join(" ", Arrays.copyOfRange(completionArgs, args.length - 1, completionArgs.length)); +270 } else { +271 return s; +272 } +273 }).collect(Collectors.toList()); +274 } +275 +276 if (completions != null) { +277 allCompletions.addAll(completions); +278 continue; +279 } +280 //noinspection ConstantIfStatement,ConstantConditions +281 if (false) { // Hack to fool compiler. since its sneakily thrown. +282 throw new CommandCompletionTextLookupException(); +283 } +284 } catch (CommandCompletionTextLookupException ignored) { +285 // This should only happen if some other feedback error occured. +286 } catch (Exception e) { +287 command.handleException(sender, Arrays.asList(args), e); +288 } +289 // Something went wrong in lookup, fall back to input +290 return Collections.singletonList(input); +291 } else { +292 // Plaintext value +293 allCompletions.add(value); +294 } +295 } +296 return allCompletions; +297 } +298 +299 public interface CommandCompletionHandler<C extends CommandCompletionContext> { +300 Collection<String> getCompletions(C context) throws InvalidCommandArgument; +301 } +302 +303 public interface AsyncCommandCompletionHandler<C extends CommandCompletionContext> extends CommandCompletionHandler<C> { +304 } +305 +306 public static class SyncCompletionRequired extends RuntimeException { +307 } +308 +309} diff --git a/docs/acf-core/src-html/co/aikar/commands/CommandContexts.html b/docs/acf-core/src-html/co/aikar/commands/CommandContexts.html index 2c13c8bf..90643a8e 100644 --- a/docs/acf-core/src-html/co/aikar/commands/CommandContexts.html +++ b/docs/acf-core/src-html/co/aikar/commands/CommandContexts.html @@ -55,292 +55,305 @@ 047 this.manager = manager; 048 registerIssuerOnlyContext(CommandIssuer.class, c -> c.getIssuer()); 049 registerContext(Short.class, (c) -> { -050 try { -051 return parseAndValidateNumber(c, Short.MIN_VALUE, Short.MAX_VALUE).shortValue(); -052 } catch (NumberFormatException e) { -053 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -054 } -055 }); -056 registerContext(short.class, (c) -> { -057 try { -058 return parseAndValidateNumber(c, Short.MIN_VALUE, Short.MAX_VALUE).shortValue(); -059 } catch (NumberFormatException e) { -060 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -061 } -062 }); -063 registerContext(Integer.class, (c) -> { -064 try { -065 return parseAndValidateNumber(c, Integer.MIN_VALUE, Integer.MAX_VALUE).intValue(); -066 } catch (NumberFormatException e) { -067 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -068 } -069 }); -070 registerContext(int.class, (c) -> { -071 try { -072 return parseAndValidateNumber(c, Integer.MIN_VALUE, Integer.MAX_VALUE).intValue(); -073 } catch (NumberFormatException e) { -074 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -075 } -076 }); -077 registerContext(Long.class, (c) -> { -078 try { -079 return parseAndValidateNumber(c, Long.MIN_VALUE, Long.MAX_VALUE).longValue(); -080 } catch (NumberFormatException e) { -081 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -082 } -083 }); -084 registerContext(long.class, (c) -> { -085 try { -086 return parseAndValidateNumber(c, Long.MIN_VALUE, Long.MAX_VALUE).longValue(); -087 } catch (NumberFormatException e) { -088 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -089 } -090 }); -091 registerContext(Float.class, (c) -> { -092 try { -093 return parseAndValidateNumber(c, -Float.MAX_VALUE, Float.MAX_VALUE).floatValue(); -094 } catch (NumberFormatException e) { -095 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -096 } -097 }); -098 registerContext(float.class, (c) -> { +050 String number = c.popFirstArg(); +051 try { +052 return parseAndValidateNumber(number, c, Short.MIN_VALUE, Short.MAX_VALUE).shortValue(); +053 } catch (NumberFormatException e) { +054 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", number); +055 } +056 }); +057 registerContext(short.class, (c) -> { +058 String number = c.popFirstArg(); +059 try { +060 return parseAndValidateNumber(number, c, Short.MIN_VALUE, Short.MAX_VALUE).shortValue(); +061 } catch (NumberFormatException e) { +062 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", number); +063 } +064 }); +065 registerContext(Integer.class, (c) -> { +066 String number = c.popFirstArg(); +067 try { +068 return parseAndValidateNumber(number, c, Integer.MIN_VALUE, Integer.MAX_VALUE).intValue(); +069 } catch (NumberFormatException e) { +070 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", number); +071 } +072 }); +073 registerContext(int.class, (c) -> { +074 String number = c.popFirstArg(); +075 try { +076 return parseAndValidateNumber(number, c, Integer.MIN_VALUE, Integer.MAX_VALUE).intValue(); +077 } catch (NumberFormatException e) { +078 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", number); +079 } +080 }); +081 registerContext(Long.class, (c) -> { +082 String number = c.popFirstArg(); +083 try { +084 return parseAndValidateNumber(number, c, Long.MIN_VALUE, Long.MAX_VALUE).longValue(); +085 } catch (NumberFormatException e) { +086 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", number); +087 } +088 }); +089 registerContext(long.class, (c) -> { +090 String number = c.popFirstArg(); +091 try { +092 return parseAndValidateNumber(number, c, Long.MIN_VALUE, Long.MAX_VALUE).longValue(); +093 } catch (NumberFormatException e) { +094 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", number); +095 } +096 }); +097 registerContext(Float.class, (c) -> { +098 String number = c.popFirstArg(); 099 try { -100 return parseAndValidateNumber(c, -Float.MAX_VALUE, Float.MAX_VALUE).floatValue(); +100 return parseAndValidateNumber(number, c, -Float.MAX_VALUE, Float.MAX_VALUE).floatValue(); 101 } catch (NumberFormatException e) { -102 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); +102 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", number); 103 } 104 }); -105 registerContext(Double.class, (c) -> { -106 try { -107 return parseAndValidateNumber(c, -Double.MAX_VALUE, Double.MAX_VALUE).doubleValue(); -108 } catch (NumberFormatException e) { -109 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -110 } -111 }); -112 registerContext(double.class, (c) -> { -113 try { -114 return parseAndValidateNumber(c, -Double.MAX_VALUE, Double.MAX_VALUE).doubleValue(); -115 } catch (NumberFormatException e) { -116 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -117 } -118 }); -119 registerContext(Number.class, (c) -> { -120 try { -121 return parseAndValidateNumber(c, -Double.MAX_VALUE, Double.MAX_VALUE); -122 } catch (NumberFormatException e) { -123 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -124 } -125 }); -126 registerContext(BigDecimal.class, (c) -> { -127 try { -128 BigDecimal number = ACFUtil.parseBigNumber(c.popFirstArg(), c.hasFlag("suffixes")); -129 validateMinMax(c, number); -130 return number; -131 } catch (NumberFormatException e) { -132 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -133 } -134 }); -135 registerContext(BigInteger.class, (c) -> { -136 try { -137 BigDecimal number = ACFUtil.parseBigNumber(c.popFirstArg(), c.hasFlag("suffixes")); -138 validateMinMax(c, number); -139 return number.toBigIntegerExact(); -140 } catch (NumberFormatException e) { -141 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", c.getFirstArg()); -142 } -143 }); -144 registerContext(Boolean.class, (c) -> ACFUtil.isTruthy(c.popFirstArg())); -145 registerContext(boolean.class, (c) -> ACFUtil.isTruthy(c.popFirstArg())); -146 registerContext(char.class, c -> { -147 String s = c.popFirstArg(); -148 if (s.length() > 1) { -149 throw new InvalidCommandArgument(MessageKeys.MUST_BE_MAX_LENGTH, "{max}", String.valueOf(1)); -150 } -151 return s.charAt(0); -152 }); -153 registerContext(String.class, (c) -> { -154 // This will fail fast, its either in the values or its not -155 if (c.hasAnnotation(Values.class)) { -156 return c.popFirstArg(); -157 } -158 String ret = (c.isLastArg() && !c.hasAnnotation(Single.class)) ? -159 ACFUtil.join(c.getArgs()) -160 : -161 c.popFirstArg(); -162 -163 Integer minLen = c.getFlagValue("minlen", (Integer) null); -164 Integer maxLen = c.getFlagValue("maxlen", (Integer) null); -165 if (minLen != null) { -166 if (ret.length() < minLen) { -167 throw new InvalidCommandArgument(MessageKeys.MUST_BE_MIN_LENGTH, "{min}", String.valueOf(minLen)); -168 } -169 } -170 if (maxLen != null) { -171 if (ret.length() > maxLen) { -172 throw new InvalidCommandArgument(MessageKeys.MUST_BE_MAX_LENGTH, "{max}", String.valueOf(maxLen)); -173 } -174 } +105 registerContext(float.class, (c) -> { +106 String number = c.popFirstArg(); +107 try { +108 return parseAndValidateNumber(number, c, -Float.MAX_VALUE, Float.MAX_VALUE).floatValue(); +109 } catch (NumberFormatException e) { +110 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", number); +111 } +112 }); +113 registerContext(Double.class, (c) -> { +114 String number = c.popFirstArg(); +115 try { +116 return parseAndValidateNumber(number, c, -Double.MAX_VALUE, Double.MAX_VALUE).doubleValue(); +117 } catch (NumberFormatException e) { +118 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", number); +119 } +120 }); +121 registerContext(double.class, (c) -> { +122 String number = c.popFirstArg(); +123 try { +124 return parseAndValidateNumber(number, c, -Double.MAX_VALUE, Double.MAX_VALUE).doubleValue(); +125 } catch (NumberFormatException e) { +126 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", number); +127 } +128 }); +129 registerContext(Number.class, (c) -> { +130 String number = c.popFirstArg(); +131 try { +132 return parseAndValidateNumber(number, c, -Double.MAX_VALUE, Double.MAX_VALUE); +133 } catch (NumberFormatException e) { +134 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", number); +135 } +136 }); +137 registerContext(BigDecimal.class, (c) -> { +138 String numberStr = c.popFirstArg(); +139 try { +140 BigDecimal number = ACFUtil.parseBigNumber(numberStr, c.hasFlag("suffixes")); +141 validateMinMax(c, number); +142 return number; +143 } catch (NumberFormatException e) { +144 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", numberStr); +145 } +146 }); +147 registerContext(BigInteger.class, (c) -> { +148 String numberStr = c.popFirstArg(); +149 try { +150 BigDecimal number = ACFUtil.parseBigNumber(numberStr, c.hasFlag("suffixes")); +151 validateMinMax(c, number); +152 return number.toBigIntegerExact(); +153 } catch (NumberFormatException e) { +154 throw new InvalidCommandArgument(MessageKeys.MUST_BE_A_NUMBER, "{num}", numberStr); +155 } +156 }); +157 registerContext(Boolean.class, (c) -> ACFUtil.isTruthy(c.popFirstArg())); +158 registerContext(boolean.class, (c) -> ACFUtil.isTruthy(c.popFirstArg())); +159 registerContext(char.class, c -> { +160 String s = c.popFirstArg(); +161 if (s.length() > 1) { +162 throw new InvalidCommandArgument(MessageKeys.MUST_BE_MAX_LENGTH, "{max}", String.valueOf(1)); +163 } +164 return s.charAt(0); +165 }); +166 registerContext(String.class, (c) -> { +167 // This will fail fast, its either in the values or its not +168 if (c.hasAnnotation(Values.class)) { +169 return c.popFirstArg(); +170 } +171 String ret = (c.isLastArg() && !c.hasAnnotation(Single.class)) ? +172 ACFUtil.join(c.getArgs()) +173 : +174 c.popFirstArg(); 175 -176 return ret; -177 }); -178 registerContext(String[].class, (c) -> { -179 String val; -180 List<String> args = c.getArgs(); -181 if (c.isLastArg() && !c.hasAnnotation(Single.class)) { -182 val = ACFUtil.join(args); -183 } else { -184 val = c.popFirstArg(); -185 } -186 String split = c.getAnnotationValue(Split.class, Annotations.NOTHING | Annotations.NO_EMPTY); -187 if (split != null) { -188 if (val.isEmpty()) { -189 throw new InvalidCommandArgument(); -190 } -191 return ACFPatterns.getPattern(split).split(val); -192 } else if (!c.isLastArg()) { -193 ACFUtil.sneaky(new IllegalStateException("Weird Command signature... String[] should be last or @Split")); -194 } -195 -196 String[] result = args.toArray(new String[0]); -197 args.clear(); -198 return result; -199 }); -200 -201 registerContext(Enum.class, (c) -> { -202 final String first = c.popFirstArg(); -203 //noinspection unchecked -204 Class<? extends Enum<?>> enumCls = (Class<? extends Enum<?>>) c.getParam().getType(); -205 Enum<?> match = ACFUtil.simpleMatch(enumCls, first); -206 if (match == null) { -207 List<String> names = ACFUtil.enumNames(enumCls); -208 throw new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_ONE_OF, "{valid}", ACFUtil.join(names, ", ")); -209 } -210 return match; -211 }); -212 registerOptionalContext(CommandHelp.class, (c) -> { -213 String first = c.getFirstArg(); -214 String last = c.getLastArg(); -215 int page = 1; -216 List<String> search = null; -217 if (last != null && ACFUtil.isInteger(last)) { -218 c.popLastArg(); -219 page = ACFUtil.parseInt(last); -220 if (!c.getArgs().isEmpty()) { -221 search = c.getArgs(); -222 } -223 } else if (first != null && ACFUtil.isInteger(first)) { -224 c.popFirstArg(); -225 page = ACFUtil.parseInt(first); -226 if (!c.getArgs().isEmpty()) { -227 search = c.getArgs(); -228 } -229 } else if (!c.getArgs().isEmpty()) { -230 search = c.getArgs(); -231 } -232 CommandHelp commandHelp = manager.generateCommandHelp(); -233 commandHelp.setPage(page); -234 Integer perPage = c.getFlagValue("perpage", (Integer) null); -235 if (perPage != null) { -236 commandHelp.setPerPage(perPage); -237 } -238 -239 // check if we have an exact match and should display the help page for that sub command instead -240 if (search != null) { -241 String cmd = String.join(" ", search); -242 if (commandHelp.testExactMatch(cmd)) { -243 return commandHelp; -244 } -245 } -246 -247 commandHelp.setSearch(search); -248 return commandHelp; -249 }); -250 } +176 Integer minLen = c.getFlagValue("minlen", (Integer) null); +177 Integer maxLen = c.getFlagValue("maxlen", (Integer) null); +178 if (minLen != null) { +179 if (ret.length() < minLen) { +180 throw new InvalidCommandArgument(MessageKeys.MUST_BE_MIN_LENGTH, "{min}", String.valueOf(minLen)); +181 } +182 } +183 if (maxLen != null) { +184 if (ret.length() > maxLen) { +185 throw new InvalidCommandArgument(MessageKeys.MUST_BE_MAX_LENGTH, "{max}", String.valueOf(maxLen)); +186 } +187 } +188 +189 return ret; +190 }); +191 registerContext(String[].class, (c) -> { +192 String val; +193 List<String> args = c.getArgs(); +194 if (c.isLastArg() && !c.hasAnnotation(Single.class)) { +195 val = ACFUtil.join(args); +196 } else { +197 val = c.popFirstArg(); +198 } +199 String split = c.getAnnotationValue(Split.class, Annotations.NOTHING | Annotations.NO_EMPTY); +200 if (split != null) { +201 if (val.isEmpty()) { +202 throw new InvalidCommandArgument(); +203 } +204 return ACFPatterns.getPattern(split).split(val); +205 } else if (!c.isLastArg()) { +206 ACFUtil.sneaky(new IllegalStateException("Weird Command signature... String[] should be last or @Split")); +207 } +208 +209 String[] result = args.toArray(new String[0]); +210 args.clear(); +211 return result; +212 }); +213 +214 registerContext(Enum.class, (c) -> { +215 final String first = c.popFirstArg(); +216 //noinspection unchecked +217 Class<? extends Enum<?>> enumCls = (Class<? extends Enum<?>>) c.getParam().getType(); +218 Enum<?> match = ACFUtil.simpleMatch(enumCls, first); +219 if (match == null) { +220 List<String> names = ACFUtil.enumNames(enumCls); +221 throw new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_ONE_OF, "{valid}", ACFUtil.join(names, ", ")); +222 } +223 return match; +224 }); +225 registerOptionalContext(CommandHelp.class, (c) -> { +226 String first = c.getFirstArg(); +227 String last = c.getLastArg(); +228 int page = 1; +229 List<String> search = null; +230 if (last != null && ACFUtil.isInteger(last)) { +231 c.popLastArg(); +232 page = ACFUtil.parseInt(last); +233 if (!c.getArgs().isEmpty()) { +234 search = c.getArgs(); +235 } +236 } else if (first != null && ACFUtil.isInteger(first)) { +237 c.popFirstArg(); +238 page = ACFUtil.parseInt(first); +239 if (!c.getArgs().isEmpty()) { +240 search = c.getArgs(); +241 } +242 } else if (!c.getArgs().isEmpty()) { +243 search = c.getArgs(); +244 } +245 CommandHelp commandHelp = manager.generateCommandHelp(); +246 commandHelp.setPage(page); +247 Integer perPage = c.getFlagValue("perpage", (Integer) null); +248 if (perPage != null) { +249 commandHelp.setPerPage(perPage); +250 } 251 -252 @NotNull -253 private Number parseAndValidateNumber(R c, Number minValue, Number maxValue) throws InvalidCommandArgument { -254 final Number val = ACFUtil.parseNumber(c.popFirstArg(), c.hasFlag("suffixes")); -255 validateMinMax(c, val, minValue, maxValue); -256 return val; -257 } -258 -259 private void validateMinMax(R c, Number val) throws InvalidCommandArgument { -260 validateMinMax(c, val, null, null); -261 } -262 -263 private void validateMinMax(R c, Number val, Number minValue, Number maxValue) throws InvalidCommandArgument { -264 minValue = c.getFlagValue("min", minValue); -265 maxValue = c.getFlagValue("max", maxValue); -266 if (maxValue != null && val.doubleValue() > maxValue.doubleValue()) { -267 throw new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_AT_MOST, "{max}", String.valueOf(maxValue)); -268 } -269 if (minValue != null && val.doubleValue() < minValue.doubleValue()) { -270 throw new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_AT_LEAST, "{min}", String.valueOf(minValue)); -271 } -272 } -273 -274 -275 /** -276 * @see #registerIssuerAwareContext(Class, IssuerAwareContextResolver) -277 * @deprecated Please switch to {@link #registerIssuerAwareContext(Class, IssuerAwareContextResolver)} -278 * as the core wants to use the platform agnostic term of "Issuer" instead of Sender -279 */ -280 @Deprecated -281 public <T> void registerSenderAwareContext(Class<T> context, IssuerAwareContextResolver<T, R> supplier) { -282 contextMap.put(context, supplier); -283 } -284 -285 /** -286 * Registers a context resolver that may conditionally consume input, falling back to using the context of the -287 * issuer to potentially fulfill this context. -288 * You may call {@link CommandExecutionContext#getFirstArg()} and then conditionally call {@link CommandExecutionContext#popFirstArg()} -289 * if you want to consume that input. -290 */ -291 public <T> void registerIssuerAwareContext(Class<T> context, IssuerAwareContextResolver<T, R> supplier) { -292 contextMap.put(context, supplier); -293 } -294 -295 /** -296 * Registers a context resolver that will never consume input. It will always satisfy its context based on the -297 * issuer of the command, so it will not appear in syntax strings. -298 */ -299 public <T> void registerIssuerOnlyContext(Class<T> context, IssuerOnlyContextResolver<T, R> supplier) { -300 contextMap.put(context, supplier); -301 } -302 -303 /** -304 * Registers a context that can safely accept a null input from the command issuer to resolve. This resolver should always -305 * call {@link CommandExecutionContext#popFirstArg()} -306 */ -307 public <T> void registerOptionalContext(Class<T> context, OptionalContextResolver<T, R> supplier) { -308 contextMap.put(context, supplier); -309 } -310 -311 /** -312 * Registers a context that requires input from the command issuer to resolve. This resolver should always -313 * call {@link CommandExecutionContext#popFirstArg()} -314 */ -315 public <T> void registerContext(Class<T> context, ContextResolver<T, R> supplier) { -316 contextMap.put(context, supplier); -317 } -318 -319 public ContextResolver<?, R> getResolver(Class<?> type) { -320 Class<?> rootType = type; -321 do { -322 if (type == Object.class) { -323 break; -324 } -325 -326 final ContextResolver<?, R> resolver = contextMap.get(type); -327 if (resolver != null) { -328 return resolver; -329 } -330 } while ((type = type.getSuperclass()) != null); +252 // check if we have an exact match and should display the help page for that sub command instead +253 if (search != null) { +254 String cmd = String.join(" ", search); +255 if (commandHelp.testExactMatch(cmd)) { +256 return commandHelp; +257 } +258 } +259 +260 commandHelp.setSearch(search); +261 return commandHelp; +262 }); +263 } +264 +265 @NotNull +266 private Number parseAndValidateNumber(String number, R c, Number minValue, Number maxValue) throws InvalidCommandArgument { +267 final Number val = ACFUtil.parseNumber(number, c.hasFlag("suffixes")); +268 validateMinMax(c, val, minValue, maxValue); +269 return val; +270 } +271 +272 private void validateMinMax(R c, Number val) throws InvalidCommandArgument { +273 validateMinMax(c, val, null, null); +274 } +275 +276 private void validateMinMax(R c, Number val, Number minValue, Number maxValue) throws InvalidCommandArgument { +277 minValue = c.getFlagValue("min", minValue); +278 maxValue = c.getFlagValue("max", maxValue); +279 if (maxValue != null && val.doubleValue() > maxValue.doubleValue()) { +280 throw new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_AT_MOST, "{max}", String.valueOf(maxValue)); +281 } +282 if (minValue != null && val.doubleValue() < minValue.doubleValue()) { +283 throw new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_AT_LEAST, "{min}", String.valueOf(minValue)); +284 } +285 } +286 +287 +288 /** +289 * @see #registerIssuerAwareContext(Class, IssuerAwareContextResolver) +290 * @deprecated Please switch to {@link #registerIssuerAwareContext(Class, IssuerAwareContextResolver)} +291 * as the core wants to use the platform agnostic term of "Issuer" instead of Sender +292 */ +293 @Deprecated +294 public <T> void registerSenderAwareContext(Class<T> context, IssuerAwareContextResolver<T, R> supplier) { +295 contextMap.put(context, supplier); +296 } +297 +298 /** +299 * Registers a context resolver that may conditionally consume input, falling back to using the context of the +300 * issuer to potentially fulfill this context. +301 * You may call {@link CommandExecutionContext#getFirstArg()} and then conditionally call {@link CommandExecutionContext#popFirstArg()} +302 * if you want to consume that input. +303 */ +304 public <T> void registerIssuerAwareContext(Class<T> context, IssuerAwareContextResolver<T, R> supplier) { +305 contextMap.put(context, supplier); +306 } +307 +308 /** +309 * Registers a context resolver that will never consume input. It will always satisfy its context based on the +310 * issuer of the command, so it will not appear in syntax strings. +311 */ +312 public <T> void registerIssuerOnlyContext(Class<T> context, IssuerOnlyContextResolver<T, R> supplier) { +313 contextMap.put(context, supplier); +314 } +315 +316 /** +317 * Registers a context that can safely accept a null input from the command issuer to resolve. This resolver should always +318 * call {@link CommandExecutionContext#popFirstArg()} +319 */ +320 public <T> void registerOptionalContext(Class<T> context, OptionalContextResolver<T, R> supplier) { +321 contextMap.put(context, supplier); +322 } +323 +324 /** +325 * Registers a context that requires input from the command issuer to resolve. This resolver should always +326 * call {@link CommandExecutionContext#popFirstArg()} +327 */ +328 public <T> void registerContext(Class<T> context, ContextResolver<T, R> supplier) { +329 contextMap.put(context, supplier); +330 } 331 -332 this.manager.log(LogLevel.ERROR, "Could not find context resolver", new IllegalStateException("No context resolver defined for " + rootType.getName())); -333 return null; -334 } -335} +332 public ContextResolver<?, R> getResolver(Class<?> type) { +333 Class<?> rootType = type; +334 do { +335 if (type == Object.class) { +336 break; +337 } +338 +339 final ContextResolver<?, R> resolver = contextMap.get(type); +340 if (resolver != null) { +341 return resolver; +342 } +343 } while ((type = type.getSuperclass()) != null); +344 +345 this.manager.log(LogLevel.ERROR, "Could not find context resolver", new IllegalStateException("No context resolver defined for " + rootType.getName())); +346 return null; +347 } +348} diff --git a/docs/acf-core/src-html/co/aikar/commands/CommandManager.html b/docs/acf-core/src-html/co/aikar/commands/CommandManager.html index fe4ce6b9..414b474a 100644 --- a/docs/acf-core/src-html/co/aikar/commands/CommandManager.html +++ b/docs/acf-core/src-html/co/aikar/commands/CommandManager.html @@ -84,7 +84,7 @@ 076 077 protected boolean usePerIssuerLocale = false; 078 protected List<IssuerLocaleChangedCallback<I>> localeChangedCallbacks = new ArrayList<>(); -079 protected Set<Locale> supportedLanguages = new HashSet<>(Arrays.asList(Locales.ENGLISH, Locales.GERMAN, Locales.SPANISH, Locales.FRENCH, Locales.CZECH, Locales.PORTUGUESE, Locales.SWEDISH, Locales.NORWEGIAN_BOKMAAL, Locales.NORWEGIAN_NYNORSK, Locales.RUSSIAN, Locales.BULGARIAN)); +079 protected Set<Locale> supportedLanguages = new HashSet<>(Arrays.asList(Locales.ENGLISH, Locales.GERMAN, Locales.SPANISH, Locales.FRENCH, Locales.CZECH, Locales.PORTUGUESE, Locales.SWEDISH, Locales.NORWEGIAN_BOKMAAL, Locales.NORWEGIAN_NYNORSK, Locales.RUSSIAN, Locales.BULGARIAN, Locales.HUNGARIAN)); 080 protected Map<MessageType, MF> formatters = new IdentityHashMap<>(); 081 protected MF defaultFormatter; 082 protected int defaultHelpPerPage = 10; diff --git a/docs/acf-core/src-html/co/aikar/commands/Locales.html b/docs/acf-core/src-html/co/aikar/commands/Locales.html index 59a7ab34..f7b6b39f 100644 --- a/docs/acf-core/src-html/co/aikar/commands/Locales.html +++ b/docs/acf-core/src-html/co/aikar/commands/Locales.html @@ -84,135 +84,136 @@ 076 public static final Locale WELSH = new Locale("cy"); 077 public static final Locale NORWEGIAN_BOKMAAL = new Locale("nb"); 078 public static final Locale NORWEGIAN_NYNORSK = new Locale("nn"); -079 -080 private final CommandManager manager; -081 private final LocaleManager<CommandIssuer> localeManager; -082 private final Map<ClassLoader, SetMultimap<String, Locale>> loadedBundles = new HashMap<>(); -083 private final List<ClassLoader> registeredClassLoaders = new ArrayList<>(); -084 -085 public Locales(CommandManager manager) { -086 this.manager = manager; -087 this.localeManager = LocaleManager.create(manager::getIssuerLocale); -088 this.addBundleClassLoader(this.getClass().getClassLoader()); -089 } -090 -091 public void loadLanguages() { -092 addMessageBundles("acf-core"); -093 } -094 -095 public Locale getDefaultLocale() { -096 return this.localeManager.getDefaultLocale(); -097 } -098 -099 public Locale setDefaultLocale(Locale locale) { -100 return this.localeManager.setDefaultLocale(locale); -101 } -102 -103 /** -104 * Looks for all previously loaded bundles, and if any new Supported Languages have been added, load them. -105 */ -106 public void loadMissingBundles() { -107 //noinspection unchecked -108 Set<Locale> supportedLanguages = manager.getSupportedLanguages(); -109 for (Locale locale : supportedLanguages) { -110 for(SetMultimap<String, Locale> localeData: this.loadedBundles.values()) { -111 for (String bundleName : new HashSet<>(localeData.keys())) { -112 addMessageBundle(bundleName, locale); -113 } -114 } -115 -116 } -117 } -118 -119 public void addMessageBundles(String... bundleNames) { -120 for (String bundleName : bundleNames) { -121 //noinspection unchecked -122 Set<Locale> supportedLanguages = manager.getSupportedLanguages(); -123 for (Locale locale : supportedLanguages) { -124 addMessageBundle(bundleName, locale); -125 } -126 } -127 } -128 -129 public boolean addMessageBundle(String bundleName, Locale locale) { -130 boolean found = false; -131 for(ClassLoader classLoader: this.registeredClassLoaders) { -132 if(this.addMessageBundle(classLoader, bundleName, locale)) { -133 found = true; -134 } -135 } -136 -137 return found; -138 } -139 -140 public boolean addMessageBundle(ClassLoader classLoader, String bundleName, Locale locale) { -141 SetMultimap<String, Locale> classLoadersLocales = this.loadedBundles.getOrDefault(classLoader, HashMultimap.create()); -142 if(!classLoadersLocales.containsEntry(bundleName, locale)) { -143 if(this.localeManager.addMessageBundle(classLoader, bundleName, locale)) { -144 classLoadersLocales.put(bundleName, locale); -145 this.loadedBundles.put(classLoader, classLoadersLocales); -146 return true; -147 } -148 } -149 -150 return false; -151 } -152 -153 public void addMessageStrings(Locale locale, @NotNull Map<String, String> messages) { -154 Map<MessageKey, String> map = new HashMap<>(messages.size()); -155 messages.forEach((key, value) -> map.put(MessageKey.of(key), value)); -156 this.localeManager.addMessages(locale, map); -157 } -158 -159 public void addMessages(Locale locale, @NotNull Map<? extends MessageKeyProvider, String> messages) { -160 Map<MessageKey, String> messagesMap = new LinkedHashMap<>(); -161 for (Map.Entry<? extends MessageKeyProvider, String> entry : messages.entrySet()) { -162 messagesMap.put(entry.getKey().getMessageKey(), entry.getValue()); -163 } -164 -165 this.localeManager.addMessages(locale, messagesMap); -166 } -167 -168 public String addMessage(Locale locale, MessageKeyProvider key, String message) { -169 return this.localeManager.addMessage(locale, key.getMessageKey(), message); -170 } -171 -172 public String getMessage(CommandIssuer issuer, MessageKeyProvider key) { -173 final MessageKey msgKey = key.getMessageKey(); -174 String message = this.localeManager.getMessage(issuer, msgKey); -175 if (message == null) { -176 manager.log(LogLevel.ERROR, "Missing Language Key: " + msgKey.getKey()); -177 message = "<MISSING_LANGUAGE_KEY:" + msgKey.getKey() + ">"; -178 } -179 return message; -180 } -181 -182 public String replaceI18NStrings(String message) { -183 if (message == null) { -184 return null; -185 } -186 Matcher matcher = ACFPatterns.I18N_STRING.matcher(message); -187 if (!matcher.find()) { -188 return message; -189 } -190 -191 CommandIssuer issuer = CommandManager.getCurrentCommandIssuer(); -192 -193 matcher.reset(); -194 StringBuffer sb = new StringBuffer(message.length()); -195 while (matcher.find()) { -196 MessageKey key = MessageKey.of(matcher.group("key")); -197 matcher.appendReplacement(sb, Matcher.quoteReplacement(getMessage(issuer, key))); -198 } -199 matcher.appendTail(sb); -200 return sb.toString(); -201 } -202 -203 public boolean addBundleClassLoader(ClassLoader classLoader) { -204 return !this.registeredClassLoaders.contains(classLoader) && this.registeredClassLoaders.add(classLoader); -205 -206 } -207} +079 public static final Locale HUNGARIAN = new Locale("hu"); +080 +081 private final CommandManager manager; +082 private final LocaleManager<CommandIssuer> localeManager; +083 private final Map<ClassLoader, SetMultimap<String, Locale>> loadedBundles = new HashMap<>(); +084 private final List<ClassLoader> registeredClassLoaders = new ArrayList<>(); +085 +086 public Locales(CommandManager manager) { +087 this.manager = manager; +088 this.localeManager = LocaleManager.create(manager::getIssuerLocale); +089 this.addBundleClassLoader(this.getClass().getClassLoader()); +090 } +091 +092 public void loadLanguages() { +093 addMessageBundles("acf-core"); +094 } +095 +096 public Locale getDefaultLocale() { +097 return this.localeManager.getDefaultLocale(); +098 } +099 +100 public Locale setDefaultLocale(Locale locale) { +101 return this.localeManager.setDefaultLocale(locale); +102 } +103 +104 /** +105 * Looks for all previously loaded bundles, and if any new Supported Languages have been added, load them. +106 */ +107 public void loadMissingBundles() { +108 //noinspection unchecked +109 Set<Locale> supportedLanguages = manager.getSupportedLanguages(); +110 for (Locale locale : supportedLanguages) { +111 for(SetMultimap<String, Locale> localeData: this.loadedBundles.values()) { +112 for (String bundleName : new HashSet<>(localeData.keys())) { +113 addMessageBundle(bundleName, locale); +114 } +115 } +116 +117 } +118 } +119 +120 public void addMessageBundles(String... bundleNames) { +121 for (String bundleName : bundleNames) { +122 //noinspection unchecked +123 Set<Locale> supportedLanguages = manager.getSupportedLanguages(); +124 for (Locale locale : supportedLanguages) { +125 addMessageBundle(bundleName, locale); +126 } +127 } +128 } +129 +130 public boolean addMessageBundle(String bundleName, Locale locale) { +131 boolean found = false; +132 for(ClassLoader classLoader: this.registeredClassLoaders) { +133 if(this.addMessageBundle(classLoader, bundleName, locale)) { +134 found = true; +135 } +136 } +137 +138 return found; +139 } +140 +141 public boolean addMessageBundle(ClassLoader classLoader, String bundleName, Locale locale) { +142 SetMultimap<String, Locale> classLoadersLocales = this.loadedBundles.getOrDefault(classLoader, HashMultimap.create()); +143 if(!classLoadersLocales.containsEntry(bundleName, locale)) { +144 if(this.localeManager.addMessageBundle(classLoader, bundleName, locale)) { +145 classLoadersLocales.put(bundleName, locale); +146 this.loadedBundles.put(classLoader, classLoadersLocales); +147 return true; +148 } +149 } +150 +151 return false; +152 } +153 +154 public void addMessageStrings(Locale locale, @NotNull Map<String, String> messages) { +155 Map<MessageKey, String> map = new HashMap<>(messages.size()); +156 messages.forEach((key, value) -> map.put(MessageKey.of(key), value)); +157 this.localeManager.addMessages(locale, map); +158 } +159 +160 public void addMessages(Locale locale, @NotNull Map<? extends MessageKeyProvider, String> messages) { +161 Map<MessageKey, String> messagesMap = new LinkedHashMap<>(); +162 for (Map.Entry<? extends MessageKeyProvider, String> entry : messages.entrySet()) { +163 messagesMap.put(entry.getKey().getMessageKey(), entry.getValue()); +164 } +165 +166 this.localeManager.addMessages(locale, messagesMap); +167 } +168 +169 public String addMessage(Locale locale, MessageKeyProvider key, String message) { +170 return this.localeManager.addMessage(locale, key.getMessageKey(), message); +171 } +172 +173 public String getMessage(CommandIssuer issuer, MessageKeyProvider key) { +174 final MessageKey msgKey = key.getMessageKey(); +175 String message = this.localeManager.getMessage(issuer, msgKey); +176 if (message == null) { +177 manager.log(LogLevel.ERROR, "Missing Language Key: " + msgKey.getKey()); +178 message = "<MISSING_LANGUAGE_KEY:" + msgKey.getKey() + ">"; +179 } +180 return message; +181 } +182 +183 public String replaceI18NStrings(String message) { +184 if (message == null) { +185 return null; +186 } +187 Matcher matcher = ACFPatterns.I18N_STRING.matcher(message); +188 if (!matcher.find()) { +189 return message; +190 } +191 +192 CommandIssuer issuer = CommandManager.getCurrentCommandIssuer(); +193 +194 matcher.reset(); +195 StringBuffer sb = new StringBuffer(message.length()); +196 while (matcher.find()) { +197 MessageKey key = MessageKey.of(matcher.group("key")); +198 matcher.appendReplacement(sb, Matcher.quoteReplacement(getMessage(issuer, key))); +199 } +200 matcher.appendTail(sb); +201 return sb.toString(); +202 } +203 +204 public boolean addBundleClassLoader(ClassLoader classLoader) { +205 return !this.registeredClassLoaders.contains(classLoader) && this.registeredClassLoaders.add(classLoader); +206 +207 } +208} diff --git a/docs/acf-core/src-html/co/aikar/commands/RegisteredCommand.html b/docs/acf-core/src-html/co/aikar/commands/RegisteredCommand.html index 9597a0c5..69a286da 100644 --- a/docs/acf-core/src-html/co/aikar/commands/RegisteredCommand.html +++ b/docs/acf-core/src-html/co/aikar/commands/RegisteredCommand.html @@ -153,7 +153,7 @@ 145 } 146 preCommand(); 147 try { -148 this.manager.conditions.validateConditions(context); +148 this.manager.getCommandConditions().validateConditions(context); 149 Map<String, Object> passedArgs = resolveContexts(sender, args); 150 if (passedArgs == null) return; 151 @@ -264,7 +264,7 @@ 256 throw new IllegalStateException("Parameter " + parameter.getName() + " is primitive and does not support Optional."); 257 } 258 //noinspection unchecked -259 this.manager.conditions.validateConditions(context, value); +259 this.manager.getCommandConditions().validateConditions(context, value); 260 passedArgs.put(parameterName, value); 261 continue; 262 } else if (requiresInput) { @@ -304,7 +304,7 @@ 296 Object paramValue = resolver.getContext(context); 297 298 //noinspection unchecked -299 this.manager.conditions.validateConditions(context, paramValue); +299 this.manager.getCommandConditions().validateConditions(context, paramValue); 300 passedArgs.put(parameterName, paramValue); 301 } 302 return passedArgs; diff --git a/docs/acf-jda/co/aikar/commands/JDALocales.html b/docs/acf-jda/co/aikar/commands/JDALocales.html index e8c38436..a57a5e1b 100644 --- a/docs/acf-jda/co/aikar/commands/JDALocales.html +++ b/docs/acf-jda/co/aikar/commands/JDALocales.html @@ -126,7 +126,7 @@ extends co.aikar.commands.Locales

    Fields inherited from class co.aikar.commands.Locales

    -AFRIKAANS, ARABIC, BULGARIAN, CHINESE, CZECH, DANISH, DUTCH, ENGLISH, FINNISH, FRENCH, GERMAN, GREEK, HEBREW, HINDI, ITALIAN, JAPANESE, KOREAN, LATIN, NORWEGIAN_BOKMAAL, NORWEGIAN_NYNORSK, POLISH, PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED_CHINESE, SPANISH, SWEDISH, THAI, TRADITIONAL_CHINESE, TURKISH, UKRANIAN, VIETNAMESE, WELSH
  • +AFRIKAANS, ARABIC, BULGARIAN, CHINESE, CZECH, DANISH, DUTCH, ENGLISH, FINNISH, FRENCH, GERMAN, GREEK, HEBREW, HINDI, HUNGARIAN, ITALIAN, JAPANESE, KOREAN, LATIN, NORWEGIAN_BOKMAAL, NORWEGIAN_NYNORSK, POLISH, PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED_CHINESE, SPANISH, SWEDISH, THAI, TRADITIONAL_CHINESE, TURKISH, UKRANIAN, VIETNAMESE, WELSH
  • diff --git a/docs/acf-sponge/co/aikar/commands/ACFSpongeUtil.html b/docs/acf-sponge/co/aikar/commands/ACFSpongeUtil.html index f32e0d58..bc116555 100644 --- a/docs/acf-sponge/co/aikar/commands/ACFSpongeUtil.html +++ b/docs/acf-sponge/co/aikar/commands/ACFSpongeUtil.html @@ -213,7 +213,7 @@ extends
  • matchPlayer

    -
    public static List<org.spongepowered.api.entity.living.player.Player> matchPlayer(String partialName)
    +
    public static List<org.spongepowered.api.entity.living.player.Player> matchPlayer(String partialName)
  • @@ -222,7 +222,7 @@ extends
  • isValidName

    -
    public static boolean isValidName(String name)
    +
    public static boolean isValidName(String name)
  • diff --git a/docs/acf-sponge/co/aikar/commands/SpongeLocales.html b/docs/acf-sponge/co/aikar/commands/SpongeLocales.html index 537a291a..4f3c4314 100644 --- a/docs/acf-sponge/co/aikar/commands/SpongeLocales.html +++ b/docs/acf-sponge/co/aikar/commands/SpongeLocales.html @@ -132,7 +132,7 @@ extends co.aikar.commands.Locales

    Fields inherited from class co.aikar.commands.Locales

    -AFRIKAANS, ARABIC, BULGARIAN, CHINESE, CZECH, DANISH, DUTCH, ENGLISH, FINNISH, FRENCH, GERMAN, GREEK, HEBREW, HINDI, ITALIAN, JAPANESE, KOREAN, LATIN, NORWEGIAN_BOKMAAL, NORWEGIAN_NYNORSK, POLISH, PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED_CHINESE, SPANISH, SWEDISH, THAI, TRADITIONAL_CHINESE, TURKISH, UKRANIAN, VIETNAMESE, WELSH
  • +AFRIKAANS, ARABIC, BULGARIAN, CHINESE, CZECH, DANISH, DUTCH, ENGLISH, FINNISH, FRENCH, GERMAN, GREEK, HEBREW, HINDI, HUNGARIAN, ITALIAN, JAPANESE, KOREAN, LATIN, NORWEGIAN_BOKMAAL, NORWEGIAN_NYNORSK, POLISH, PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED_CHINESE, SPANISH, SWEDISH, THAI, TRADITIONAL_CHINESE, TURKISH, UKRANIAN, VIETNAMESE, WELSH
  • diff --git a/docs/acf-sponge/src-html/co/aikar/commands/ACFSpongeUtil.html b/docs/acf-sponge/src-html/co/aikar/commands/ACFSpongeUtil.html index f3c5c465..e23d2ab6 100644 --- a/docs/acf-sponge/src-html/co/aikar/commands/ACFSpongeUtil.html +++ b/docs/acf-sponge/src-html/co/aikar/commands/ACFSpongeUtil.html @@ -25,87 +25,83 @@ 017 return null; 018 } 019 String name = ACFUtil.replace(search, ":confirm", ""); -020 if (name.length() < 3) { -021 issuer.sendError(MinecraftMessageKeys.USERNAME_TOO_SHORT); +020 if (!isValidName(name)) { +021 issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name); 022 return null; 023 } -024 if (!isValidName(name)) { -025 issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name); -026 return null; -027 } +024 +025 List<Player> matches = matchPlayer(name); +026 List<Player> confirmList = new ArrayList<>(); +027 findMatches(search, requester, matches, confirmList); 028 -029 List<Player> matches = matchPlayer(name); -030 List<Player> confirmList = new ArrayList<>(); -031 findMatches(search, requester, matches, confirmList); -032 -033 -034 if (matches.size() > 1 || confirmList.size() > 1) { -035 String allMatches = matches.stream().map(Player::getName).collect(Collectors.joining(", ")); -036 issuer.sendError(MinecraftMessageKeys.MULTIPLE_PLAYERS_MATCH, -037 "{search}", name, "{all}", allMatches); -038 return null; -039 } -040 -041 if (matches.isEmpty()) { -042 Player player = ACFUtil.getFirstElement(confirmList); -043 if (player == null) { -044 issuer.sendError(MinecraftMessageKeys.NO_PLAYER_FOUND_SERVER, "{search}", name); +029 +030 if (matches.size() > 1 || confirmList.size() > 1) { +031 String allMatches = matches.stream().map(Player::getName).collect(Collectors.joining(", ")); +032 issuer.sendError(MinecraftMessageKeys.MULTIPLE_PLAYERS_MATCH, +033 "{search}", name, "{all}", allMatches); +034 return null; +035 } +036 +037 if (matches.isEmpty()) { +038 Player player = ACFUtil.getFirstElement(confirmList); +039 if (player == null) { +040 issuer.sendError(MinecraftMessageKeys.NO_PLAYER_FOUND_SERVER, "{search}", name); +041 return null; +042 } else { +043 +044 issuer.sendInfo(MinecraftMessageKeys.PLAYER_IS_VANISHED_CONFIRM, "{vanished}", player.getName()); 045 return null; -046 } else { -047 -048 issuer.sendInfo(MinecraftMessageKeys.PLAYER_IS_VANISHED_CONFIRM, "{vanished}", player.getName()); -049 return null; -050 } -051 } -052 -053 return matches.get(0); -054 } -055 -056 private static void findMatches(String search, CommandSource requester, List<Player> matches, List<Player> confirmList) { -057 // Remove vanished players from smart matching. -058 Iterator<Player> iter = matches.iterator(); -059 //noinspection Duplicates -060 while (iter.hasNext()) { -061 Player player = iter.next(); -062 if (requester instanceof Player && !((Player) requester).canSee(player)) { -063 if (requester.hasPermission("acf.seevanish")) { -064 if (!search.endsWith(":confirm")) { -065 confirmList.add(player); -066 iter.remove(); -067 } -068 } else { -069 iter.remove(); -070 } -071 } -072 } -073 } -074 -075 public static List<Player> matchPlayer(String partialName) { -076 List<Player> matchedPlayers = new ArrayList<>(); -077 -078 for (Player iterPlayer : Sponge.getServer().getOnlinePlayers()) { -079 String iterPlayerName = iterPlayer.getName(); -080 -081 if (partialName.equalsIgnoreCase(iterPlayerName)) { -082 // Exact match -083 matchedPlayers.clear(); -084 matchedPlayers.add(iterPlayer); -085 break; +046 } +047 } +048 +049 return matches.get(0); +050 } +051 +052 private static void findMatches(String search, CommandSource requester, List<Player> matches, List<Player> confirmList) { +053 // Remove vanished players from smart matching. +054 Iterator<Player> iter = matches.iterator(); +055 //noinspection Duplicates +056 while (iter.hasNext()) { +057 Player player = iter.next(); +058 if (requester instanceof Player && !((Player) requester).canSee(player)) { +059 if (requester.hasPermission("acf.seevanish")) { +060 if (!search.endsWith(":confirm")) { +061 confirmList.add(player); +062 iter.remove(); +063 } +064 } else { +065 iter.remove(); +066 } +067 } +068 } +069 } +070 +071 public static List<Player> matchPlayer(String partialName) { +072 List<Player> matchedPlayers = new ArrayList<>(); +073 +074 for (Player iterPlayer : Sponge.getServer().getOnlinePlayers()) { +075 String iterPlayerName = iterPlayer.getName(); +076 +077 if (partialName.equalsIgnoreCase(iterPlayerName)) { +078 // Exact match +079 matchedPlayers.clear(); +080 matchedPlayers.add(iterPlayer); +081 break; +082 } +083 if (iterPlayerName.toLowerCase(java.util.Locale.ENGLISH).contains(partialName.toLowerCase(java.util.Locale.ENGLISH))) { +084 // Partial match +085 matchedPlayers.add(iterPlayer); 086 } -087 if (iterPlayerName.toLowerCase(java.util.Locale.ENGLISH).contains(partialName.toLowerCase(java.util.Locale.ENGLISH))) { -088 // Partial match -089 matchedPlayers.add(iterPlayer); -090 } -091 } -092 -093 return matchedPlayers; +087 } +088 +089 return matchedPlayers; +090 } +091 +092 public static boolean isValidName(String name) { +093 return name != null && !name.isEmpty() && ACFPatterns.VALID_NAME_PATTERN.matcher(name).matches(); 094 } 095 -096 public static boolean isValidName(String name) { -097 return name != null && !name.isEmpty() && ACFPatterns.VALID_NAME_PATTERN.matcher(name).matches(); -098 } -099 -100} +096} diff --git a/docs/acf-velocity/co/aikar/commands/ACFVelocityUtil.html b/docs/acf-velocity/co/aikar/commands/ACFVelocityUtil.html index e8dbeaa6..bd3012f0 100644 --- a/docs/acf-velocity/co/aikar/commands/ACFVelocityUtil.html +++ b/docs/acf-velocity/co/aikar/commands/ACFVelocityUtil.html @@ -230,7 +230,7 @@ extends
  • isValidName

    -
    public static boolean isValidName(String name)
    +
    public static boolean isValidName(String name)
  • @@ -241,7 +241,7 @@ extends
  • validate

    -
    public static <T> T validate(T object,
    +
    public static <T> T validate(T object,
                                  String message,
                                  Object... values)
  • diff --git a/docs/acf-velocity/co/aikar/commands/VelocityLocales.html b/docs/acf-velocity/co/aikar/commands/VelocityLocales.html index f22084bf..af054fc3 100644 --- a/docs/acf-velocity/co/aikar/commands/VelocityLocales.html +++ b/docs/acf-velocity/co/aikar/commands/VelocityLocales.html @@ -132,7 +132,7 @@ extends co.aikar.commands.Locales

    Fields inherited from class co.aikar.commands.Locales

    -AFRIKAANS, ARABIC, BULGARIAN, CHINESE, CZECH, DANISH, DUTCH, ENGLISH, FINNISH, FRENCH, GERMAN, GREEK, HEBREW, HINDI, ITALIAN, JAPANESE, KOREAN, LATIN, NORWEGIAN_BOKMAAL, NORWEGIAN_NYNORSK, POLISH, PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED_CHINESE, SPANISH, SWEDISH, THAI, TRADITIONAL_CHINESE, TURKISH, UKRANIAN, VIETNAMESE, WELSH +AFRIKAANS, ARABIC, BULGARIAN, CHINESE, CZECH, DANISH, DUTCH, ENGLISH, FINNISH, FRENCH, GERMAN, GREEK, HEBREW, HINDI, HUNGARIAN, ITALIAN, JAPANESE, KOREAN, LATIN, NORWEGIAN_BOKMAAL, NORWEGIAN_NYNORSK, POLISH, PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED_CHINESE, SPANISH, SWEDISH, THAI, TRADITIONAL_CHINESE, TURKISH, UKRANIAN, VIETNAMESE, WELSH diff --git a/docs/acf-velocity/src-html/co/aikar/commands/ACFVelocityUtil.html b/docs/acf-velocity/src-html/co/aikar/commands/ACFVelocityUtil.html index ff1784f5..f551aae8 100644 --- a/docs/acf-velocity/src-html/co/aikar/commands/ACFVelocityUtil.html +++ b/docs/acf-velocity/src-html/co/aikar/commands/ACFVelocityUtil.html @@ -20,76 +20,72 @@ 012import com.velocitypowered.api.proxy.ProxyServer; 013 014import net.kyori.text.TextComponent; -015import net.kyori.text.serializer.ComponentSerializers; +015import net.kyori.text.serializer.legacy.LegacyComponentSerializer; 016 017public class ACFVelocityUtil { 018 019 @SuppressWarnings("deprecation") 020 public static TextComponent color(String message) { -021 return ComponentSerializers.LEGACY.deserialize(message); +021 return LegacyComponentSerializer.legacy().deserialize(message); 022 } 023 024 public static Player findPlayerSmart(ProxyServer server, CommandIssuer issuer, String search) { 025 CommandSource requester = issuer.getIssuer(); 026 String name = ACFUtil.replace(search, ":confirm", ""); -027 if (name.length() < 3) { -028 issuer.sendError(MinecraftMessageKeys.USERNAME_TOO_SHORT); +027 if (!isValidName(name)) { +028 issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name); 029 return null; 030 } -031 if (!isValidName(name)) { -032 issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name); -033 return null; -034 } -035 -036 List<Player> matches = new ArrayList<>(matchPlayer(server, name)); -037 -038 if (matches.size() > 1) { -039 String allMatches = matches.stream().map(Player::getUsername).collect(Collectors.joining(", ")); -040 issuer.sendError(MinecraftMessageKeys.MULTIPLE_PLAYERS_MATCH, "{search}", name, "{all}", allMatches); -041 return null; -042 } -043 -044 if (matches.isEmpty()) { -045 issuer.sendError(MinecraftMessageKeys.NO_PLAYER_FOUND_SERVER, "{search}", name); -046 return null; -047 } -048 -049 return matches.get(0); -050 } -051 -052 /* -053 * Original code written by md_5 -054 * -055 * Modified to work with Velocity by Crypnotic -056 */ -057 private static Collection<Player> matchPlayer(ProxyServer server, final String partialName) { -058 // A better error message might be nice. This just mimics the previous output -059 if (partialName == null) { -060 throw new NullPointerException("partialName"); -061 } -062 -063 Optional<Player> exactMatch = server.getPlayer(partialName); -064 //noinspection OptionalIsPresent -065 if (exactMatch.isPresent()) { -066 return Collections.singleton(exactMatch.get()); -067 } -068 -069 return server.getAllPlayers().stream() -070 .filter(player -> player.getUsername().regionMatches(true, 0, partialName, 0, partialName.length())) -071 .collect(Collectors.toList()); +031 +032 List<Player> matches = new ArrayList<>(matchPlayer(server, name)); +033 +034 if (matches.size() > 1) { +035 String allMatches = matches.stream().map(Player::getUsername).collect(Collectors.joining(", ")); +036 issuer.sendError(MinecraftMessageKeys.MULTIPLE_PLAYERS_MATCH, "{search}", name, "{all}", allMatches); +037 return null; +038 } +039 +040 if (matches.isEmpty()) { +041 issuer.sendError(MinecraftMessageKeys.NO_PLAYER_FOUND_SERVER, "{search}", name); +042 return null; +043 } +044 +045 return matches.get(0); +046 } +047 +048 /* +049 * Original code written by md_5 +050 * +051 * Modified to work with Velocity by Crypnotic +052 */ +053 private static Collection<Player> matchPlayer(ProxyServer server, final String partialName) { +054 // A better error message might be nice. This just mimics the previous output +055 if (partialName == null) { +056 throw new NullPointerException("partialName"); +057 } +058 +059 Optional<Player> exactMatch = server.getPlayer(partialName); +060 //noinspection OptionalIsPresent +061 if (exactMatch.isPresent()) { +062 return Collections.singleton(exactMatch.get()); +063 } +064 +065 return server.getAllPlayers().stream() +066 .filter(player -> player.getUsername().regionMatches(true, 0, partialName, 0, partialName.length())) +067 .collect(Collectors.toList()); +068 } +069 +070 public static boolean isValidName(String name) { +071 return name != null && !name.isEmpty() && ACFPatterns.VALID_NAME_PATTERN.matcher(name).matches(); 072 } 073 -074 public static boolean isValidName(String name) { -075 return name != null && !name.isEmpty() && ACFPatterns.VALID_NAME_PATTERN.matcher(name).matches(); -076 } -077 -078 public static <T> T validate(T object, String message, Object... values) { -079 if (object == null) { -080 throw new NullPointerException(String.format(message, values)); -081 } -082 return object; -083 } -084} +074 public static <T> T validate(T object, String message, Object... values) { +075 if (object == null) { +076 throw new NullPointerException(String.format(message, values)); +077 } +078 return object; +079 } +080} diff --git a/docs/acf-velocity/src-html/co/aikar/commands/VelocityMessageFormatter.html b/docs/acf-velocity/src-html/co/aikar/commands/VelocityMessageFormatter.html index 11783aec..071a4752 100644 --- a/docs/acf-velocity/src-html/co/aikar/commands/VelocityMessageFormatter.html +++ b/docs/acf-velocity/src-html/co/aikar/commands/VelocityMessageFormatter.html @@ -9,7 +9,7 @@
    001package co.aikar.commands;
     002
     003import net.kyori.text.format.TextColor;
    -004import net.kyori.text.serializer.ComponentSerializers;
    +004import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
     005
     006public class VelocityMessageFormatter extends MessageFormatter<TextColor> {
     007
    @@ -20,7 +20,7 @@
     012    @Override
     013    @SuppressWarnings("deprecation")
     014    String format(TextColor color, String message) {
    -015        return ComponentSerializers.LEGACY.serialize(ComponentSerializers.LEGACY.deserialize(message).color(color));
    +015        return LegacyComponentSerializer.legacy().serialize(LegacyComponentSerializer.legacy().deserialize(message).color(color));
     016    }
     017}