【问题标题】:Having Trouble Devloping Minecraft Plugin开发 Minecraft 插件时遇到问题
【发布时间】:2021-05-16 21:05:41
【问题描述】:

按照 YouTube 教程,但是当我运行插件时,Minecraft 根本没有注册它。 该插件旨在返回“嗨!”当播放 /hello 或 /hi 时。 当我将插件放在我的服务器上时,甚至没有在 /plugins 中注册

代码: Main.java:

package me.Cheese_Echidna.helloworld;

import me.Cheese_Echidna.helloworld.commands.HelloCommand;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin {

    @Override
    public void onEnable() {
        new HelloCommand(this);

    }
}

HelloCommand.java:

package me.Cheese_Echidna.helloworld.commands;

import me.Cheese_Echidna.helloworld.Main;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;


public class HelloCommand implements CommandExecutor {

    @SuppressWarnings("unused")
    private Main plugin;

    public HelloCommand(Main plugin) {
        this.plugin = plugin;
        plugin.getCommand("hello").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         if (!(sender instanceof Player)) {
             sender.sendMessage("Only players may execute this command!");
             return true;
         }
         Player p = (Player) sender;

         if (p.hasPermission("hello.use")) {
             p.sendMessage("Hi!");

             return true;
         } else {
             p.sendMessage("You do not have permission to execute this command!");
         }

        return false;
    }

}

plugin.yml:

name: HelloWorld
version: 1.0
author: Cheese_Echidna
main: me.Cheese_Echidna.helloworld.main
description: My first Bukkit plugin

commands:
  hello:
   aliases: [hi]
   description: This is the hello command!

YT 教程: https://www.youtube.com/watch?v=XaU8JKQW0Ao

我在此处附上了文件结构的照片:

任何帮助将不胜感激。

【问题讨论】:

  • 您是否正在以任何方式构建.jar 文件?写完代码后做什么?你是怎么把它放在你的服务器上的?
  • 我只是导出到 .jar
  • 您好!您能否在启动时发布服务器控制台的输出?

标签: java minecraft


【解决方案1】:

我有一个基本问题。 您是否在您的 Minecraft 服务器上安装了 Vanilla Minecraft 版本?要使用 Bukkit 或 Spigot 插件,您必须使用它们的扩展程序

【讨论】:

    【解决方案2】:

    我不舒尔。但问题可能出在 plugin.yml 中!

    首先重要的是您在 plugin.yml 中为制表符使用一个空格

    另一个问题是你有 main 后面的路径:必须通向一个类 在这种情况下,它将是 主:me.Cheese_Echidna.helloworld.main.Main

    更正后的 plugin.yml 应如下所示:

    name: HelloWorld
    version: 1.0
    author: Cheese_Echidna
    main: me.Cheese_Echidna.helloworld.main.Main
    description: My first Bukkit plugin
    
    commands:
     hello:
      aliases: [hi]
      description: This is the hello command!
    

    【讨论】:

      【解决方案3】:

      您忘记在 plugin.yml 中添加 API 版本。很常见的错误,别担心,很多人都会这样做。这是 plugin.yml wiki 了解更多信息:Plugin.yml wiki

      它也应该是这样的。看来您的文件位于文件夹中,而不是包中。

      My plugin.yml for reference

      【讨论】: