你可以使用以下代码来获取玩家所打开的箱子的坐标:

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class ChestCoordinatesPlugin extends JavaPlugin implements Listener {

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

    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {
        if (event.getClickedInventory() != null && event.getClickedInventory().getLocation() != null) {
            Block clickedBlock = event.getClickedInventory().getLocation().getBlock();
            if (clickedBlock.getType().toString().contains("CHEST")) {
                Location chestLocation = clickedBlock.getLocation();
                int chestX = chestLocation.getBlockX();
                int chestY = chestLocation.getBlockY();
                int chestZ = chestLocation.getBlockZ();
                event.getWhoClicked().sendMessage("You opened a chest at coordinates: X=" + chestX + ", Y=" + chestY + ", Z=" + chestZ);
            }
        }
    }
}

这个代码创建了一个Bukkit插件,它监听了InventoryClickEvent事件。当玩家点击一个物品栏时,它会检查该物品栏是否位于一个箱子上。如果是,它就会获取箱子的坐标,并向玩家发送一个包含箱子坐标的消息。

记得将代码编译为JAR文件并将其放入你的Bukkit服务器的插件文件夹中。然后在服务器启动时,插件将会被加载并监听InventoryClickEvent事件。当玩家打开一个箱子时,它将会输出箱子的坐标到玩家的聊天框中

用Java写一个Bukkit1201里面 获取玩家所打开的箱子坐标用InventoryClickEvent

原文地址: http://www.cveoy.top/t/topic/ieCE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录