我的Minecraft Spigot插件未报告

时间:2020-08-28 15:02:59

标签: java minecraft

我对Java编程非常陌生,并且已经完成了一些教程,这些教程很棒,但是我不知道为什么它在游戏中不起作用。我已经尝试过各种方法,例如更改它以及查看许多不同的论坛。事件有两个类(加入和离开事件)和主类。我已经确保检查了它们的导入,并且没有错误可供我查看。如果有人可以帮助,那将是一件好事。

代码:-主类:

package me.JimmyClown.FirstPlugin;

import org.bukkit.plugin.java.JavaPlugin;

public class MainClass extends JavaPlugin {
    
@Override 
   
public void onEnable() {

        System.out.println("It works!");
        getServer().getPluginManager().registerEvents(new PlayerJoin(), this);
        getServer().getPluginManager().registerEvents(new PlayerLeave(), this);
    }
    
    @Override
    public void onDisable() {
        
    }       
}

**Code for the Join-Class:**

package me.JimmyClown.FirstPlugin;

import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

public class PlayerJoin implements Listener{
    
@EventHandler
    
void onPlayerJoin(PlayerJoinEvent e) {
        
Player player = e.getPlayer();
        
e.setJoinMessage(ChatColor.BLUE + "Welcome back to the server!" + player.getDisplayName());
    }   
}
**Code for Leave Class:**
package me.JimmyClown.FirstPlugin;

import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;

public class PlayerLeave implements Listener {
    @EventHandler
    void onPlayerLeave(PlayerQuitEvent e) {
        Player player = e.getPlayer();
        e.setQuitMessage(ChatColor.DARK_BLUE + "Awwww, We hope we see you soon" + player.getDisplayName());
    }   
}

plugin.yml:

name: FirstProject
version: 1.0
main: me.JimmyClown.FirstPlugin.MainClass
authors: JimmyTheClown
description: This is my first plugin.

1 个答案:

答案 0 :(得分:0)

尝试将事件方法的访问修饰符设置为public。

public void onPlayerLeave(PlayerQuitEvent e) { }

public void onPlayerJoin(PlayerJoinEvent e) { }