MrBynoz

can you make me a plugin that can hide cordinates x , y , z from f3 until the player type the coreect password /login .. and also after server give him a notification that he is logined after that the player can use cordinates!! until that don't show !!!

Kodari AI
KodariOct 8 at 9:08 am 1
CoordinateLock
A Minecraft plugin that hides the player's coordinates (X, Y, Z) from the F3 debug screen until they authenticate with a password via /login. On server join, coordinates are hidden and a notification prompts the player to log in. After entering the correct password, the plugin sends a confirmation message and restores coordinate visibility for that player. The plugin manages password storage, login sessions, and enforces coordinate hiding for unauthenticated players.

I’ll create a Paper plugin with per-player /register and /login passwords, hiding F3 debug details until authentication succeeds and then notifying the player.

Created CoordinateLogin. Players register once with /register <password> <password>, then use /login <password> when they join. Until login, the plugin enables Minecraft’s Reduced Debug Info for them; after successful login, it reveals F3 coordinates and sends a confirmation. Passwords are stored as salted hashes.

Minecraft’s Reduced Debug Info also hides some other F3 details, not just coordinates.

MrBynoz

The compilation failed with this error:

code
Compilation failed with 2 error(s):

ERROR in src/main/java/com/kodari/coordinatelogin/CoordinateLoginPlugin.java at line 42: cannot find symbol
        player.setReducedDebugInfo(true);
              ^
  symbol: method setReducedDebugInfo(boolean)
  location: variable player of type Player

ERROR in src/main/java/com/kodari/coordinatelogin/CoordinateLoginPlugin.java at line 132: cannot find symbol
        player.setReducedDebugInfo(false);
              ^
  symbol: method setReducedDebugInfo(boolean)
  location: variable player of type Player


=== COMPILATION ERROR ANALYSIS ===

MISSING METHODS:
  - setReducedDebugInfo(boolean)
ACTION: Check method names and signatures

FILES TO INVESTIGATE:
  - src/main/java/com/kodari/coordinatelogin/CoordinateLoginPlugin.java

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

Kodari AI
KodariOct 8 at 9:11 am 1

Plan:

  1. Replace the unavailable Bukkit calls with a per-player reduced-debug packet.

  2. Add ProtocolLib as a required runtime dependency so the setting remains player-specific.

  3. Keep the existing password and login flow unchanged.

Replaced the unsupported Player#setReducedDebugInfo calls with ProtocolLib packets, preserving per-player coordinate hiding. ProtocolLib is now a required server plugin for CoordinateLogin to work.

MrBynoz

The compilation failed with this error:

code
Compilation failed with 2 error(s):

ERROR in src/main/java/com/kodari/coordinatelogin/CoordinateLoginPlugin.java at line 42: cannot find symbol
        player.setReducedDebugInfo(true);
              ^
  symbol: method setReducedDebugInfo(boolean)
  location: variable player of type Player

ERROR in src/main/java/com/kodari/coordinatelogin/CoordinateLoginPlugin.java at line 132: cannot find symbol
        player.setReducedDebugInfo(false);
              ^
  symbol: method setReducedDebugInfo(boolean)
  location: variable player of type Player


=== COMPILATION ERROR ANALYSIS ===

MISSING METHODS:
  - setReducedDebugInfo(boolean)
ACTION: Check method names and signatures

FILES TO INVESTIGATE:
  - src/main/java/com/kodari/coordinatelogin/CoordinateLoginPlugin.java

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

Kodari AI
KodariOct 8 at 9:12 am 1

Updated to CoordinateLogin 1.0.1. The current code uses a ProtocolLib packet helper—there are no calls to Player#setReducedDebugInfo(boolean). ProtocolLib remains a required server dependency.

