Ege
📎 1 file 4,792 chars
📄
pasted-code-1791109410044.txt
txt 215 lines
▶
Create a complete Minecraft Java plugin for a /register and /login authentication system.

Requirements:

Target Minecraft version: 1.21.x

Use Java 21.

Use the Paper API.

Use Maven for dependency management.

Plugin name: SecureAuth

Provide the complete project structure and all source files.

Include a properly configured plugin.yml.

Authentication Commands

Implement:

/register  

/login 

/changepassword  

/logout

Behavior:

When a player joins for the first time, check whether they have an account.

If they are not registered, prevent normal gameplay and tell them to use /register  .

If they are registered, prevent normal gameplay and tell them to use /login .

Players must not be able to move, chat, interact, attack, drop items, pick up items, open inventories, or use commands while unauthenticated, except for authentication-related commands.

After successful authentication, restore normal player functionality.

If a player enters an incorrect password, show an error message.

Add a configurable maximum number of login attempts.

If the maximum number of failed attempts is reached, automatically kick the player.

Add an optional authentication timeout. If the player does not authenticate within the configured time, kick them.

Security

NEVER store passwords as plain text.

Hash passwords securely using BCrypt or Argon2.

Store a unique salt automatically as part of the password hashing system.

Never log player passwords to the console.

Protect against basic brute-force login attempts.

Validate password length and configurable password requirements.

Make sure passwords cannot be accidentally exposed through commands or logs.

Use UUIDs instead of player names as the primary player identifier.

Database

Support SQLite by default.

Store:

UUID

Player name

Password hash

Registration timestamp

Last login timestamp

Create the database automatically when the plugin starts.

Use asynchronous database operations where appropriate so the main server thread is not blocked.

Configuration

Create a configurable config.yml containing options such as:

Maximum password length

Minimum password length

Maximum login attempts

Authentication timeout

Database settings

Messages

Whether unauthenticated players can move

Whether unauthenticated players can chat

Whether unauthenticated players can interact

Session settings

All messages must be configurable and support Minecraft color codes.

Sessions

Implement an optional session system.

If enabled:

A player who reconnects from the same IP within a configurable period can optionally be automatically authenticated.

Make this feature configurable and disabled by default for better security.

Permissions

Add permissions:

secureauth.admin

secureauth.bypass

secureauth.bypass should allow trusted players to bypass authentication restrictions.

Admin Commands

Implement:

/auth reload

/auth unregister 

/auth resetpassword  

/auth info 

Only players with secureauth.admin can use administrative commands.

Events

Properly handle:

PlayerJoinEvent

PlayerQuitEvent

PlayerMoveEvent

AsyncPlayerChatEvent

PlayerInteractEvent

InventoryClickEvent

PlayerDropItemEvent

EntityDamageEvent

PlayerCommandPreprocessEvent

Make sure unauthenticated players cannot bypass the authentication system through alternative interactions or commands.

Code Quality

Use clean, modular, object-oriented Java.

Separate command handlers, authentication logic, database logic, listeners, configuration, and utilities into appropriate classes.

Avoid putting everything into one class.

Use dependency injection where it makes sense.

Add comments explaining security-critical code.

Handle exceptions properly.

Do not use deprecated Bukkit/Paper APIs if a modern alternative exists.

Ensure the plugin is thread-safe when asynchronous database operations are used.

Deliverables

Give me:

Complete folder/project structure.

pom.xml.

plugin.yml.

config.yml.

Every Java source file required.

Database initialization code.

Complete command implementations.

Complete event listeners.

Installation/build instructions.

A short explanation of how the authentication flow works.

The final result must be a production-ready, compilable Minecraft Paper plugin. Do not provide pseudocode or incomplete sections. Make sure all imports, package names, dependencies, commands, permissions, and configuration paths are consistent across the entire project.
Kodari AI
KodariOct 4 at 10:31 am 2
SecureAuth
SecureAuth is a comprehensive authentication plugin for Paper 1.21.x servers providing registration, login, and session management. It features BCrypt password hashing, SQLite storage with async operations, configurable security policies including login attempt limits and timeouts, and full gameplay restriction for unauthenticated players. The plugin includes admin commands for user management, configurable messages with color code support, and permission-based bypass options. It prevents movement, chat, interaction, and command usage until authentication, with optional IP-based session persistence for reconnecting players.
  1. Set up the Maven/Paper 1.21 project, plugin metadata, and configurable defaults.

  2. Add SQLite persistence, BCrypt password handling, authentication/session state, and password policy.

  3. Implement player/admin commands and listeners that enforce unauthenticated restrictions.

