ghansis

create a plugin that allows geyser players to disable their coordinates or enable using a /enablecoordinates and /disable coordinates.

it can only turn it off for them, not everyone.

Kodari AI
KodariJul 9 at 2:07 pm 2
GeyserCoordsToggle
A plugin that lets Geyser (Bedrock) players individually toggle their coordinate display on or off. Players use /enablecoordinates to see their coordinates via actionbar, and /disablecoordinates to hide them. Settings are stored per-player and persist across sessions. Only affects the player who runs the command — no global gamerule changes.

I’ll create the plugin structure now

A plugin that lets Geyser (Bedrock) players individually toggle their coordinate display using /enablecoordinates and /disablecoordinates. Each player's preference is saved and persists across sessions. Uses a per-player scoreboard to show/hide coordinates — only affects the player who runs the command, not the whole server.
ghansis

The compilation failed with this error:

code
Compilation failed with 2 error(s):

ERROR in src/main/java/com/example/geysercoordstoggle/GeyserCoordsToggle.java at line 16: package org.geysermc.geyser.api does not exist
import org.geysermc.geyser.api.GeyserApi;
                              ^

ERROR in src/main/java/com/example/geysercoordstoggle/GeyserCoordsToggle.java at line 21: cannot find symbol
    private GeyserApi geyserApi;
            ^
  symbol: class GeyserApi
  location: class GeyserCoordsToggle


=== COMPILATION ERROR ANALYSIS ===

MISSING CLASSES:
  - GeyserApi
ACTION: Create these classes or check imports

FILES TO INVESTIGATE:
  - src/main/java/com/example/geysercoordstoggle/GeyserCoordsToggle.java

Please fix this error by creating a new artifact with the corrected code.

Kodari AI
KodariJul 9 at 2:10 pm 1

The Geyser API can’t be resolved at compile time in this environment. I’ll refactor to use soft-depend + reflection — it’s actually the better pattern for Geyser plugins since it removes the hard compile dependency entirely

All 3 patches applied. The plugin now uses reflection to access the Geyser API at runtime, removing the compile-time dependency:

  • build.gradle — Geyser API dep removed (no longer needed at compile time)

  • plugin.yml — depend → softdepend, so it loads fine without Geyser installed

  • GeyserCoordsToggle.java — Geyser API loaded via reflection; isBedrockPlayer() returns false if Geyser is absent

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
5 260
src/main/java/com/example/geysercoordstoggle/GeyserCoordsToggle.java
package com.example.geysercoordstoggle;

import com.example.geysercoordstoggle.commands.ToggleCoordsCommand;
import com.example.geysercoordstoggle.managers.PlayerDataManager;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;

import java.lang.reflect.Method;

public class GeyserCoordsToggle extends JavaPlugin implements Listener {

    private PlayerDataManager playerDataManager;
    private Object geyserApi;
    private Method isBedrockPlayerMethod;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        playerDataManager = new PlayerDataManager(this);

        try {
            Class<?> geyserApiClass = Class.forName("org.geysermc.geyser.api.GeyserApi");
            geyserApi = geyserApiClass.getMethod("api").invoke(null);
            isBedrockPlayerMethod = geyserApiClass.getMethod("isBedrockPlayer", java.util.UUID.class);
            getLogger().info("Geyser API hooked successfully.");
        } catch (Exception e) {
            getLogger().warning("Geyser not found — Bedrock check disabled");
        }

        getCommand("enablecoordinates").setExecutor(new ToggleCoordsCommand(this));
        getCommand("disablecoordinates").setExecutor(new ToggleCoordsCommand(this));

        Bukkit.getPluginManager().registerEvents(this, this);

        Bukkit.getScheduler().runTaskTimer(this, this::updateCoordinateScoreboards, 0L, 20L);

        getLogger().info("GeyserCoordsToggle enabled!");
    }

    @Override
    public void onDisable() {
        if (playerDataManager != null) {
            playerDataManager.save();
        }
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Bukkit.getScheduler().runTaskLater(this, () -> {
            Player player = event.getPlayer();
            if (!isBedrockPlayer(player.getUniqueId())) return;
            if (playerDataManager.isCoordsEnabled(player.getUniqueId())) {
                showCoordinates(player);
            } else {
                hideCoordinates(player);
            }
        }, 10L);
    }

    public boolean isBedrockPlayer(java.util.UUID uuid) {
        if (geyserApi == null || isBedrockPlayerMethod == null) return false;
        try {
            return (boolean) isBedrockPlayerMethod.invoke(geyserApi, uuid);
        } catch (Exception e) {
            return false;
        }
    }

    public PlayerDataManager getPlayerDataManager() {
        return playerDataManager;
    }

    public void showCoordinates(Player player) {
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        if (manager == null) return;
        Scoreboard board = manager.getNewScoreboard();
        Objective objective = board.registerNewObjective("gct_coords", "dummy", "§6§lCoordinates");
        objective.setDisplaySlot(DisplaySlot.SIDEBAR);
        player.setScoreboard(board);
    }

    public void hideCoordinates(Player player) {
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        if (manager == null) return;
        player.setScoreboard(manager.getNewScoreboard());
    }

    private void updateCoordinateScoreboards() {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (!isBedrockPlayer(player.getUniqueId())) continue;
            if (!playerDataManager.isCoordsEnabled(player.getUniqueId())) continue;

            Scoreboard board = player.getScoreboard();
            Objective objective = board.getObjective("gct_coords");
            if (objective == null) continue;

            int x = player.getLocation().getBlockX();
            int y = player.getLocation().getBlockY();
            int z = player.getLocation().getBlockZ();
            String world = player.getWorld().getName();

            for (String entry : board.getEntries()) {
                board.resetScores(entry);
            }

            objective.getScore("§7World: §f" + world).setScore(4);
            objective.getScore("§7X: §f" + x).setScore(3);
            objective.getScore("§7Y: §f" + y).setScore(2);
            objective.getScore("§7Z: §f" + z).setScore(1);
        }
    }
}