MrBynoz
📎 1 file 34,263 chars
📄
pasted-code-1791451099122.txt
txt 343 lines
▶
>....[09:16:48 INFO]: [Multiverse-Core] Loving Multiverse-Core? Please consider supporting the project with a small donation: https://github.com/sponsors/Multiverse
>....[09:16:48 INFO]: [EconomySystem] Enabling EconomySystem v1.33
>....[09:16:48 INFO]: [PlaceholderAPI] Successfully registered internal expansion: economysystem [1.33]
>....[09:16:48 INFO]: [EconomySystem] MoneyTop PlaceholderAPI Expansion loaded!
>....[09:16:48 INFO]: [EconomySystem] Connected to LiteSQL database at economy.db
>....[09:16:48 INFO]: [EconomySystem] Tables created or already exist.
>....[09:16:48 INFO]: TextComponentImpl{content='', children=[TextComponentImpl{content='[EconomySystem]', children=[], style=StyleImpl{font=null, color=green, shadowColor=null, decorations=DecorationMap{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set}, clickEvent=null, hoverEvent=null, insertion=null}}, TextComponentImpl{content=' ', children=[], style=StyleImpl{font=null, color=null, shadowColor=null, decorations=DecorationMap{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set}, clickEvent=null, hoverEvent=null, insertion=null}}, TextComponentImpl{content='The plugin has been enabled!', children=[], style=StyleImpl{font=null, color=green, shadowColor=null, decorations=DecorationMap{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set}, clickEvent=null, hoverEvent=null, insertion=null}}], style=StyleImpl{font=null, color=null, shadowColor=null, decorations=DecorationMap{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set}, clickEvent=null, hoverEvent=null, insertion=null}}
>....[09:16:48 INFO]: [Multiverse-Portals] Enabling Multiverse-Portals v5.3.0
>....[09:16:48 INFO]: [Multiverse-Portals] 0 - Portals(s) loaded
>....[09:16:48 INFO]: [Multiverse-Portals] Found WorldEdit. Using it for selections.
>....[09:16:48 INFO]: [Multiverse-Portals] Version 5.3.0 (API v5.3) Enabled - By Rigby, fernferret and benwoo1110
>....[09:16:48 INFO]: [ViaBackwards] Enabling ViaBackwards v5.12.0
>....[09:16:48 INFO]: [Spawn] Enabling Spawn v2.4.4
>....[09:16:48 INFO]: [WorldMobFix] Enabling WorldMobFix v1.0.0
>....[09:16:48 INFO]: [WorldMobFix] WorldMobFix enabled. Protected world: world
>....[09:16:48 INFO]: [AuctionPlus] Enabling AuctionPlus v1.0.0
>....[09:16:48 INFO]: [LeaderboardEconomy] Enabling LeaderboardEconomy v2.1.0
>....[09:16:48 INFO]: [LeaderboardEconomy] Scoreboard title is too long to use bold with hex colors - using non-bold. Use a shorter title.text to keep bold.
>....[09:16:48 INFO]: [LeaderboardEconomy] Hooked into Vault economy: Dollar
>....[09:16:48 INFO]: [NoEnd] Enabling NoEnd v1.0.0
>....[09:16:48 INFO]: [NoEnd] NoEnd enabled - players cannot enter the End.
>....[09:16:48 INFO]: [DayNightFix] Enabling DayNightFix v1.0
>....[09:16:48 INFO]: [DayNightFix] DayNightFix enabled.
>....[09:16:48 INFO]: [WildRTP] Enabling WildRTP v4.0
>....[09:16:49 INFO]: [WildRTP] WildRTP by Joni running version: 4.0
>....[09:16:49 INFO]: [WildRTP] PlaceholderAPI hook enabled.
>....[09:16:49 INFO]: [PlaceholderAPI] Successfully registered internal expansion: wildrtp [4.0]
>....[09:16:49 INFO]: [WildRTP] Checking for updates...
>....[09:16:49 INFO]: [ShieldAC] Enabling ShieldAC v1.0.0
>....[09:16:49 INFO]: [ShieldAC] ShieldAC enabled. Ops are exempt, everyone else is watched.
>....[09:16:49 INFO]: [CozyShop] Enabling CozyShop v1.3.0
>....[09:16:49 WARN]: [CozyShop] [overworld/lighting] Unknown item 'CHAIN' - skipped.
>....[09:16:49 INFO]: [CozyShop] [overworld] loaded 812 items in 20 sections.
>....[09:16:49 INFO]: [CozyShop] [nether] loaded 106 items in 5 sections.
>....[09:16:49 INFO]: [CozyShop] [end] loaded 0 items in 0 sections.
>....[09:16:49 INFO]: [CozyShop] CozyShop enabled.
>....[09:16:49 INFO]: [WorldRules] Enabling WorldRules v1.0.0
>....[09:16:49 INFO]: [WorldRules] WorldRules enabled for world 'orchid'.
>....[09:16:49 INFO]: [Citizens] Enabling Citizens v2.0.44-SNAPSHOT (build 4256)
>....[09:16:49 INFO]: [WildRTP] You are on the latest version! (4.0)
>....[09:16:49 INFO]: [Citizens] Loaded 2 templates.
>....[09:16:49 INFO]: [PlaceholderAPI] Successfully registered internal expansion: citizens [1.0.0]
>....[09:16:49 INFO]: [Citizens] Loaded economy handling via Vault.
>....[09:16:50 WARN]: Plugin SetHome v1.0.0 tried to register permission 'sethome.use' but it's already registered
>....[09:16:50 WARN]: Plugin SetHome v1.0.0 tried to register permission 'sethome.op' but it's already registered
>....[09:16:50 WARN]: Plugin SetHome v1.0.0 tried to register permission 'sethome.reload' but it's already registered
>....[09:16:50 INFO]: [SetHome] Enabling SetHome v1.0.0
>....[09:16:50 INFO]: [Multiverse-NetherPortals] Enabling Multiverse-NetherPortals v5.1.0
>....[09:16:50 INFO]: [Multiverse-NetherPortals] Version 5.1.0 (API v5.1) Enabled - By Rigby, fernferret and benwoo1110
>....[09:16:50 INFO]: [voicechat] Enabling voicechat v2.6.24
>....[09:16:50 INFO]: [voicechat] Initializing compatibility for version 26.3.build.140-beta
>....[09:16:50 INFO]: [voicechat] Compatibility version 20
>....[09:16:50 INFO]: [voicechat] Successfully initialized commodore command completion
>....[09:16:50 INFO]: [PlaceholderAPI] Successfully registered internal expansion: voicechat [2.6.24]
>....[09:16:50 INFO]: [voicechat] Successfully registered PlaceholderAPI expansion
>....[09:16:50 INFO]: [voicechat] Successfully added ViaVersion mappings
>....[09:16:50 WARN]: Plugin Ranks v1.0.0 tried to register permission 'ranks.set' but it's already registered
>....[09:16:50 INFO]: [Ranks] Enabling Ranks v1.0.0
>....[09:16:50 INFO]: [Ranks] Ranks enabled.
>....[09:16:50 INFO]: [UltraCoinFlip] Enabling UltraCoinFlip v6.6.2
>....[09:16:50 INFO]: [UltraCoinFlip] Server Information:
>....[09:16:50 INFO]: [UltraCoinFlip]   Server: Paper
>....[09:16:50 INFO]: [UltraCoinFlip]   Version: 26.3-140-977da0d (MC: 26.3)
>....[09:16:50 INFO]: [UltraCoinFlip]   Detected Version: 26.3
>....[09:16:50 INFO]: [UltraCoinFlip]   Java Version: 25
>....[09:16:50 INFO]: [UltraCoinFlip] ✓ Server compatibility check passed
>....[09:16:50 INFO]: [UltraCoinFlip] Server Version: 26.3
>....[09:16:50 INFO]: [UltraCoinFlip] Server Software: Paper
>....[09:16:50 INFO]: [UltraCoinFlip] Java Version: 25
>....[09:16:50 INFO]: [UltraCoinFlip] Legacy Mode: No
>....[09:16:50 INFO]: [UltraCoinFlip] Adventure Native: Yes
>....[09:16:50 INFO]: [UltraCoinFlip] 
>....[09:16:50 INFO]: [UltraCoinFlip]               /$$   /$$ /$$    /$$$$$$$$ /$$$$$$$   /$$$$$$ 
>....[09:16:50 INFO]: [UltraCoinFlip]              | $$  | $$| $$   |__  $$__/| $$__  $$ /$$__  $$
>....[09:16:50 INFO]: [UltraCoinFlip]              | $$  | $$| $$      | $$   | $$  \ $$| $$  \ $$
>....[09:16:50 INFO]: [UltraCoinFlip]              | $$  | $$| $$      | $$   | $$$$$$$/| $$$$$$$$
>....[09:16:50 INFO]: [UltraCoinFlip]              | $$  | $$| $$      | $$   | $$__  $$| $$__  $$
>....[09:16:50 INFO]: [UltraCoinFlip]              | $$  | $$| $$      | $$   | $$  \ $$| $$  | $$
>....[09:16:50 INFO]: [UltraCoinFlip]              |  $$$$$$/| $$$$$$$$| $$   | $$  | $$| $$  | $$
>....[09:16:50 INFO]: [UltraCoinFlip]               \______/ |________/|__/   |__/  |__/|__/  |__/
>....[09:16:50 INFO]: [UltraCoinFlip] 
>....[09:16:50 INFO]: [UltraCoinFlip]   /$$$$$$   /$$$$$$  /$$$$$$ /$$   /$$ /$$$$$$$$ /$$       /$$$$$$ /$$$$$$$ 
>....[09:16:50 INFO]: [UltraCoinFlip]  /$$__  $$ /$$__  $$|_  $$_/| $$$ | $$| $$_____/| $$      |_  $$_/| $$__  $$
>....[09:16:50 INFO]: [UltraCoinFlip] | $$  \__/| $$  \ $$  | $$  | $$$$| $$| $$      | $$        | $$  | $$  \ $$
>....[09:16:50 INFO]: [UltraCoinFlip] | $$      | $$  | $$  | $$  | $$ $$ $$| $$$$$   | $$        | $$  | $$$$$$$/
>....[09:16:50 INFO]: [UltraCoinFlip] | $$      | $$  | $$  | $$  | $$  $$$$| $$__/   | $$        | $$  | $$____/ 
>....[09:16:50 INFO]: [UltraCoinFlip] | $$    $$| $$  | $$  | $$  | $$\  $$$| $$      | $$        | $$  | $$      
>....[09:16:50 INFO]: [UltraCoinFlip] |  $$$$$$/|  $$$$$$/ /$$$$$$| $$ \  $$| $$      | $$$$$$$$ /$$$$$$| $$      
>....[09:16:50 INFO]: [UltraCoinFlip]  \______/  \______/ |______/|__/  \__/|__/      |________/|______/|__/      
>....[09:16:50 INFO]: [UltraCoinFlip] 
>....[09:16:50 INFO]: [UltraCoinFlip] [UltraCoinFlip] Using legacy text handling (no Adventure API)
>....[09:16:50 INFO]: [UltraCoinFlip] Created language folder: plugins/UltraCoinFlip/langs
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_en.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_vi.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_de.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_fr.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_zh_cn.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_zh_tw.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_ru.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_nl.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_es.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_ar.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_it.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_lt.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_pt.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_pl.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_tr.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_ko.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default language file: messages_ja.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Language files check: 17 saved, 0 updated, 0 skipped, 0 errors
>....[09:16:50 INFO]: [UltraCoinFlip] Created GUI config folder: plugins/UltraCoinFlip/gui
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default GUI config file: mainmenu.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default GUI config file: history.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default GUI config file: flipping.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default GUI config file: create.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default GUI config file: leaderboard.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default GUI config file: heads-tails.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default GUI config file: settings.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default GUI config file: audit.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default GUI config file: stats.yml
>....[09:16:50 INFO]: [UltraCoinFlip] Saved default sounds.yml file
>....[09:16:51 INFO]: [PlaceholderAPI] Successfully registered internal expansion: coinflip [6.6.2]
>....[09:16:51 INFO]: [UltraCoinFlip]      Vault economy ready!
>....[09:16:51 INFO]: [UltraCoinFlip]   → Vault:          Found (v1.7.3-b131)
>....[09:16:51 INFO]: [UltraCoinFlip]   → PlaceholderAPI: Found (v2.12.3)
>....[09:16:51 INFO]: [UltraCoinFlip]   → PlayerPoints:   Not installed
>....[09:16:51 INFO]: [UltraCoinFlip]   → TokenManager:   Not installed
>....[09:16:51 INFO]: [UltraCoinFlip]   → ExcellentEconomy: Not installed
>....[09:16:51 INFO]: [UltraCoinFlip]   → BeastTokens:    Not installed
>....[09:16:51 INFO]: [UltraCoinFlip] [ExploitDetector] Security system initialized
>....[09:16:51 INFO]: [UltraCoinFlip] SQLite database connected!
>....[09:16:51 INFO]: [UltraCoinFlip] Database initialized successfully!
>....[09:16:51 INFO]: [UltraCoinFlip] [ACF] Enabled Asynchronous Tab Completion Support!
>....[09:16:51 INFO]: [UltraCoinFlip]      bStats enabled! Anonymous statistics collection active
>....[09:16:51 INFO]: [UltraCoinFlip] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
>....[09:16:51 INFO]: [UltraCoinFlip]   UltraCoinFlip v6.6.2 enabled successfully!
>....[09:16:51 INFO]: [UltraCoinFlip] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
>....[09:16:51 INFO]: [UltraCoinFlip]   Developed by KStudio
>....[09:16:51 INFO]: [UltraCoinFlip]   Support:     https://discord.gg/GGDxDnpnDP
>....[09:16:51 INFO]: [UltraCoinFlip] 
>....[09:16:51 INFO]: [UltraCoinFlip]   💬  Found a bug or have suggestions? Join our Discord for quick support!
>....[09:16:51 INFO]: [UltraCoinFlip]   ⭐  Enjoying the plugin? Please leave a 5-star review to help us grow!
>....[09:16:51 INFO]: [SimpleLogin] Enabling SimpleLogin v1.16.7
>....[09:16:51 INFO]: [SimpleLogin] SimpleLogin enabled!
>....[09:16:51 INFO]: [BasicTPA] Enabling BasicTPA v1.0.0
>....[09:16:51 INFO]: [BasicTPA] BasicTPA has been enabled!
>....[09:16:51 INFO]: [LifeSteal] Enabling LifeSteal v3
>....[09:16:51 INFO]: [LifeSteal] LifeSteal Plugin has been enabled!
>....[09:16:51 INFO]: [MinerTrack] Enabling MinerTrack v2.1.2.0
>....[09:16:51 INFO]: [MinerTrack] Loaded group configuration: end (end.yml)
>....[09:16:51 INFO]: [MinerTrack] Loaded group configuration: overworld (overworld.yml)
>....[09:16:51 INFO]: [MinerTrack] Loaded group configuration: nether (nether.yml)
>....[09:16:51 INFO]: [MinerTrack] Built world-to-group mapping from xray.worlds: {minecraft:overworld=overworld, minecraft:the_nether=nether, minecraft:the_end=end} (default unnamed -> overworld)
>....[09:16:51 INFO]: [MinerTrack] Loaded group configurations (3 active):
>....[09:16:51 INFO]: [MinerTrack]  - nether: worlds=[minecraft:the_nether], patterns=[]
>....[09:16:51 INFO]: [MinerTrack]  - end: worlds=[minecraft:the_end], patterns=[]
>....[09:16:51 INFO]: [MinerTrack]  - overworld: worlds=[minecraft:overworld], patterns=[]
>....[09:16:51 INFO]: [MinerTrack] Default unnamed group (all_unnamed_world): overworld
>....[09:16:51 WARN]: [MinerTrack] Could not save de.yml to plugins/MinerTrack/Translations/de.yml because de.yml already exists.
>....[09:16:51 WARN]: [MinerTrack] Could not save fr.yml to plugins/MinerTrack/Translations/fr.yml because fr.yml already exists.
>....[09:16:51 WARN]: [MinerTrack] Could not save ru.yml to plugins/MinerTrack/Translations/ru.yml because ru.yml already exists.
>....[09:16:51 WARN]: [MinerTrack] Could not save zh_cn.yml to plugins/MinerTrack/Translations/zh_cn.yml because zh_cn.yml already exists.
>....[09:16:51 INFO]: [SimpleLogin] Plugin is up to date (1.16.7)
>....[09:16:51 INFO]: [MinerTrack] Core initialized for version 2.1.2.0
>....[09:16:51 INFO]: ----[MinerTrack v2.1.2.0 ]-----------
>....[09:16:51 INFO]: MinerTrack Anti-XRay Enabled!
>....[09:16:51 INFO]: 
>....[09:16:51 INFO]: Authors: Author87668
>....[09:16:51 INFO]: Original Author: Author87668
>....[09:16:51 INFO]: Contributors: Author87668, Zhang12334, Thomas, xiaoyueyoqwq
>....[09:16:51 INFO]: 
>....[09:16:51 INFO]: Thanks for your use!
>....[09:16:51 INFO]: -----------------------------------------
>....[09:16:51 INFO]: [MinerTrack] MinerTrack (BukkitPlatform) enabled.
>....[09:16:51 INFO]: [CoordinateLogin] Enabling CoordinateLogin v1.0.1
>....[09:16:51 INFO]: [Multiverse-Inventories] Enabling Multiverse-Inventories v5.3.6
>....[09:16:52 INFO]: [PlaceholderAPI] Successfully registered internal expansion: multiverse-inventories [5.3.6]
>....[09:16:52 INFO]: [Multiverse-Inventories] Loading player names map...
>....[09:16:52 INFO]: [Multiverse-Inventories] Version 5.3.6 (API v5.3) Enabled - By dumptruckman and benwoo1110
>....[09:16:52 INFO]: [FancyHolograms] Enabling FancyHolograms v2.12.0
>....[09:16:52 INFO]: [FancyHolograms] (Server thread) INFO: Successfully enabled FancyHolograms version 2.12.0
>....[09:16:52 INFO]: [spark] Starting background profiler...
>....[09:16:53 INFO]: [PlaceholderAPI] Placeholder expansion registration initializing...
>....[09:16:53 INFO]: Saving chunks for level 'ServerLevel[orchid]'/minecraft:overworld
>....[09:16:53 INFO]: Saving chunks for level 'ServerLevel[orchid]'/minecraft:the_nether
>....[09:16:53 INFO]: Saving chunks for level 'ServerLevel[orchid]'/minecraft:fun
>....[09:16:53 INFO]: Saving chunks for level 'ServerLevel[orchid]'/minecraft:the_end
>....[09:16:53 INFO]: Saving chunks for level 'ServerLevel[orchid]'/minecraft:world
>....[09:16:53 INFO]: Running delayed init tasks
>....[09:16:53 INFO]: [Vault] Checking for Updates ... 
>....[09:16:53 INFO]: [ViaVersion] Finished mapping loading, shutting down loader executor.
>....[09:16:53 INFO]: [UltraCoinFlip]   You are running the latest version (v6.6.2)
>....[09:16:53 INFO]: [Vault] No new version available
>....[09:16:54 INFO]: [Citizens] Loaded 10 NPCs.
>....[09:16:54 INFO]: Done (55.029s)! For help, type "help"
>....[09:16:54 INFO]: [voicechat] Loading plugins
>....[09:16:54 INFO]: [voicechat] Loaded 0 plugin(s)
>....[09:16:54 INFO]: [voicechat] Initializing plugins
>....[09:16:54 INFO]: [voicechat] Initialized 0 plugin(s)
>....[09:16:54 WARN]: [voicechat] Running in offline mode - Voice chat encryption is not secure!
>....[09:16:54 INFO]: [voicechat] Using the Minecraft servers port as voice chat port
>....[09:16:54 INFO]: 0 placeholder hook(s) registered!
>....[09:16:54 INFO]: [voicechat] Voice host is 'titan.foflare.com:19139'
>....[09:16:54 ERROR]: [voicechat] Failed to bind to address 'titan.foflare.com', binding to wildcard IP instead
>....[09:16:54 INFO]: [voicechat] Voice chat server started at titan.foflare.com:19139
>....[09:16:54 INFO]: *** Currently you are 19 builds behind ***
>....[09:16:54 INFO]: *** It is highly recommended to download the latest build from https://papermc.io/downloads/paper ***
>....[09:17:20 INFO]: UUID of player dwollismm is 433ba9cc-f6e2-3704-a4e0-938bbcba1072
>....[09:17:20 INFO]: [HorriblePlayerLoginEventHack] You have plugins listening to the PlayerLoginEvent, this will cause re-configuration APIs to be unavailable: [LuckPerms, ProtocolLib]
>....[09:17:21 ERROR]: Error sending packet clientbound/minecraft:game_event
io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:game_event'
	at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:63) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:13) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:27) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:12) ~[paper-26.3.jar:26.3-140-977da0d]
	at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ~[netty-codec-base-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:113) ~[netty-codec-base-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:120) ~[netty-codec-base-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.ChannelOutboundHandlerAdapter.write(ChannelOutboundHandlerAdapter.java:113) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at net.minecraft.network.Connection$2.write(Connection.java:737) ~[paper-26.3.jar:26.3-140-977da0d]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.DefaultChannelPipeline.write(DefaultChannelPipeline.java:1036) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.Channel.write(Channel.java:267) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at ProtocolLib.jar//com.comphenix.protocol.injector.netty.channel.NettyChannelProxy.write(NettyChannelProxy.java:210) ~[?:?]
	at net.minecraft.network.Connection.doSendPacket(Connection.java:521) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.Connection.lambda$sendPacket$0(Connection.java:501) ~[paper-26.3.jar:26.3-140-977da0d]
	at ProtocolLib.jar//com.comphenix.protocol.injector.netty.channel.NettyEventLoopProxy.lambda$proxyRunnable$2(NettyEventLoopProxy.java:49) ~[?:?]
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:148) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:141) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:535) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.SingleThreadIoEventLoop.run(SingleThreadIoEventLoop.java:201) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:1204) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at java.base/java.lang.Thread.run(Thread.java:1474) ~[?:?]
Caused by: java.lang.NullPointerException: Cannot read field "id" because "this.event" is null
	at net.minecraft.network.protocol.game.ClientboundGameEventPacket.write(ClientboundGameEventPacket.java:47) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.StreamCodec$2.encode(StreamCodec.java:46) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.StreamCodec$5.encode(StreamCodec.java:96) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.StreamCodec$5.encode(StreamCodec.java:86) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:58) ~[paper-26.3.jar:26.3-140-977da0d]
	... 29 more
