mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 00:58:50 +01:00
Fix AlternativeCommandsHandler not detecting some aliases (#3856)
This commit is contained in:
parent
318df64e54
commit
02ba924f33
@ -10,7 +10,7 @@
|
|||||||
<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>
|
||||||
|
@ -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());
|
|
||||||
labels.add(command.getName());
|
|
||||||
|
|
||||||
for (final String label : labels) {
|
|
||||||
final List<Command> plugincommands = altcommands.computeIfAbsent(label.toLowerCase(Locale.ENGLISH), k -> new ArrayList<>());
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (final Command pc2 : plugincommands) {
|
for (final Command pc2 : pluginCommands) {
|
||||||
if (pc2 instanceof PluginIdentifiableCommand) {
|
// Safe cast, everything that's added comes from getPluginCommands which already performs the cast check.
|
||||||
if (((PluginIdentifiableCommand) pc2).getPlugin().equals(plugin)) {
|
if (((PluginIdentifiableCommand) pc2).getPlugin().equals(plugin)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
plugincommands.add(command);
|
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;
|
||||||
|
@ -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);
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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'
|
||||||
|
@ -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'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user