所以我最近尝试为我的世界制作一个bukkit插件。 我的想法是,这只是一个测试插件,看看我是否可以做到,显然我不能。这是我提出的代码
package me.glowhoo.BlockChanger; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class BlockChanger extends JavaPlugin
{
@Override public void onEnable() {
Bukkit.getLogger().info(this.getDescription().getName() +
" has been enabled");
}
@Override public void onDisable() {
Bukkit.getLogger().info(this.getDescription().getName() + " has been disabled");
}
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
/*command: /tpa Glowhoo
* args.length = 1
* args[0] = Glowhoo
* command.getName() = tpa
*/
if (cmd.getName().equalsIgnoreCase("message")){
if(sender instanceof Player)
{
/*ComandSender sender-who sent the command
* Command cmd- the command that was executed
* String commandLabel-the command alias that was used
* String[] args-array of additional arguments
*/
sender.sendMessage(ChatColor.RED +"Hello player!");
}else
{
sender.sendMessage(ChatColor.AQUA +"Hello console!");
}
}
return false;
}
}
所以问题就在于,无论何时我加载服务器,它都说" BlockChanger已经启用",但是当我尝试键入它所拥有的唯一命令(消息)或/消息,什么都没发生,它说这是一个无法识别的命令,并输入/帮助信息。但问题并没有结束,每当我真正试图让插件运行时,90%的时间我都有一个plugin.yml错误,我不完全理解,但如果有人知道的话关于这个问题的任何事情,请回复
我的plugin.yml文件在这里(注意:这个plugin.yml副本实际上有效,但命令本身并没有。):
name: BlockChanger
version: 1.0
main: me.glowhoo.BlockChanger.BlockChanger
description:
commands:
message:
description: -no desc-
usage: /message
答案 0 :(得分:0)
您的plugin.yml
不正确。您需要在message
下缩进commands
以定义节点。目前commands
是一个关键值。将相关部分更改为:
commands:
message:
usage: /message
答案 1 :(得分:0)
现在是将来的某个时间,但是如果你再次使用它,当你有一个命令时,你需要返回true,否则它会告诉你它是一个不正确的命令,即使你的.yml /。 yaml文件设置正确。因此,在调用时,您需要做的是使其注册命令:
package me.glowhoo.BlockChanger; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class BlockChanger extends JavaPlugin
{
@Override public void onEnable() {
Bukkit.getLogger().info(this.getDescription().getName() +
" has been enabled");
}
@Override public void onDisable() {
Bukkit.getLogger().info(this.getDescription().getName() + " has been disabled");
}
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
/*command: /tpa Glowhoo
* args.length = 1
* args[0] = Glowhoo
* command.getName() = tpa
*/
if (cmd.getName().equalsIgnoreCase("message")){
if(sender instanceof Player)
{
/*ComandSender sender-who sent the command
* Command cmd- the command that was executed
* String commandLabel-the command alias that was used
* String[] args-array of additional arguments
*/
sender.sendMessage(ChatColor.RED +"Hello player!");
}else
{
sender.sendMessage(ChatColor.AQUA +"Hello console!");
}
return true;
}
return false;
}
}
答案 2 :(得分:0)
U need to register this class as command executor in onEnable method.