我正在嘗試開發一個派系插件,它為每個運行的命令運行一個腳本。因此,我有一個 CommandListner 腳本,它由 onEnable 中的 Main.java 激活,并且偵聽器使用參數來確定運行哪個命令并運行執行該命令的腳本。我已經嘗試了很多東西來解決這個問題,我記得錯誤更嚴重/更大,但我已經解決了其中的一部分。但我似乎無法找到解決方案。package net.evolvedmc.evolvedfactions.commands;import java.awt.Color;import org.bukkit.command.Command;import org.bukkit.command.CommandExecutor;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;import net.evolvedmc.evolvedfactions.Main;public class CommandListner implements CommandExecutor {? ??? ? private Main plugin;? ??? ? public CommandListner(Main plugin) {? ? ? ??? ? ? ? //Listens for the /f command? ? ? ? this.plugin = plugin;? ? ? ? String STRBaseCMD = "f";? ? ? ? System.out.println("[EvolvedFactions] Listning for command '" + STRBaseCMD + "' with executor " + this);? ? ? ? plugin.getCommand(STRBaseCMD).setExecutor(this);? ? ? ??? ? }? ??? ? @Override? ? public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {? ? ? ??? ? ? ? //Defines our player? ? ? ? Player player = (Player) sender;? ? ? ??? ? ? ? //checks if the player has given enough arguments? ? ? ? if(args.length == 0) {? ? ? ? ? ? player.sendMessage(Color.RED + "Correct usage: /f <arg>");? ? ? ? ? ? return false;? ? ? ? }? ? ? ??? ? ? ? //checks if our argument is help? ? ? ? if(args[0].equalsIgnoreCase("help")) {? ? ? ? ? ??? ? ? ? ? ? //checks if the player has the permission to execute this command? ? ? ? ? ? if(player.hasPermission("evolvedfactions.default.help")) {? ? ? ? ? ? ? ??? ? ? ? ? ? ? ? //loads the script which executes the command? ? ? ? ? ? ? ? player.sendMessage("BomPom");? ? ? ? ? ? ? ? new HelpCommand(this, player);? ? ? ? ? ? ? ? return true;? ? ? ? ? ? ? ??? ? ? ? ? ? } else {? ? ? ? ? ? ? ? player.sendMessage("You do not have permission to execute this command.");? ? ? ? ? ? }? ? ? ? ? ??? ? ? ? ? ??? ? ? ? }? ? ? ??? ? ? ? return false;? ? }}
1 回答

蕭十郎
TA貢獻1815條經驗 獲得超13個贊
您忘記將命令添加到您的plugin.yml(這會導致getCommand("f")返回null):
main: ...
version: ...
name: ...
commands:
? f:
添加回答
舉報
0/150
提交
取消