我正在尝试开发一个派系插件,它为每个运行的命令运行一个脚本。因此,我有一个 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
提交
取消