我正在尝试为Minecraft进行bukkit编程,但是由于某些原因,我陷入了事件。这是我的代码:

主类文件:

package com.plugin1;

import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginDescriptionFile;
//import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

import net.md_5.bungee.api.ChatColor;

public class Plugin extends JavaPlugin {

    public int songStage;
    public static Plugin plugin;

    public void OnEnable () {
        PluginDescriptionFile pluginDesc = getDescription();
        Logger logger = getLogger();

        plugin = this;
        registerEvents(this, new BlockBreak());

        logger.info(pluginDesc.getName() + " is enabled! (V. " + pluginDesc.getVersion() + ")");
    }

    public void OnDisable () {
        PluginDescriptionFile pluginDesc = getDescription();
        Logger logger = Logger.getLogger("Plugin");

        plugin = null;
        logger.info(pluginDesc.getName() + " is disabled! (V. " + pluginDesc.getVersion() + ")");
    }

    public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
        for (Listener listener : listeners) {
            Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
            }
        }

    public static Plugin getPlugin() {
        return plugin;
        }
   }


事件类文件:

package com.plugin1;

import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

public class BlockBreak implements Listener {

    @EventHandler(priority = EventPriority.HIGH)
    public void OnBlockBreak (BlockBreakEvent e) {
        Player p = e.getPlayer();

        p.sendMessage("Block broken.");
    }
}


基本上,这不会返回任何错误。我已经通过控制台了,什么都没有。当我打破障碍时,实际上什么也没发生!

我尝试了一些事情:经历了这些,尝试了多个视频教程,并在Minecraft论坛上尝试了文本教程,但还是一无所获。我还联系了一位为bukkit插件编码的服务器所有者,但他无法解决此问题。

如果有人可以帮助我,请告诉我!!!!

提前致谢!

最佳答案

我认为您没有以正确的方式注册监听器...

尝试这段代码,告诉我是否可行...我真的很想帮助您

首先,不要使用“插件”作为主类的名称...而是使用“主”。

启用:

public class Main extends JavaPlugin {

    public void onEnable() {
        Bukkit.getPluginManger().registerEvents(new Join(this),this);
    }

}


听众:

public class Join implements Listener {

    private Main plugin;

    public Join(Main plugin) {
        this.plugin = plugin;
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent ev) {
        ev.setJoinMessage("Just another test");
    }
}


希望它能...

关于java - Minecraft Bukkit Activity ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35687552/

10-08 22:12