From 524cc4713d8498505173286dee15f3533f88ce28 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Wed, 19 Jun 2024 13:52:45 +0200 Subject: [PATCH] Fix help for internal commands not working in standalone mode --- .../Minepacks/Bukkit/API/MinepacksCommand.java | 11 +++++++---- .../Minepacks/Bukkit/Command/CommandManager.java | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Minepacks-API/src/at/pcgamingfreaks/Minepacks/Bukkit/API/MinepacksCommand.java b/Minepacks-API/src/at/pcgamingfreaks/Minepacks/Bukkit/API/MinepacksCommand.java index 583ad1e..6f0fd54 100644 --- a/Minepacks-API/src/at/pcgamingfreaks/Minepacks/Bukkit/API/MinepacksCommand.java +++ b/Minepacks-API/src/at/pcgamingfreaks/Minepacks/Bukkit/API/MinepacksCommand.java @@ -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 @@ -12,7 +12,7 @@ * 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 . + * along with this program. If not, see . */ package at.pcgamingfreaks.Minepacks.Bukkit.API; @@ -20,6 +20,7 @@ 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; @@ -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."); @@ -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); } } diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/CommandManager.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/CommandManager.java index 8d91505..b8a86e5 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/CommandManager.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/CommandManager.java @@ -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