>....[09:17:21 INFO]: System chat: dwollismm joined the game
>....[09:17:21 INFO]: dwollismm[/49.244.224.104:22810] logged in with entity id 75 at ([minecraft:world]914.2786857948084, -56.0, -1563.3453830706321)
>....[09:17:21 INFO]: dwollismm lost connection: Internal Exception: io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:game_event'
>....[09:17:21 INFO]: [voicechat] Disconnecting client dwollismm
>....[09:17:22 INFO]: System chat: ♛ KILLS #1 dwollismm left the game
>....[09:17:28 INFO]: UUID of player dwollismm is 433ba9cc-f6e2-3704-a4e0-938bbcba1072
>....[09:17:29 ERROR]: Error sending packet clientbound/minecraft:game_event
io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:game_event'
	at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:63) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:13) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:27) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:12) ~[paper-26.3.jar:26.3-140-977da0d]
	at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ~[netty-codec-base-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:113) ~[netty-codec-base-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:120) ~[netty-codec-base-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.ChannelOutboundHandlerAdapter.write(ChannelOutboundHandlerAdapter.java:113) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at net.minecraft.network.Connection$2.write(Connection.java:737) ~[paper-26.3.jar:26.3-140-977da0d]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.DefaultChannelPipeline.write(DefaultChannelPipeline.java:1036) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.Channel.write(Channel.java:267) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at ProtocolLib.jar//com.comphenix.protocol.injector.netty.channel.NettyChannelProxy.write(NettyChannelProxy.java:210) ~[?:?]
	at net.minecraft.network.Connection.doSendPacket(Connection.java:521) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.Connection.lambda$sendPacket$0(Connection.java:501) ~[paper-26.3.jar:26.3-140-977da0d]
	at ProtocolLib.jar//com.comphenix.protocol.injector.netty.channel.NettyEventLoopProxy.lambda$proxyRunnable$2(NettyEventLoopProxy.java:49) ~[?:?]
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:148) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:141) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:535) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.SingleThreadIoEventLoop.run(SingleThreadIoEventLoop.java:201) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:1204) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at java.base/java.lang.Thread.run(Thread.java:1474) ~[?:?]
Caused by: java.lang.NullPointerException: Cannot read field "id" because "this.event" is null
	at net.minecraft.network.protocol.game.ClientboundGameEventPacket.write(ClientboundGameEventPacket.java:47) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.StreamCodec$2.encode(StreamCodec.java:46) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.StreamCodec$5.encode(StreamCodec.java:96) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.StreamCodec$5.encode(StreamCodec.java:86) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:58) ~[paper-26.3.jar:26.3-140-977da0d]
	... 29 more
