Skip to content

Commit

Permalink
Fix help for internal commands not working in standalone mode
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgH93 committed Jun 19, 2024
1 parent 5ae86a2 commit 524cc47
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 GeorgH93
* Copyright (C) 2024 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -12,14 +12,15 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package at.pcgamingfreaks.Minepacks.Bukkit.API;

import at.pcgamingfreaks.Bukkit.Command.SubCommand;
import at.pcgamingfreaks.Bukkit.Message.Message;
import at.pcgamingfreaks.Command.HelpData;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -40,6 +41,8 @@ public abstract class MinepacksCommand extends SubCommand
@SuppressWarnings("FieldMayBeFinal")
private static MinepacksPlugin minepacksPlugin = null; // Will be set by reflection
@SuppressWarnings("FieldMayBeFinal")
private static Object minepacksCommandManager = null;
@SuppressWarnings("FieldMayBeFinal")
private static Method showHelp = null; // Will be set by reflection
@SuppressWarnings("FieldMayBeFinal") // Will be overwritten by reflection
private static Message messageNoPermission = new Message(ChatColor.RED + "You don't have the permission to do that.");
Expand Down Expand Up @@ -182,11 +185,11 @@ public void showHelp(final @NotNull CommandSender sendTo, final @NotNull String
{
try
{
showHelp.invoke(getMinepacksPlugin().getCommandManager(), sendTo, usedMainCommandAlias, doGetHelp(sendTo));
showHelp.invoke(minepacksCommandManager, sendTo, usedMainCommandAlias, doGetHelp(sendTo));
}
catch(Exception e)
{
plugin.getLogger().log(Level.SEVERE, e, () -> "Failed to execute command " + usedMainCommandAlias);
plugin.getLogger().log(Level.SEVERE, e, () -> "Failed to show help for command " + usedMainCommandAlias);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public CommandManager(@NotNull Minepacks plugin)
{
// Show help function
Reflection.setStaticField(MinepacksCommand.class, "minepacksPlugin", plugin); // Plugin instance
Reflection.setStaticField(MinepacksCommand.class, "minepacksCommandManager", this); // Command manager instance
Reflection.setStaticField(MinepacksCommand.class, "showHelp", this.getClass().getDeclaredMethod("sendHelp", CommandSender.class, String.class, Collection.class));
Reflection.setStaticField(MinepacksCommand.class, "messageNoPermission", plugin.messageNoPermission); // No permission message
Reflection.setStaticField(MinepacksCommand.class, "messageNotFromConsole", plugin.messageNotFromConsole); // Not from console message
Expand Down

0 comments on commit 524cc47

Please sign in to comment.