gpt4 book ai didi

java - CraftBukkit 插件编码错误

转载 作者:行者123 更新时间:2023-11-29 05:25:57 25 4
gpt4 key购买 nike

我正在为 CraftBukkit Beta Build 1.7.2 R0.3 制作一个简单的 /heal Bukkit 插件。 (我是 java 的新手。)我在 Eclipse 中编程。我收到一条错误消息:

enter image description here

这是我的代码:

public boolean onCommand_heal(CommandSender sender, Command cmd, String commandLabel, String[] args){
Player player = (Player) sender;
if(commandLabel.equalsIgnoreCase("heal")){
if(args.length == 0){
player.setHealth(20);
player.setFireTicks(0);
player.sendMessage(ChatColor.GOLD + "You are healed!");
}else if(args.length == 1){
if(player.getServer().getPlayer(args[0]) !=null){
Player targetPlayer = player.getServer().getPlayer(args[0]);
targetPlayer.setHealth(20);
player.sendMessage(ChatColor.GOLD + "Player Healed!");
}else{
player.sendMessage(ChatColor.RED + "PLAYER NOT ONLINE!");
}
}
}
return false;
}

最佳答案

尝试这样做:

Player targetPlayer = Bukkit.getServer().getPlayer(args[0]);
//or this:
Player targetPlayer = plugin.getServer().getPlayer(args[0]);

代替

Player targetPlayer = player.getServer().getPlayer(args[0]);

和这里一样,替换:

if(player.getServer().getPlayer(args[0]) !=null){

与:

if(Bukkit.getServer().getPlayer(args[0]) != null){

此外,自最近的 Bukkit 更新以来,您应该始终在设置健康时使用 floatssetHealth(int) 已弃用,取而代之的是 setHealth(float),因此请尝试:

targetPlayer.setHealth(20.0f);

关于java - CraftBukkit 插件编码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22674995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com