>....[09:17:29 INFO]: System chat: dwollismm joined the game
>....[09:17:29 INFO]: dwollismm[/49.244.224.104:22817] logged in with entity id 120 at ([minecraft:world]914.2786857948084, -56.0, -1563.3453830706321)
>....[09:17:29 INFO]: dwollismm lost connection: Internal Exception: io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:game_event'
>....[09:17:29 INFO]: [voicechat] Disconnecting client dwollismm
>....[09:17:29 INFO]: System chat: ♛ KILLS #1 dwollismm left the game
>....[09:17:38 INFO]: UUID of player xinal69 is c293c643-2992-30db-80c9-95ce4834c63b
>....[09:17:39 INFO]: System chat: xinal69 joined the game
>....[09:17:39 INFO]: xinal69[/49.244.224.104:22855] logged in with entity id 158 at ([minecraft:world]915.0882699685133, -56.0, -1564.9705977788183)
>....[09:17:39 ERROR]: Error sending packet clientbound/minecraft:game_event
io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:game_event'
	at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:63) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:13) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:27) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:12) ~[paper-26.3.jar:26.3-140-977da0d]
	at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ~[netty-codec-base-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:113) ~[netty-codec-base-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:120) ~[netty-codec-base-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.ChannelOutboundHandlerAdapter.write(ChannelOutboundHandlerAdapter.java:113) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at net.minecraft.network.Connection$2.write(Connection.java:737) ~[paper-26.3.jar:26.3-140-977da0d]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:800) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:737) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.DefaultChannelPipeline.write(DefaultChannelPipeline.java:1036) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.Channel.write(Channel.java:267) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at ProtocolLib.jar//com.comphenix.protocol.injector.netty.channel.NettyChannelProxy.write(NettyChannelProxy.java:210) ~[?:?]
	at net.minecraft.network.Connection.doSendPacket(Connection.java:521) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.Connection.lambda$sendPacket$0(Connection.java:501) ~[paper-26.3.jar:26.3-140-977da0d]
	at ProtocolLib.jar//com.comphenix.protocol.injector.netty.channel.NettyEventLoopProxy.lambda$proxyRunnable$2(NettyEventLoopProxy.java:49) ~[?:?]
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:148) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:141) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:535) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.channel.SingleThreadIoEventLoop.run(SingleThreadIoEventLoop.java:201) ~[netty-transport-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:1204) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.2.16.Final.jar:4.2.16.Final]
	at java.base/java.lang.Thread.run(Thread.java:1474) ~[?:?]
