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