Created SecureAuth with Maven, Paper 1.21.x, Java 21, SQLite, and salted BCrypt password hashes. Database work and password hashing run asynchronously.

Project structure

Plain Text
pom.xml
manifest.kod
src/main/resources/
  plugin.yml
  config.yml
src/main/java/com/kodari/secureauth/
  SecureAuth.java
  auth/
    AccountInfo.java
    AccountRecord.java
    AuthManager.java
    AuthService.java
    Messages.java
    PasswordPolicy.java
  command/
    AuthAdminCommand.java
    ChangePasswordCommand.java
    LoginCommand.java
    LogoutCommand.java
    RegisterCommand.java
  listener/
    AuthListener.java
  storage/
    AuthDatabase.java

Authentication flow: On join, players are restricted while SecureAuth checks their UUID-based account in SQLite. New players register; existing players log in. Successful authentication lifts the restrictions. Login attempts, timeout, password rules, messages, and optional same-IP sessions are configurable. Sessions are disabled by default.

To get the jar, click Compile in the top bar (on phone: ⋮ → Compile Project), then click Compile and Download. Place SecureAuth.jar in the Paper server’s plugins folder and restart it. The SQLite database is created in the plugin’s data folder.

Kodari can make mistakes. Review important code before using.
Files
src
manifest.kod
pom.xml
Code
18 1,297
src/main/java/com/kodari/secureauth/SecureAuth.java
package com.kodari.secureauth;

import com.kodari.secureauth.auth.AuthManager;
import com.kodari.secureauth.auth.AuthService;
import com.kodari.secureauth.auth.PasswordPolicy;
import com.kodari.secureauth.command.AuthAdminCommand;
import com.kodari.secureauth.command.ChangePasswordCommand;
import com.kodari.secureauth.command.LoginCommand;
import com.kodari.secureauth.command.LogoutCommand;
import com.kodari.secureauth.command.RegisterCommand;
import com.kodari.secureauth.listener.AuthListener;
import com.kodari.secureauth.storage.AuthDatabase;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

public final class SecureAuth extends JavaPlugin {
    private AuthService authService;
    private AuthManager authManager;
    private PasswordPolicy passwordPolicy;

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

        try {
            AuthDatabase database = new AuthDatabase(this);
            database.initialize();
            authService = new AuthService(database);
        } catch (IOException | java.sql.SQLException exception) {
            getLogger().log(Level.SEVERE, "Could not initialize the authentication database.", exception);
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }

        authManager = new AuthManager(this);
        passwordPolicy = new PasswordPolicy(this);
        Bukkit.getPluginManager().registerEvents(new AuthListener(this), this);
        registerCommands();
    }

    @Override
    public void onDisable() {
        if (authService != null) {
            try {
                authService.shutdown();
            } catch (InterruptedException exception) {
                Thread.currentThread().interrupt();
                getLogger().log(Level.WARNING, "Interrupted while closing the authentication database.", exception);
            }
        }
    }

    private void registerCommands() {
        setExecutor("register", new RegisterCommand(this));
        setExecutor("login", new LoginCommand(this));
        setExecutor("changepassword", new ChangePasswordCommand(this));
        setExecutor("logout", new LogoutCommand(this));
        setExecutor("auth", new AuthAdminCommand(this));
    }

    private void setExecutor(String commandName, org.bukkit.command.CommandExecutor executor) {
        PluginCommand command = getCommand(commandName);
        if (command != null) {
            command.setExecutor(executor);
        }
    }

    public AuthService getAuthService() {
        return authService;
    }

    public AuthManager getAuthManager() {
        return authManager;
    }

    public PasswordPolicy getPasswordPolicy() {
        return passwordPolicy;
    }

    public void logDatabaseError(Throwable exception) {
        getLogger().log(Level.SEVERE, "An authentication database operation failed.", exception);
    }
}