mirror of
https://github.com/aikar/commands.git
synced 2026-06-20 14:00:37 +00:00
Use per-platform Locales classes
This commit is contained in:
@@ -61,12 +61,11 @@ public class BukkitCommandManager extends CommandManager {
|
||||
protected BukkitCommandContexts contexts;
|
||||
protected BukkitCommandCompletions completions;
|
||||
MCTiming commandTiming;
|
||||
protected BukkitLocales locales;
|
||||
|
||||
@SuppressWarnings("JavaReflectionMemberAccess")
|
||||
public BukkitCommandManager(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
String pluginName = "acf-" + plugin.getDescription().getName();
|
||||
this.locales.addMessageBundles("acf-minecraft", pluginName, pluginName.toLowerCase());
|
||||
this.timingManager = TimingManager.of(plugin);
|
||||
this.commandTiming = this.timingManager.of("Commands");
|
||||
CommandMap commandMap = null;
|
||||
@@ -123,6 +122,16 @@ public class BukkitCommandManager extends CommandManager {
|
||||
return completions;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
BukkitLocales getLocales() {
|
||||
if (this.locales == null) {
|
||||
this.locales = new BukkitLocales(this);
|
||||
}
|
||||
return locales;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasRegisteredCommands() {
|
||||
return !registeredCommands.isEmpty();
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
public class BukkitLocales extends Locales {
|
||||
BukkitLocales(BukkitCommandManager manager) {
|
||||
super(manager);
|
||||
String pluginName = "acf-" + manager.plugin.getDescription().getName();
|
||||
addMessageBundles("acf-minecraft", pluginName, pluginName.toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -44,11 +44,10 @@ public class BungeeCommandManager extends CommandManager {
|
||||
protected Map<String, BungeeRootCommand> registeredCommands = new HashMap<>();
|
||||
protected BungeeCommandContexts contexts;
|
||||
protected BungeeCommandCompletions completions;
|
||||
protected BungeeLocales locales;
|
||||
|
||||
public BungeeCommandManager(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
String pluginName = "acf-" + plugin.getDescription().getName();
|
||||
this.locales.addMessageBundles("acf-minecraft", pluginName, pluginName.toLowerCase());
|
||||
this.formatters.put(MessageType.ERROR, new BungeeMessageFormatter(ChatColor.RED, ChatColor.YELLOW, ChatColor.RED));
|
||||
this.formatters.put(MessageType.SYNTAX, new BungeeMessageFormatter(ChatColor.YELLOW, ChatColor.GREEN, ChatColor.WHITE));
|
||||
this.formatters.put(MessageType.INFO, new BungeeMessageFormatter(ChatColor.BLUE, ChatColor.DARK_GREEN, ChatColor.GREEN));
|
||||
@@ -74,6 +73,15 @@ public class BungeeCommandManager extends CommandManager {
|
||||
return completions;
|
||||
}
|
||||
|
||||
@Override
|
||||
BungeeLocales getLocales() {
|
||||
if (this.locales == null) {
|
||||
this.locales = new BungeeLocales(this);
|
||||
}
|
||||
return locales;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerCommand(BaseCommand command) {
|
||||
command.onRegister(this);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package co.aikar.commands;
|
||||
|
||||
public class BungeeLocales extends Locales {
|
||||
BungeeLocales(BungeeCommandManager manager) {
|
||||
super(manager);
|
||||
String pluginName = "acf-" + manager.plugin.getDescription().getName();
|
||||
addMessageBundles("acf-minecraft", pluginName, pluginName.toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,6 @@ public abstract class CommandManager {
|
||||
static ThreadLocal<Stack<CommandOperationContext>> commandOperationContext = ThreadLocal.withInitial(Stack::new);
|
||||
protected Map<String, RootCommand> rootCommands = new HashMap<>();
|
||||
protected CommandReplacements replacements = new CommandReplacements(this);
|
||||
protected Locales locales = new Locales(this);
|
||||
protected ExceptionHandler defaultExceptionHandler = null;
|
||||
protected Map<MessageType, MessageFormatter> formatters = new IdentityHashMap<>();
|
||||
{
|
||||
@@ -93,6 +92,12 @@ public abstract class CommandManager {
|
||||
|
||||
public abstract RootCommand createRootCommand(String cmd);
|
||||
|
||||
/**
|
||||
* Returns a Locales Manager to add and modify language tables for your commands.
|
||||
* @return
|
||||
*/
|
||||
abstract Locales getLocales();
|
||||
|
||||
public abstract <R extends CommandExecutionContext> R createCommandContext(RegisteredCommand command, Parameter parameter, CommandIssuer sender, List<String> args, int i, Map<String, Object> passedArgs);
|
||||
|
||||
public abstract CommandCompletionContext createCompletionContext(RegisteredCommand command, CommandIssuer sender, String input, String config, String[] args);
|
||||
@@ -116,14 +121,6 @@ public abstract class CommandManager {
|
||||
return replacements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Locales Manager to add and modify language tables for your commands.
|
||||
* @return
|
||||
*/
|
||||
Locales getLocales() {
|
||||
return locales;
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandIssuer issuer, String permission) {
|
||||
return permission == null || permission.isEmpty() || issuer.hasPermission(permission);
|
||||
}
|
||||
|
||||
@@ -46,11 +46,12 @@ public class SpongeCommandManager extends CommandManager {
|
||||
protected SpongeCommandContexts contexts;
|
||||
protected SpongeCommandCompletions completions;
|
||||
private Timing commandTiming;
|
||||
protected SpongeLocales locales;
|
||||
|
||||
public SpongeCommandManager(PluginContainer plugin) {
|
||||
this.plugin = plugin;
|
||||
String pluginName = "acf-" + plugin.getName();
|
||||
this.locales.addMessageBundles("acf-minecraft", pluginName, pluginName.toLowerCase());
|
||||
getLocales().addMessageBundles("acf-minecraft", pluginName, pluginName.toLowerCase());
|
||||
this.commandTiming = Timings.of(plugin, "Commands");
|
||||
|
||||
this.formatters.put(MessageType.ERROR, new SpongeMessageFormatter(TextColors.RED, TextColors.YELLOW, TextColors.RED));
|
||||
@@ -79,6 +80,14 @@ public class SpongeCommandManager extends CommandManager {
|
||||
return completions;
|
||||
}
|
||||
|
||||
@Override
|
||||
SpongeLocales getLocales() {
|
||||
if (this.locales == null) {
|
||||
this.locales = new SpongeLocales(this);
|
||||
}
|
||||
return locales;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRegisteredCommands() {
|
||||
return !registeredCommands.isEmpty();
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package co.aikar.commands;
|
||||
|
||||
public class SpongeLocales extends Locales{
|
||||
SpongeLocales(SpongeCommandManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user