diff --git a/docs/acf-bukkit/allclasses-frame.html b/docs/acf-bukkit/allclasses-frame.html index bedc5318..00b64233 100644 --- a/docs/acf-bukkit/allclasses-frame.html +++ b/docs/acf-bukkit/allclasses-frame.html @@ -12,6 +12,7 @@
public class ACFBukkitHelpTopic +extends org.bukkit.help.GenericCommandHelpTopic+
commandamendedPermission, fullText, name, shortText| Constructor and Description | +
|---|
ACFBukkitHelpTopic(BukkitCommandManager manager,
+ BukkitRootCommand command) |
+
public ACFBukkitHelpTopic(BukkitCommandManager manager, + BukkitRootCommand command)+
Copyright © 2019. All rights reserved.
+ + diff --git a/docs/acf-bukkit/co/aikar/commands/ACFBukkitUtil.html b/docs/acf-bukkit/co/aikar/commands/ACFBukkitUtil.html index 1b76b261..7a1b63af 100644 --- a/docs/acf-bukkit/co/aikar/commands/ACFBukkitUtil.html +++ b/docs/acf-bukkit/co/aikar/commands/ACFBukkitUtil.html @@ -48,7 +48,7 @@ var activeTableTab = "activeTableTab";public final Integer mcMinorVersion+
public final Integer mcMinorVersion
public final Integer mcPatchVersion+
public final Integer mcPatchVersion
protected Map<String,org.bukkit.command.Command> knownCommands+
protected Map<String,org.bukkit.command.Command> knownCommands
protected Map<String,BukkitRootCommand> registeredCommands+
protected Map<String,BukkitRootCommand> registeredCommands
protected BukkitCommandContexts contexts+
protected BukkitCommandContexts contexts
protected BukkitCommandCompletions completions+
protected BukkitCommandCompletions completions
protected BukkitLocales locales+
protected BukkitLocales locales
protected boolean autoDetectFromClient+
protected boolean autoDetectFromClient
public BukkitCommandManager(org.bukkit.plugin.Plugin plugin)+
public BukkitCommandManager(org.bukkit.plugin.Plugin plugin)
public org.bukkit.plugin.Plugin getPlugin()+
public org.bukkit.plugin.Plugin getPlugin()
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, @@ -677,7 +677,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, @@ -694,7 +694,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)@@ -710,7 +710,7 @@ public voidcreateConditionContext
-public BukkitConditionContext createConditionContext(co.aikar.commands.CommandIssuer issuer, +public BukkitConditionContext createConditionContext(co.aikar.commands.CommandIssuer issuer, String config)
- Overrides:
@@ -724,7 +724,7 @@ public voidlog
-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
- @@ -749,7 +749,7 @@ public void
usePerIssuerLocale
-public boolean usePerIssuerLocale(boolean usePerIssuerLocale, +public boolean usePerIssuerLocale(boolean usePerIssuerLocale, boolean autoDetectFromClient)- diff --git a/docs/acf-bukkit/co/aikar/commands/package-frame.html b/docs/acf-bukkit/co/aikar/commands/package-frame.html index 0b403bd9..8cfc6d88 100644 --- a/docs/acf-bukkit/co/aikar/commands/package-frame.html +++ b/docs/acf-bukkit/co/aikar/commands/package-frame.html @@ -13,6 +13,7 @@
getCommandPrefix
-public String getCommandPrefix(co.aikar.commands.CommandIssuer issuer)+public String getCommandPrefix(co.aikar.commands.CommandIssuer issuer)
- Overrides:
- @@ -762,7 +762,7 @@ public void
getCommandPrefixin classco.aikar.commands.CommandManager<org.bukkit.command.CommandSender,BukkitCommandIssuer,org.bukkit.ChatColor,BukkitMessageFormatter,BukkitCommandExecutionContext,BukkitConditionContext>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/class-use/ACFBukkitHelpTopic.html b/docs/acf-bukkit/co/aikar/commands/class-use/ACFBukkitHelpTopic.html new file mode 100644 index 00000000..5d34df98 --- /dev/null +++ b/docs/acf-bukkit/co/aikar/commands/class-use/ACFBukkitHelpTopic.html @@ -0,0 +1,123 @@ + + + + + + +Uses of Class co.aikar.commands.ACFBukkitHelpTopic (ACF (Bukkit) 0.5.0-SNAPSHOT API) + + + + + + + + ++ + + ++ ++ ++ + +++Uses of Class
+
co.aikar.commands.ACFBukkitHelpTopicNo usage of co.aikar.commands.ACFBukkitHelpTopic+ + ++ + + ++ ++ ++ + +Copyright © 2019. All rights reserved.
+ + diff --git a/docs/acf-bukkit/co/aikar/commands/class-use/BukkitCommandManager.html b/docs/acf-bukkit/co/aikar/commands/class-use/BukkitCommandManager.html index 1eb3cad3..1876c207 100644 --- a/docs/acf-bukkit/co/aikar/commands/class-use/BukkitCommandManager.html +++ b/docs/acf-bukkit/co/aikar/commands/class-use/BukkitCommandManager.html @@ -101,12 +101,16 @@- + BukkitCommandCompletions(BukkitCommandManager manager)ACFBukkitHelpTopic(BukkitCommandManager manager, + BukkitRootCommand command)- + BukkitCommandContexts(BukkitCommandManager manager)BukkitCommandCompletions(BukkitCommandManager manager)+ ++ BukkitCommandContexts(BukkitCommandManager manager)diff --git a/docs/acf-bukkit/co/aikar/commands/class-use/BukkitRootCommand.html b/docs/acf-bukkit/co/aikar/commands/class-use/BukkitRootCommand.html index 310edba5..629d7fb1 100644 --- a/docs/acf-bukkit/co/aikar/commands/class-use/BukkitRootCommand.html +++ b/docs/acf-bukkit/co/aikar/commands/class-use/BukkitRootCommand.html @@ -124,6 +124,18 @@ + BukkitLocales(BukkitCommandManager manager)+
Constructors in co.aikar.commands with parameters of type BukkitRootCommand ++ + +Constructor and Description ++ + ++ ACFBukkitHelpTopic(BukkitCommandManager manager, + BukkitRootCommand command)Classes
+
- ACFBukkitHelpTopic
- ACFBukkitUtil
- BukkitCommandCompletionContext
- BukkitCommandCompletions
diff --git a/docs/acf-bukkit/co/aikar/commands/package-summary.html b/docs/acf-bukkit/co/aikar/commands/package-summary.html index bea76260..54d405b4 100644 --- a/docs/acf-bukkit/co/aikar/commands/package-summary.html +++ b/docs/acf-bukkit/co/aikar/commands/package-summary.html @@ -82,50 +82,54 @@+ +ACFBukkitHelpTopic ++ - ACFBukkitUtil + - BukkitCommandCompletionContext + - BukkitCommandCompletions + - BukkitCommandContexts + - BukkitCommandExecutionContext + - BukkitCommandIssuer + - BukkitCommandManager + - BukkitConditionContext + - BukkitLocales + - BukkitMessageFormatter + - BukkitRegisteredCommand + diff --git a/docs/acf-bukkit/co/aikar/commands/package-tree.html b/docs/acf-bukkit/co/aikar/commands/package-tree.html index 55202b65..71d0022e 100644 --- a/docs/acf-bukkit/co/aikar/commands/package-tree.html +++ b/docs/acf-bukkit/co/aikar/commands/package-tree.html @@ -117,6 +117,15 @@ BukkitRootCommand - co.aikar.commands.BukkitConditionContext
+- org.bukkit.help.HelpTopic +
+
+- org.bukkit.help.GenericCommandHelpTopic +
++
+- co.aikar.commands.ACFBukkitHelpTopic
+- co.aikar.commands.Locales
+
- co.aikar.commands.BukkitLocales
diff --git a/docs/acf-bukkit/index-all.html b/docs/acf-bukkit/index-all.html index 9283433c..8d97e129 100644 --- a/docs/acf-bukkit/index-all.html +++ b/docs/acf-bukkit/index-all.html @@ -73,6 +73,10 @@A
+
- ACFBukkitHelpTopic - Class in co.aikar.commands
+- +
- ACFBukkitHelpTopic(BukkitCommandManager, BukkitRootCommand) - Constructor for class co.aikar.commands.ACFBukkitHelpTopic
+- ACFBukkitUtil - Class in co.aikar.commands
- ACFBukkitUtil() - Constructor for class co.aikar.commands.ACFBukkitUtil
diff --git a/docs/acf-bukkit/overview-tree.html b/docs/acf-bukkit/overview-tree.html index edb67b30..53e02190 100644 --- a/docs/acf-bukkit/overview-tree.html +++ b/docs/acf-bukkit/overview-tree.html @@ -119,6 +119,15 @@- co.aikar.commands.BukkitConditionContext
- org.bukkit.help.HelpTopic +
+
+- org.bukkit.help.GenericCommandHelpTopic +
++
+- co.aikar.commands.ACFBukkitHelpTopic
+- co.aikar.commands.Locales
- co.aikar.commands.BukkitLocales
diff --git a/docs/acf-bukkit/src-html/co/aikar/commands/ACFBukkitHelpTopic.html b/docs/acf-bukkit/src-html/co/aikar/commands/ACFBukkitHelpTopic.html new file mode 100644 index 00000000..0d9cb071 --- /dev/null +++ b/docs/acf-bukkit/src-html/co/aikar/commands/ACFBukkitHelpTopic.html @@ -0,0 +1,119 @@ + + + +Source code + + + +++ + 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 e900caba..79d93b61 100644 --- a/docs/acf-bukkit/src-html/co/aikar/commands/BukkitCommandManager.html +++ b/docs/acf-bukkit/src-html/co/aikar/commands/BukkitCommandManager.html @@ -45,362 +45,370 @@ 037import org.bukkit.command.SimpleCommandMap; 038import org.bukkit.configuration.file.FileConfiguration; 039import org.bukkit.entity.Player; -040import org.bukkit.inventory.ItemFactory; -041import org.bukkit.plugin.Plugin; -042import org.bukkit.plugin.PluginManager; -043import org.bukkit.plugin.java.JavaPlugin; -044import org.bukkit.scheduler.BukkitScheduler; -045import org.bukkit.scheduler.BukkitTask; -046import org.bukkit.scoreboard.ScoreboardManager; -047import org.jetbrains.annotations.NotNull; -048 -049import java.lang.reflect.Field; -050import java.lang.reflect.Method; -051import java.util.Collection; -052import java.util.Collections; -053import java.util.HashMap; -054import java.util.List; -055import java.util.Locale; -056import java.util.Map; -057import java.util.Objects; -058import java.util.logging.Level; -059import java.util.logging.Logger; -060import java.util.regex.Matcher; -061import java.util.regex.Pattern; -062 -063@SuppressWarnings("WeakerAccess") -064public class BukkitCommandManager extends CommandManager< -065 CommandSender, -066 BukkitCommandIssuer, -067 ChatColor, -068 BukkitMessageFormatter, -069 BukkitCommandExecutionContext, -070 BukkitConditionContext -071 > { -072 -073 @SuppressWarnings("WeakerAccess") -074 protected final Plugin plugin; -075 private final CommandMap commandMap; -076 private final TimingManager timingManager; -077 private final BukkitTask localeTask; -078 private final Logger logger; -079 public final Integer mcMinorVersion; -080 public final Integer mcPatchVersion; -081 protected Map<String, Command> knownCommands = new HashMap<>(); -082 protected Map<String, BukkitRootCommand> registeredCommands = new HashMap<>(); -083 protected BukkitCommandContexts contexts; -084 protected BukkitCommandCompletions completions; -085 MCTiming commandTiming; -086 protected BukkitLocales locales; -087 private boolean cantReadLocale = false; -088 protected boolean autoDetectFromClient = true; -089 -090 @SuppressWarnings("JavaReflectionMemberAccess") -091 public BukkitCommandManager(Plugin plugin) { -092 this.plugin = plugin; -093 this.logger = Logger.getLogger(this.plugin.getName()); -094 this.timingManager = TimingManager.of(plugin); -095 this.commandTiming = this.timingManager.of("Commands"); -096 this.commandMap = hookCommandMap(); -097 this.formatters.put(MessageType.ERROR, defaultFormatter = new BukkitMessageFormatter(ChatColor.RED, ChatColor.YELLOW, ChatColor.RED)); -098 this.formatters.put(MessageType.SYNTAX, new BukkitMessageFormatter(ChatColor.YELLOW, ChatColor.GREEN, ChatColor.WHITE)); -099 this.formatters.put(MessageType.INFO, new BukkitMessageFormatter(ChatColor.BLUE, ChatColor.DARK_GREEN, ChatColor.GREEN)); -100 this.formatters.put(MessageType.HELP, new BukkitMessageFormatter(ChatColor.AQUA, ChatColor.GREEN, ChatColor.YELLOW)); -101 Pattern versionPattern = Pattern.compile("\\(MC: (\\d)\\.(\\d+)\\.?(\\d+?)?\\)"); -102 Matcher matcher = versionPattern.matcher(Bukkit.getVersion()); -103 if (matcher.find()) { -104 this.mcMinorVersion = ACFUtil.parseInt(matcher.toMatchResult().group(2), 0); -105 this.mcPatchVersion = ACFUtil.parseInt(matcher.toMatchResult().group(3), 0); -106 } else { -107 this.mcMinorVersion = -1; -108 this.mcPatchVersion = -1; -109 } -110 -111 Bukkit.getPluginManager().registerEvents(new ACFBukkitListener(this, plugin), plugin); -112 -113 getLocales(); // auto load locales -114 this.localeTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> { -115 if (this.cantReadLocale || !this.autoDetectFromClient) { -116 return; -117 } -118 Bukkit.getOnlinePlayers().forEach(this::readPlayerLocale); -119 }, 5, 5); +040import org.bukkit.help.GenericCommandHelpTopic; +041import org.bukkit.inventory.ItemFactory; +042import org.bukkit.plugin.Plugin; +043import org.bukkit.plugin.PluginManager; +044import org.bukkit.plugin.java.JavaPlugin; +045import org.bukkit.scheduler.BukkitScheduler; +046import org.bukkit.scheduler.BukkitTask; +047import org.bukkit.scoreboard.ScoreboardManager; +048import org.jetbrains.annotations.NotNull; +049 +050import java.lang.reflect.Field; +051import java.lang.reflect.Method; +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 registerDependency(plugin.getClass(), plugin); -122 registerDependency(Logger.class, plugin.getLogger()); -123 registerDependency(FileConfiguration.class, plugin.getConfig()); -124 registerDependency(FileConfiguration.class, "config", plugin.getConfig()); -125 registerDependency(Plugin.class, plugin); -126 registerDependency(JavaPlugin.class, plugin); -127 registerDependency(PluginManager.class, Bukkit.getPluginManager()); -128 registerDependency(Server.class, Bukkit.getServer()); -129 registerDependency(BukkitScheduler.class, Bukkit.getScheduler()); -130 registerDependency(ScoreboardManager.class, Bukkit.getScoreboardManager()); -131 registerDependency(ItemFactory.class, Bukkit.getItemFactory()); -132 } -133 -134 @NotNull -135 private CommandMap hookCommandMap() { -136 CommandMap commandMap = null; -137 try { -138 Server server = Bukkit.getServer(); -139 Method getCommandMap = server.getClass().getDeclaredMethod("getCommandMap"); -140 getCommandMap.setAccessible(true); -141 commandMap = (CommandMap) getCommandMap.invoke(server); -142 if (!SimpleCommandMap.class.isAssignableFrom(commandMap.getClass())) { -143 this.log(LogLevel.ERROR, "ERROR: CommandMap has been hijacked! Offending command map is located at: " + commandMap.getClass().getName()); -144 this.log(LogLevel.ERROR, "We are going to try to hijack it back and resolve this, but you are now in dangerous territory."); -145 this.log(LogLevel.ERROR, "We can not guarantee things are going to work."); -146 Field cmField = server.getClass().getDeclaredField("commandMap"); -147 commandMap = new ProxyCommandMap(this, commandMap); -148 cmField.set(server, commandMap); -149 this.log(LogLevel.INFO, "Injected Proxy Command Map... good luck..."); -150 } -151 Field knownCommands = SimpleCommandMap.class.getDeclaredField("knownCommands"); -152 knownCommands.setAccessible(true); -153 //noinspection unchecked -154 this.knownCommands = (Map<String, Command>) knownCommands.get(commandMap); -155 } catch (Exception e) { -156 this.log(LogLevel.ERROR, "Failed to get Command Map. ACF will not function."); -157 ACFUtil.sneaky(e); -158 } -159 return commandMap; -160 } -161 -162 public Plugin getPlugin() { -163 return this.plugin; -164 } -165 -166 @Override -167 public boolean isCommandIssuer(Class<?> type) { -168 return CommandSender.class.isAssignableFrom(type); -169 } -170 -171 @Override -172 public synchronized CommandContexts<BukkitCommandExecutionContext> getCommandContexts() { -173 if (this.contexts == null) { -174 this.contexts = new BukkitCommandContexts(this); -175 } -176 return contexts; +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 CommandCompletions<BukkitCommandCompletionContext> getCommandCompletions() { -181 if (this.completions == null) { -182 this.completions = new BukkitCommandCompletions(this); +180 public synchronized CommandContexts<BukkitCommandExecutionContext> getCommandContexts() { +181 if (this.contexts == null) { +182 this.contexts = new BukkitCommandContexts(this); 183 } -184 return completions; +184 return contexts; 185 } 186 -187 -188 @Override -189 public BukkitLocales getLocales() { -190 if (this.locales == null) { -191 this.locales = new BukkitLocales(this); -192 this.locales.loadLanguages(); -193 } -194 return locales; -195 } -196 -197 -198 @Override -199 public boolean hasRegisteredCommands() { -200 return !registeredCommands.isEmpty(); -201 } -202 -203 public void registerCommand(BaseCommand command, boolean force) { -204 final String plugin = this.plugin.getName().toLowerCase(); -205 command.onRegister(this); -206 for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) { -207 String commandName = entry.getKey().toLowerCase(); -208 BukkitRootCommand bukkitCommand = (BukkitRootCommand) entry.getValue(); -209 if (!bukkitCommand.isRegistered) { -210 Command oldCommand = commandMap.getCommand(commandName); -211 if (oldCommand instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) oldCommand).getPlugin() == this.plugin) { -212 knownCommands.remove(commandName); -213 oldCommand.unregister(commandMap); -214 } else if (oldCommand != null && force) { -215 knownCommands.remove(commandName); -216 for (Map.Entry<String, Command> ce : knownCommands.entrySet()) { -217 String key = ce.getKey(); -218 Command value = ce.getValue(); -219 if (key.contains(":") && oldCommand.equals(value)) { -220 String[] split = ACFPatterns.COLON.split(key, 2); -221 if (split.length > 1) { -222 oldCommand.unregister(commandMap); -223 oldCommand.setLabel(split[0] + ":" + command.getName()); -224 oldCommand.register(commandMap); -225 } -226 } -227 } -228 } -229 commandMap.register(commandName, plugin, bukkitCommand); -230 } -231 bukkitCommand.isRegistered = true; -232 registeredCommands.put(commandName, bukkitCommand); -233 } -234 } -235 -236 @Override -237 public void registerCommand(BaseCommand command) { -238 registerCommand(command, false); -239 } -240 -241 public void unregisterCommand(BaseCommand command) { -242 for (RootCommand rootcommand : command.registeredCommands.values()) { -243 BukkitRootCommand bukkitCommand = (BukkitRootCommand) rootcommand; -244 bukkitCommand.getSubCommands().values().removeAll(command.subCommands.values()); -245 if (bukkitCommand.isRegistered && bukkitCommand.getSubCommands().isEmpty()) { -246 unregisterCommand(bukkitCommand); -247 bukkitCommand.isRegistered = false; -248 } -249 } -250 } -251 -252 /** -253 * @param command -254 * @deprecated Use unregisterCommand(BaseCommand) - this will be visibility reduced later. -255 */ -256 @Deprecated -257 public void unregisterCommand(BukkitRootCommand command) { -258 final String plugin = this.plugin.getName().toLowerCase(); -259 command.unregister(commandMap); -260 String key = command.getName(); -261 Command registered = knownCommands.get(key); -262 if (command.equals(registered)) { -263 knownCommands.remove(key); -264 } -265 knownCommands.remove(plugin + ":" + key); -266 } -267 -268 public void unregisterCommands() { -269 for (Map.Entry<String, BukkitRootCommand> entry : registeredCommands.entrySet()) { -270 unregisterCommand(entry.getValue()); -271 } -272 this.registeredCommands.clear(); -273 } -274 +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 +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 +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 private Field getEntityField(Player player) throws NoSuchFieldException { -277 Class cls = player.getClass(); -278 while (cls != Object.class) { -279 if (cls.getName().endsWith("CraftEntity")) { -280 Field field = cls.getDeclaredField("entity"); -281 field.setAccessible(true); -282 return field; -283 } -284 cls = cls.getSuperclass(); -285 } -286 return null; -287 } -288 -289 public Locale setPlayerLocale(Player player, Locale locale) { -290 return this.setIssuerLocale(player, locale); -291 } -292 -293 void readPlayerLocale(Player player) { -294 if (!player.isOnline() || cantReadLocale) { -295 return; -296 } -297 try { -298 Field entityField = getEntityField(player); -299 if (entityField == null) { -300 return; -301 } -302 Object nmsPlayer = entityField.get(player); -303 if (nmsPlayer != null) { -304 Field localeField = nmsPlayer.getClass().getDeclaredField("locale"); -305 Object localeString = localeField.get(nmsPlayer); -306 if (localeString instanceof String) { -307 String[] split = ACFPatterns.UNDERSCORE.split((String) localeString); -308 Locale locale = split.length > 1 ? new Locale(split[0], split[1]) : new Locale(split[0]); -309 Locale prev = issuersLocale.put(player.getUniqueId(), locale); -310 if (!Objects.equals(locale, prev)) { -311 this.notifyLocaleChange(getCommandIssuer(player), prev, locale); -312 } -313 } -314 } -315 } catch (Exception e) { -316 cantReadLocale = true; -317 this.localeTask.cancel(); -318 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); -319 } -320 } -321 -322 public TimingManager getTimings() { -323 return timingManager; -324 } -325 -326 @Override -327 public RootCommand createRootCommand(String cmd) { -328 return new BukkitRootCommand(this, cmd); -329 } -330 -331 @Override -332 public Collection<RootCommand> getRegisteredRootCommands() { -333 return Collections.unmodifiableCollection(registeredCommands.values()); -334 } -335 -336 @Override -337 public BukkitCommandIssuer getCommandIssuer(Object issuer) { -338 if (!(issuer instanceof CommandSender)) { -339 throw new IllegalArgumentException(issuer.getClass().getName() + " is not a Command Issuer."); -340 } -341 return new BukkitCommandIssuer(this, (CommandSender) issuer); +276 public void unregisterCommands() { +277 for (Map.Entry<String, BukkitRootCommand> entry : registeredCommands.entrySet()) { +278 unregisterCommand(entry.getValue()); +279 } +280 this.registeredCommands.clear(); +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 BukkitCommandExecutionContext createCommandContext(RegisteredCommand command, CommandParameter parameter, CommandIssuer sender, List<String> args, int i, Map<String, Object> passedArgs) { -346 return new BukkitCommandExecutionContext(command, parameter, (BukkitCommandIssuer) sender, args, i, passedArgs); -347 } -348 -349 @Override -350 public BukkitCommandCompletionContext createCompletionContext(RegisteredCommand command, CommandIssuer sender, String input, String config, String[] args) { -351 return new BukkitCommandCompletionContext(command, (BukkitCommandIssuer) sender, input, config, args); -352 } -353 -354 @Override -355 public RegisteredCommand createRegisteredCommand(BaseCommand command, String cmdName, Method method, String prefSubCommand) { -356 return new BukkitRegisteredCommand(command, cmdName, method, prefSubCommand); -357 } -358 -359 @Override -360 public BukkitConditionContext createConditionContext(CommandIssuer issuer, String config) { -361 return new BukkitConditionContext((BukkitCommandIssuer) issuer, config); -362 } -363 -364 -365 @Override -366 public void log(LogLevel level, String message, Throwable throwable) { -367 Level logLevel = level == LogLevel.INFO ? Level.INFO : Level.SEVERE; -368 logger.log(logLevel, LogLevel.LOG_PREFIX + message); -369 if (throwable != null) { -370 for (String line : ACFPatterns.NEWLINE.split(ApacheCommonsExceptionUtil.getFullStackTrace(throwable))) { -371 logger.log(logLevel, LogLevel.LOG_PREFIX + line); -372 } -373 } -374 } -375 -376 public boolean usePerIssuerLocale(boolean usePerIssuerLocale, boolean autoDetectFromClient) { -377 boolean old = this.usePerIssuerLocale; -378 this.usePerIssuerLocale = usePerIssuerLocale; -379 this.autoDetectFromClient = autoDetectFromClient; -380 return old; -381 } -382 -383 @Override -384 public String getCommandPrefix(CommandIssuer issuer) { -385 return issuer.isPlayer() ? "/" : ""; -386 } -387 -388 @Override -389 protected boolean handleUncaughtException(BaseCommand scope, RegisteredCommand registeredCommand, CommandIssuer sender, List<String> args, Throwable t) { -390 if (t instanceof CommandException && t.getCause() != null && t.getMessage().startsWith("Unhandled exception")) { -391 t = t.getCause(); -392 } -393 return super.handleUncaughtException(scope, registeredCommand, sender, args, t); +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} +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}001/* +002 * Copyright (c) 2016-2019 Daniel Ennis (Aikar) - MIT License +003 * +004 * Permission is hereby granted, free of charge, to any person obtaining +005 * a copy of this software and associated documentation files (the +006 * "Software"), to deal in the Software without restriction, including +007 * without limitation the rights to use, copy, modify, merge, publish, +008 * distribute, sublicense, and/or sell copies of the Software, and to +009 * permit persons to whom the Software is furnished to do so, subject to +010 * the following conditions: +011 * +012 * The above copyright notice and this permission notice shall be +013 * included in all copies or substantial portions of the Software. +014 * +015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +016 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +017 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +018 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +019 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +020 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +021 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +022 */ +023 +024package co.aikar.commands; +025 +026import org.bukkit.Bukkit; +027import org.bukkit.help.GenericCommandHelpTopic; +028 +029import java.util.ArrayList; +030import java.util.List; +031 +032public class ACFBukkitHelpTopic extends GenericCommandHelpTopic { +033 +034 public ACFBukkitHelpTopic(BukkitCommandManager manager, BukkitRootCommand command) { +035 super(command); +036 +037 List<String> messages = new ArrayList<>(); +038 BukkitCommandIssuer captureIssuer = new BukkitCommandIssuer(manager, Bukkit.getConsoleSender()) { +039 @Override +040 public void sendMessageInternal(String message) { +041 messages.add(message); +042 } +043 }; +044 manager.generateCommandHelp(captureIssuer, command).showHelp(captureIssuer); +045 this.fullText = ACFUtil.join(messages, "\n"); +046 } +047} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ++