首页 文章

Java Minecraft Plugin命令无效

提问于
浏览
-2

我刚刚开始使用Minecraft插件开发,并希望得到一些帮助,为什么我的插件不是't 100% working. What I mean by that, is things like 681992 are working, but the actual command 681993 isn' t所以我相信它可能是我的代码 . (它可能是我的插件之一,但是对此表示怀疑)插件可以很好地加载任何错误,并在启动时向控制台发送消息 .

我正在使用Craftbukkit 1.8快照 .
其他人可以测试我的代码,或指出任何明显的错误 .

这是我的插件的源代码

package me.MorrisKid.myfirstplugin;

import java.util.logging.Logger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

public class main extends JavaPlugin {
    public Logger logger = Logger.getLogger("Minecraft");
    public void onEnable(){
        PluginDescriptionFile pdffile = this.getDescription();
        this.logger.info(pdffile.getName() + " Has been enabled");
    }
    public void onDisable(){
        PluginDescriptionFile pdffile = this.getDescription();
        this.logger.info(pdffile + " Has been disabled");
    }
    public boolean onCommand(Command cmd, CommandSender sender, String label, String[] args){
        if(label.equalsIgnoreCase("hello")){
            Player p = (Player) sender;
            p.sendMessage("Hello!");
        }   
        return true;
    }
}

如果需要,您可以获得插件文件的副本,和/或插件的已编译Jar

here下载编译的jar
here下载完整目录

1 回答

  • 1

    你必须有一个plugin.yml文件 - 所以bukkit会知道该命令的插件是什么 . 如果你没有,它显然不会起作用 . 它可能看起来像这样:

    name: MorrisKid's plugin
    main: me.MorrisKid.myfirstplugin.main
    version: 1.0.0
    load: startup
    description: this is my first plugin
    commands:
      hello:
        description: greeting the player!
        usage: /<command>
    

    *我没有't test this yml, so check that it'正确且没有语法错误 . 检查这个youtuber的视频:https://www.youtube.com/watch?v=_EUPVpqwvZw他解释了plugin.yml文件 .

相关问题