Skip to content

Commit

Permalink
Fix duplicate extension's help command permission registration on Pap…
Browse files Browse the repository at this point in the history
…er (#4079)

* Fix duplicate permission registration

* Register /<extensionid> help (and aliased ?) commands under the "geyser.command.exthelp.id" permission

* Fix: Show correct header for /geyser help vs /<extensionid> help
  • Loading branch information
onebeastchris authored Aug 27, 2023
1 parent 48ecde0 commit 00def3b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,6 @@ public void onEnable() {
return;
}

// Remove this in like a year
if (Bukkit.getPluginManager().getPlugin("floodgate-bukkit") != null) {
geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.outdated", Constants.FLOODGATE_DOWNLOAD_LOCATION));
this.getPluginLoader().disablePlugin(this);
return;
}

this.geyserCommandManager = new GeyserSpigotCommandManager(geyser);
this.geyserCommandManager.init();

Expand Down Expand Up @@ -323,6 +316,12 @@ private void postStartup() {
continue;
}

// Avoid registering the same permission twice, e.g. for the extension help commands
if (Bukkit.getPluginManager().getPermission(command.permission()) != null) {
GeyserImpl.getInstance().getLogger().debug("Skipping permission " + command.permission() + " as it is already registered");
continue;
}

Bukkit.getPluginManager().addPermission(new Permission(command.permission(),
GeyserLocale.getLocaleStringLog(command.description()),
command.isSuggestedOpOnly() ? PermissionDefault.OP : PermissionDefault.TRUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public void register(@NonNull Command command) {

// Register help commands for all extensions with commands
for (Map.Entry<Extension, Map<String, Command>> entry : this.extensionCommands.entrySet()) {
registerExtensionCommand(entry.getKey(), new HelpCommand(this.geyser, "help", "geyser.commands.exthelp.desc", "geyser.command.exthelp", entry.getKey().description().id(), entry.getValue()));
String id = entry.getKey().description().id();
registerExtensionCommand(entry.getKey(), new HelpCommand(this.geyser, "help", "geyser.commands.exthelp.desc", "geyser.command.exthelp." + id, id, entry.getValue()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public HelpCommand(GeyserImpl geyser, String name, String description, String pe
public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
int page = 1;
int maxPage = 1;
String header = GeyserLocale.getPlayerLocaleString("geyser.commands.help.header", sender.locale(), page, maxPage);
String translationKey = this.baseCommand.equals("geyser") ? "geyser.commands.help.header" : "geyser.commands.extensions.header";
String header = GeyserLocale.getPlayerLocaleString(translationKey, sender.locale(), page, maxPage);
sender.sendMessage(header);

this.commands.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> {
Expand Down

0 comments on commit 00def3b

Please sign in to comment.