bipnix_fr

I want to create a login security plugin with the following features:

  • When a player joins the server for the first time, the plugin should ask them to register in the chat.
  • Once a player registers, they should not have to log in again every time they join the server.
  • The plugin should remember the player's authenticated session.
  • If someone tries to join using the same player account while it is already online, they should be blocked with the message: "This player is already online."
  • The system should prevent duplicate logins and unauthorized access to an active session.
Kodari AI
KodariAug 15 at 3:32 pm 1
SessionGuard
A login security plugin that manages player authentication sessions. When a player joins for the first time, it prompts them to register via chat. Registered players are remembered and automatically authenticated on subsequent joins. The plugin prevents duplicate logins by blocking connection attempts when the same player account is already online, displaying "This player is already online." It maintains session persistence through configuration storage and enforces single-session access to prevent unauthorized entry into active game sessions.
  1. Create the Gradle/plugin metadata and default configuration.

  2. Implement persistent PBKDF2-backed registration and active-session tracking.

  3. Add join, chat-registration, duplicate-login, and unauthenticated-action listeners.

Created the LoginSecurity plugin from scratch.

  • First-time players are prompted to register by entering a password in chat.

  • Passwords are stored using PBKDF2 hashing with a random salt.

  • Registered players are automatically authenticated on future joins.

  • Active sessions are tracked by UUID and username.

  • Duplicate online logins are blocked with: This player is already online.

  • Unregistered players cannot move, use commands, interact, break/place blocks, access inventories, drop/pick up items, or attack players until registration is complete.

  • Added Gradle build files, plugin.yml, and configurable messages.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
7 394
src/main/java/com/kodari/loginsecurity/LoginSecurityPlugin.java
package com.kodari.loginsecurity;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;

public class LoginSecurityPlugin extends JavaPlugin {
    private AuthManager authManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        this.authManager = new AuthManager(this);
        Bukkit.getPluginManager().registerEvents(new SecurityListener(this, authManager), this);
    }

    public AuthManager getAuthManager() {
        return authManager;
    }

    public String message(String key, String fallback) {
        String value = getConfig().getString("messages." + key, fallback);
        return ChatColor.translateAlternateColorCodes('&', value);
    }

    public int getMinimumPasswordLength() {
        return Math.max(1, getConfig().getInt("minimum-password-length", 6));
    }
}