Fix AlternativeCommandsHandler not detecting some aliases (#3856)

This commit is contained in:
Josh Roy 2020-12-30 14:59:38 -05:00 committed by GitHub
parent 318df64e54
commit 02ba924f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 38 deletions

View File

@ -10,10 +10,10 @@
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" /> <entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
<entry key="location-2" value="PROJECT_RELATIVE:$PROJECT_DIR$/.checkstyle/checkstyle.xml:EssentialsX" /> <entry key="location-2" value="PROJECT_RELATIVE:$PROJECT_DIR$/.checkstyle/checkstyle.xml:EssentialsX" />
<entry key="property-2.configDirectory" value=".checkstyle/" /> <entry key="property-2.configDirectory" value=".checkstyle/" />
<entry key="scan-before-checkin" value="false" /> <entry key="scan-before-checkin" value="true" />
<entry key="scanscope" value="JavaOnly" /> <entry key="scanscope" value="JavaOnly" />
<entry key="suppress-errors" value="false" /> <entry key="suppress-errors" value="false" />
</map> </map>
</option> </option>
</component> </component>
</project> </project>

View File

@ -32,36 +32,30 @@ public class AlternativeCommandsHandler {
if (plugin.getDescription().getMain().contains("com.earth2me.essentials")) { if (plugin.getDescription().getMain().contains("com.earth2me.essentials")) {
return; return;
} }
final List<Command> commands = getPluginCommands(plugin); for (final Map.Entry<String, Command> entry : getPluginCommands(plugin).entrySet()) {
final String pluginName = plugin.getDescription().getName().toLowerCase(Locale.ENGLISH); final String commandName = entry.getKey().contains(":") ? entry.getKey().split(":")[1] : entry.getKey();
final Command command = entry.getValue();
for (final Command command : commands) { final List<Command> pluginCommands = altcommands.computeIfAbsent(commandName.toLowerCase(Locale.ENGLISH), k -> new ArrayList<>());
final List<String> labels = new ArrayList<>(command.getAliases()); boolean found = false;
labels.add(command.getName()); for (final Command pc2 : pluginCommands) {
// Safe cast, everything that's added comes from getPluginCommands which already performs the cast check.
for (final String label : labels) { if (((PluginIdentifiableCommand) pc2).getPlugin().equals(plugin)) {
final List<Command> plugincommands = altcommands.computeIfAbsent(label.toLowerCase(Locale.ENGLISH), k -> new ArrayList<>()); found = true;
boolean found = false; break;
for (final Command pc2 : plugincommands) {
if (pc2 instanceof PluginIdentifiableCommand) {
if (((PluginIdentifiableCommand) pc2).getPlugin().equals(plugin)) {
found = true;
break;
}
}
}
if (!found) {
plugincommands.add(command);
} }
} }
if (!found) {
pluginCommands.add(command);
}
} }
} }
private List<Command> getPluginCommands(Plugin plugin) { private Map<String, Command> getPluginCommands(Plugin plugin) {
final List<Command> commands = new ArrayList<>(); final Map<String, Command> commands = new HashMap<>();
for (Command cmd : ess.getKnownCommandsProvider().getKnownCommands().values()) { for (final Map.Entry<String, Command> entry : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) {
if (cmd instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) cmd).getPlugin().getName().equals(plugin.getName())) { if (entry.getValue() instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) entry.getValue()).getPlugin().equals(plugin)) {
commands.add(cmd); commands.put(entry.getKey(), entry.getValue());
} }
} }
return commands; return commands;

View File

@ -574,6 +574,9 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
public boolean onCommandEssentials(final CommandSender cSender, final Command command, final String commandLabel, final String[] args, final ClassLoader classLoader, final String commandPath, final String permissionPrefix, final IEssentialsModule module) { public boolean onCommandEssentials(final CommandSender cSender, final Command command, final String commandLabel, final String[] args, final ClassLoader classLoader, final String commandPath, final String permissionPrefix, final IEssentialsModule module) {
// Allow plugins to override the command via onCommand // Allow plugins to override the command via onCommand
if (!getSettings().isCommandOverridden(command.getName()) && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName()))) { if (!getSettings().isCommandOverridden(command.getName()) && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName()))) {
if (getSettings().isDebug()) {
LOGGER.log(Level.INFO, "Searching for alternative to: " + commandLabel);
}
final Command pc = alternativeCommandsHandler.getAlternative(commandLabel); final Command pc = alternativeCommandsHandler.getAlternative(commandLabel);
if (pc != null) { if (pc != null) {
alternativeCommandsHandler.executed(commandLabel, pc); alternativeCommandsHandler.executed(commandLabel, pc);

View File

@ -134,18 +134,14 @@ public class Commandessentials extends EssentialsCommand {
// Lists commands that are being handed over to other plugins. // Lists commands that are being handed over to other plugins.
private void runCommands(final Server server, final CommandSource sender, final String commandLabel, final String[] args) { private void runCommands(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
final StringBuilder disabledCommands = new StringBuilder(); if (ess.getAlternativeCommandsHandler().disabledCommands().size() == 0) {
for (final Map.Entry<String, String> entry : ess.getAlternativeCommandsHandler().disabledCommands().entrySet()) {
if (disabledCommands.length() > 0) {
disabledCommands.append("\n");
}
disabledCommands.append(entry.getKey()).append(" => ").append(entry.getValue());
}
if (disabledCommands.length() > 0) {
sender.sendMessage(tl("blockList"));
sender.sendMessage(disabledCommands.toString());
} else {
sender.sendMessage(tl("blockListEmpty")); sender.sendMessage(tl("blockListEmpty"));
return;
}
sender.sendMessage(tl("blockList"));
for (final Map.Entry<String, String> entry : ess.getAlternativeCommandsHandler().disabledCommands().entrySet()) {
sender.sendMessage(entry.getKey() + " => " + entry.getValue());
} }
} }

View File

@ -1,3 +1,4 @@
org.gradle.cache=true org.gradle.cache=true
org.gradle.caching=true
org.gradle.parallel=true org.gradle.parallel=true
org.gradle.jvmargs='-Dfile.encoding=UTF-8' org.gradle.jvmargs='-Dfile.encoding=UTF-8'

View File

@ -1,4 +1,4 @@
dependencies { dependencies {
implementation project(':providers:BaseProviders') implementation project(':providers:BaseProviders')
compileOnly 'com.destroystokyo.paper:paper-api:1.16.3-R0.1-SNAPSHOT' compileOnly 'com.destroystokyo.paper:paper-api:1.16.4-R0.1-SNAPSHOT'
} }