编辑:
尽管我的Player仍然有错误,但我已经修改了代码,并变得更加可靠。
package me.kcsharkfin.commands;
import me.kcsharkfin.alreadysaid.AlreadySaid;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class HelpCommand implements CommandExecutor {
private AlreadySaid plugin;
public HelpCommand(AlreadySaid plugin) {
this.plugin - plugin;
plugin.getCommand("help").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player))
sender.sendMessage("Only Players Have Permission to Execute This Command");
return true;
}
Player p - (Player) sender;
if (p.hasPermission("alreadysaid.command.help"))
p.sendMessgae("Test");
return true;
} else {
p.sendMessage("You Do Not Have Permision To Execute This Command!");
}
return false;
}
}
那是我的HelpCommand.class,我也有一个AlreadySaid.class
public void onEnable() {
this.config = new Config(this);
this.config.load();
getServer().getPluginManager().registerEvents(this, (Plugin)this);
new HelpCommand(this);
}
在onEnable部分中,我尝试调用该命令,但它似乎对我没有太大帮助。
答案 0 :(得分:0)
我相信我在您拥有的onCommand方法中发现了问题
strings.length()!=1
但是,为了获得Java对象数组的长度,您必须使用.length,因此只需将其替换为
if (strings.length != 1) {
你应该很好!
修改
好吧,我现在意识到这是另一回事 因此,由于您的“字符串”变量只是单个字符串,因此您无法执行字符串[0] 您所需要做的就是
strings.equalsIgnoreCase("help")