Caused by: java.lang.NullPointerException: Cannot read field "id" because "this.event" is null
	at net.minecraft.network.protocol.game.ClientboundGameEventPacket.write(ClientboundGameEventPacket.java:47) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.StreamCodec$2.encode(StreamCodec.java:46) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.StreamCodec$5.encode(StreamCodec.java:96) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.StreamCodec$5.encode(StreamCodec.java:86) ~[paper-26.3.jar:26.3-140-977da0d]
	at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:58) ~[paper-26.3.jar:26.3-140-977da0d]
	... 29 more
>....[09:17:39 INFO]: xinal69 lost connection: Internal Exception: io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:game_event'
>....[09:17:39 INFO]: [voicechat] Disconnecting client xinal69
>....[09:17:40 INFO]: System chat: [DEV] xinal69 left the game
Kodari AI
KodariOct 8 at 9:20 am 1

The generation was stopped before any content could be produced.

MrBynoz

fix that the why i couldn't login into that ??

Kodari AI
KodariOct 8 at 9:23 am 1

The login check itself looks correct. The likely blocker is ProtocolLib: plugin.yml declares it as a required dependency, so if it isn’t installed, CoordinateLogin won’t start and /login won’t be available.

Install a server-compatible ProtocolLib version and restart the server. If ProtocolLib is already installed and the plugin starts, tell me the exact message you see when you run /login—for example, “Incorrect password” or “Unknown command”—so I can pinpoint the next cause.

