简体   繁体   English

当我吃东西时,我的 Spigot Minecraft 插件没有说“yum”

[英]My Spigot Minecraft plugin doesn't say "yum" when I eat something

I'm working on a Spigot plugin right now.我现在正在开发一个 Spigot 插件。 but I'm having some problems with it.但我遇到了一些问题。 I'm having issues with the listeners.我对听众有问题。 I've watched tutorials but it didn't work.我看过教程,但没有用。 When I eat something in-game it doesn't say "Yum!"当我在游戏中吃东西时,它不会说“好吃!” It doesn't do anything.它什么也不做。 I tried to fix it but I can't.我试图修复它,但我不能。 I don't think it's because I put it in the same package.我不认为是因为我把它放在同一个包里。

Listeners.java :监听器.java:

package adawda.awdwa;

import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class Listeners extends JavaPlugin implements Listener
{
    public Listeners(Awdwa plugin)
    {

    }
    public void onEnable()
    {
        Bukkit.getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void onPlayerItemConsume(PlayerItemConsumeEvent event)
    {
        event.getPlayer().sendMessage("Yum!");
    }
}

Awdwa.java ( Main ) : Awdwa.java(主):

package adawda.awdwa;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

import java.util.Arrays;

public final class Awdwa extends JavaPlugin implements CommandExecutor {
    public Location homeLoc;
    @Override
    public void onEnable() {
        // Plugin startup logic
        PluginManager pm = getServer().getPluginManager();
        Listeners listener = new Listeners(this);
        pm.registerEvents(listener,this);
    }

    @Override
    public void onDisable() {
        // Plugin shutdown logic
    }
    public void onPlayerJoin(PlayerJoinEvent event)
    {
        Bukkit.broadcastMessage("Naber, " + event.getPlayer().getName()+"!");
    }
    public void onPlayerBedEnter(PlayerBedEnterEvent event)
    {
        Bukkit.broadcastMessage("birisi uyuyor.. daha doğrusu çalışıyor.");
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        String cmdName = cmd.getName().toLowerCase();
        Player p = (Player) sender;
        if (cmdName.equals("example")) {
            sender.sendMessage("UwU it works!");
            return true;
        } else if(cmdName.equals("sethome")) {
            homeLoc = p.getLocation();
            return true;
        } else if(cmdName.equals("home")) {
            p.teleport(homeLoc);
            return  true;
        } else if(cmdName.equals("kedi")) {
            World w = getServer().getWorld("world");
            int i = 0;
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            w.spawnEntity(p.getLocation(), EntityType.CAT);
            return true;
        }
        else {
            return false;
        }
    }
}

Please remove the extends JavaPlugin in your Listeners.class .请删除Listeners.class中的extends JavaPlugin This will only be needed inside the Main.class .这仅在Main.class 中需要。 Your Listeners.class should only implement Listener by default.默认情况下,您的Listeners.class应仅实现 Listener。 You should then also remove the constructor and the onEnable() method inside your Listeners class as they are not needed.然后,您还应该删除 Listeners 类中的构造函数和 onEnable() 方法,因为它们不是必需的。

You should then change your way of registering events inside your Main.class .然后,您应该更改在Main.class中注册事件的方式 You should register events like this:您应该注册这样的事件:

pm.registerEvents(new Listeners(), this);

(Create a new Listeners Object inside the registerEvents() method) (在 registerEvents() 方法中创建一个新的 Listeners 对象)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM