gpt4 book ai didi

java - Bukkit PlayerInteractEvent 不起作用

转载 作者:行者123 更新时间:2023-11-30 07:54:43 25 4
gpt4 key购买 nike

我认为这是正确的,但如果我用斧头点击什么也没有发生,没有错误

我不知道出了什么问题,因为在互联网上它可以工作

package mrleaw.tools.main;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin implements Listener{

String prefix = "§0[§4RollmopsMC | Tools§0] §5";

public void onEnable() {
Bukkit.getConsoleSender().sendMessage(prefix + "§aDas Plugin wurde aktiviert!");
Bukkit.getConsoleSender().sendMessage(prefix + "§6Coded by MrLeaw");
}
public void onDisable() {
Bukkit.getConsoleSender().sendMessage(prefix + "§cDas Plugin wurde deaktiviert!");
Bukkit.getConsoleSender().sendMessage(prefix + "§6Coded by MrLeaw");
}

@EventHandler
void onRightClickTool(PlayerInteractEvent e){
try {
if(e.getAction() == Action.LEFT_CLICK_AIR
|| e.getAction() == Action.RIGHT_CLICK_AIR
|| e.getAction() == Action.LEFT_CLICK_BLOCK
|| e.getAction() == Action.RIGHT_CLICK_BLOCK){
Player player = e.getPlayer();
if(player.getItemInHand() != null && player.getItemInHand().getType() == Material.WOOD_AXE){
player.sendMessage(prefix + "test");
}
}
}catch(Exception exception){
}catch(Error error){
}
}
}

最佳答案

添加 getServer().getPluginManager().registerEvents(this, this);onEnable()

根据 Bukkit API reference,您必须这样做才能注册您的监听器

关于java - Bukkit PlayerInteractEvent 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43822049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com