以下是一个使用Java编写的示例代码,当玩家长时间不移动时,将在其头顶显示一条基于HolographicDisplays插件的文字消息。

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;

public class PlayerMovementChecker extends BukkitRunnable {
    
    private final Plugin plugin;
    private final int idleTimeInSeconds;
    
    public PlayerMovementChecker(Plugin plugin, int idleTimeInSeconds) {
        this.plugin = plugin;
        this.idleTimeInSeconds = idleTimeInSeconds;
    }
    
    @Override
    public void run() {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (!player.isSneaking() && !player.isInsideVehicle() && player.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) {
                // Check if the player is not sneaking, not inside a vehicle, and standing on an empty block
                long idleTime = (System.currentTimeMillis() - player.getLastMovementTime()) / 1000;
                
                if (idleTime >= idleTimeInSeconds) {
                    // Player has been idle for the specified time
                    showHologram(player);
                }
            }
        }
    }
    
    private void showHologram(Player player) {
        // Use HolographicDisplays API to create a hologram and display it above the player's head
        
        // Example code:
        // Hologram hologram = HologramsAPI.createHologram(plugin, player.getLocation().add(0, 1.5, 0));
        // hologram.appendTextLine("You have been idle for too long!");
    }
}

你需要将上述代码添加到你的插件中,并在启用插件时调度这个任务,例如:

import org.bukkit.plugin.java.JavaPlugin;

public class YourPlugin extends JavaPlugin {
    
    private PlayerMovementChecker movementChecker;
    
    @Override
    public void onEnable() {
        // Initialize and schedule the PlayerMovementChecker task to run every second
        movementChecker = new PlayerMovementChecker(this, 10);
        movementChecker.runTaskTimer(this, 0L, 20L);
    }
    
    @Override
    public void onDisable() {
        // Cancel the task when the plugin is disabled
        movementChecker.cancel();
    }
}

在这个例子中,idleTimeInSeconds参数表示玩家长时间不移动的阈值,以秒为单位。你可以根据需要进行调整。

请注意,这只是示例代码,你需要根据你的实际需求和具体的HolographicDisplays插件API进行适当的修改和调整

用Java写一个Bukkit1201 玩家长时间不移动的时候头顶显示一条基于HolographicDisplays插件的文字消息

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

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