kohinoor1397
📎 1 file 1,292 chars
📄
pasted-code-1772887329283.txt
txt 39 lines
â–¶
Create a Minecraft plugin for Paper 1.21.1 (Java) that restricts each player account to a single registered IP address.

Plugin Requirements:

1. When a player joins the server for the first time, their IP address is automatically registered and saved in a configuration file or database linked to their UUID.

2. After the first registration:
   - The player can only join the server from that same IP address.
   - If they try to join from a different IP, they must be kicked with the message:
     "This account is locked to a different IP address."

3. Admin Commands:
   - /ipreset 
     - Clears the saved IP for that player so they can re-register with a new IP.
   - /ipcheck 
     - Shows the registered IP for that player.

4. Permissions:
   - iplock.reset
   - iplock.check

5. Storage:
   - Save player UUID and IP in a YAML file called players.yml.

6. The plugin must:
   - Work on Paper 1.21.1
   - Use PlayerLoginEvent or AsyncPlayerPreLoginEvent
   - Be lightweight and efficient
   - Automatically create the config file if missing.

7. Project Structure:
   - Main plugin class
   - Listener for login events
   - Command handlers
   - players.yml storage system

8. Include:
   - plugin.yml
   - Full Java source code
Kodari AI
KodariMar 7 at 12:42 pm 7,250 (v2)

I’ll create a lightweight IP lock plugin for Paper 1.21.1 that restricts players to a single IP address.

IPLockPlugin
A security plugin that restricts each player account to a single registered IP address. When a player first joins, their IP is automatically registered and saved. Future logins are only allowed from that IP address. Includes admin commands to reset or check registered IPs, with YAML-based storage for efficient data persistence.

Plan

  • Main plugin class with IPDataManager

  • IPDataManager for YAML storage (players.yml)

  • PlayerLoginListener using AsyncPlayerPreLoginEvent for efficiency

  • IPCommand handling both /ipreset and /ipcheck

  • plugin.yml with commands and permissions

Plugin created successfully!

Features:

  • Automatically registers player IP on first join

  • Blocks login attempts from different IPs with custom kick message

  • YAML storage in players.yml (auto-creates if missing)

  • /ipreset <player> - Clear registered IP (permission: iplock.reset)

  • /ipcheck <player> - View registered IP (permission: iplock.check)

  • Uses AsyncPlayerPreLoginEvent for optimal performance

  • Logs all registration, blocking, and admin actions

The plugin is lightweight, efficient, and ready for Paper 1.21.1 with Lombok for cleaner code.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
7 271
src/main/java/com/iplockplugin/IPLockPlugin.java
package com.iplockplugin;

import com.iplockplugin.commands.IPCommand;
import com.iplockplugin.listeners.PlayerLoginListener;
import com.iplockplugin.managers.IPDataManager;
import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class IPLockPlugin extends JavaPlugin {
    private IPDataManager dataManager;

    @Override
    public void onEnable() {
        this.dataManager = new IPDataManager(this);
        this.dataManager.load();

        getServer().getPluginManager().registerEvents(new PlayerLoginListener(this), this);
        
        IPCommand ipCommand = new IPCommand(this);
        getCommand("ipreset").setExecutor(ipCommand);
        getCommand("ipcheck").setExecutor(ipCommand);

        getLogger().info("IPLockPlugin has been enabled!");
    }

    @Override
    public void onDisable() {
        if (this.dataManager != null) {
            this.dataManager.save();
        }
        getLogger().info("IPLockPlugin has been disabled!");
    }
}