MrBynoz

i couldn't login

1 image attached
Kodari AI
KodariOct 8 at 9:29 am 1
  • Trace the login packet handling in CoordinateLoginPlugin.

  • Fix the packet encoding failure shown in the disconnect screen.

The disconnect happens before /login: the plugin sends a reduced-debug packet when you join, and the project targets Minecraft 1.21.4 while depending on ProtocolLib 5.3.0, which doesn’t support that version. I updated the ProtocolLib dependency to 5.4.0, which supports 1.21.4.

Because ProtocolLib is a server-side dependency, update the ProtocolLib installed on your server to 5.4.0 or newer and restart it before trying again.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
3 212
src/main/java/com/kodari/coordinatelogin/CoordinateLoginPlugin.java
package com.kodari.coordinatelogin;

import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.Base64;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class CoordinateLoginPlugin extends JavaPlugin implements Listener, CommandExecutor {
    private static final int SALT_LENGTH = 16;
    private static final int HASH_LENGTH_BITS = 256;
    private static final int HASH_ITERATIONS = 120_000;
    private static final int MIN_PASSWORD_LENGTH = 6;

    private final SecureRandom secureRandom = new SecureRandom();
    private final Set<UUID> authenticatedPlayers = new HashSet<>();

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("login").setExecutor(this);
        getCommand("register").setExecutor(this);
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        sendReducedDebugInfoPacket(player, true);

        if (hasAccount(player.getUniqueId())) {
            player.sendMessage("Please log in with /login <password> to reveal F3 coordinates.");
        } else {
            player.sendMessage("Create an account with /register <password> <password> to reveal F3 coordinates.");
        }
    }

    @EventHandler
    public void onPlayerQuit(PlayerQuitEvent event) {
        authenticatedPlayers.remove(event.getPlayer().getUniqueId());
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage("Only players can use this command.");
            return true;
        }

        return switch (command.getName().toLowerCase(Locale.ROOT)) {
            case "login" -> handleLogin(player, args);
            case "register" -> handleRegister(player, args);
            default -> false;
        };
    }

    private boolean handleLogin(Player player, String[] args) {
        if (args.length != 1) {
            player.sendMessage("Usage: /login <password>");
            return true;
        }
        if (authenticatedPlayers.contains(player.getUniqueId())) {
            player.sendMessage("You are already logged in.");
            return true;
        }
        if (!hasAccount(player.getUniqueId())) {
            player.sendMessage("You do not have an account yet. Use /register <password> <password>.");
            return true;
        }

        try {
            if (!passwordMatches(player.getUniqueId(), args[0])) {
                player.sendMessage("Incorrect password.");
                return true;
            }
            authenticate(player);
        } catch (GeneralSecurityException exception) {
            getLogger().severe("Could not verify a player password: " + exception.getMessage());
            player.sendMessage("Login could not be completed. Please contact an administrator.");
        }
        return true;
    }

    private boolean handleRegister(Player player, String[] args) {
        if (args.length != 2) {
            player.sendMessage("Usage: /register <password> <password>");
            return true;
        }
        if (hasAccount(player.getUniqueId())) {
            player.sendMessage("You already have an account. Use /login <password>.");
            return true;
        }
        if (args[0].length() < MIN_PASSWORD_LENGTH) {
            player.sendMessage("Your password must be at least " + MIN_PASSWORD_LENGTH + " characters long.");
            return true;
        }
        if (!args[0].equals(args[1])) {
            player.sendMessage("Those passwords do not match.");
            return true;
        }

        try {
            byte[] salt = new byte[SALT_LENGTH];
            secureRandom.nextBytes(salt);
            String accountPath = accountPath(player.getUniqueId());
            getConfig().set(accountPath + ".salt", Base64.getEncoder().encodeToString(salt));
            getConfig().set(accountPath + ".hash", Base64.getEncoder().encodeToString(hashPassword(args[0], salt)));
            saveConfig();
            authenticate(player);
        } catch (GeneralSecurityException exception) {
            getLogger().severe("Could not save a player password: " + exception.getMessage());
            player.sendMessage("Registration could not be completed. Please contact an administrator.");
        }
        return true;
    }

    private void authenticate(Player player) {
        authenticatedPlayers.add(player.getUniqueId());
        sendReducedDebugInfoPacket(player, false);
        player.sendMessage("You are now logged in. F3 coordinates are visible.");
    }

    private void sendReducedDebugInfoPacket(Player player, boolean reduced) {
        PacketContainer packet = ProtocolLibrary.getProtocolManager()
                .createPacket(PacketType.Play.Server.GAME_STATE_CHANGE);
        packet.getGameStateIDs().write(0, 22);
        packet.getFloat().write(0, reduced ? 1.0f : 0.0f);
        ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
    }

    private boolean hasAccount(UUID playerId) {
        return getConfig().contains(accountPath(playerId) + ".salt")
                && getConfig().contains(accountPath(playerId) + ".hash");
    }

    private boolean passwordMatches(UUID playerId, String password) throws GeneralSecurityException {
        String accountPath = accountPath(playerId);
        byte[] salt = Base64.getDecoder().decode(getConfig().getString(accountPath + ".salt", ""));
        byte[] expectedHash = Base64.getDecoder().decode(getConfig().getString(accountPath + ".hash", ""));
        return MessageDigest.isEqual(expectedHash, hashPassword(password, salt));
    }

    private byte[] hashPassword(String password, byte[] salt) throws GeneralSecurityException {
        PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, HASH_ITERATIONS, HASH_LENGTH_BITS);
        try {
            return SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(keySpec).getEncoded();
        } finally {
            keySpec.clearPassword();
        }
    }

    private String accountPath(UUID playerId) {
        return "accounts." + playerId;
    }
}