rkh3ss

BetterLocks is a lightweight Paper plugin for Minecraft 1.21.x that allows players to protect their blocks by locking them. Players can lock furnaces of any type, including blast furnaces and smokers, as well as campfires, chests, shulker boxes, and all types of signs. To lock a block, players simply crouch and press L, and to unlock it, they crouch and press Z. Locked blocks can only be accessed by their owner, helping prevent griefing and theft while remaining fully survival-friendly. BetterLocks is designed to be simple, efficient, and optimized for Paper servers.

Kodari AI
KodariJan 18 at 2:52 pm 6,163 (v2)

I’ll create a lightweight block protection plugin for Paper 1.21.x with keybind-based locking.

BetterLocks
A lightweight Paper plugin that allows players to protect blocks by locking them. Players can lock furnaces, campfires, chests, shulker boxes, and signs by crouching and pressing L, and unlock with crouch + Z. Locked blocks are accessible only by their owner, preventing griefing and theft in a survival-friendly way. Optimized for Paper 1.21.x servers.

BetterLocks plugin created! The plugin uses the F key (swap hands) as a substitute for custom keybinds since Bukkit/Paper doesn’t natively support custom key detection. Players crouch + press F to toggle locks on blocks they’re looking at. All lockable blocks are configurable, locks persist across restarts, and only owners can access/break their locked blocks.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
10 431
src/main/java/com/betterlocks/BetterLocks.java
package com.betterlocks;

import com.betterlocks.listeners.BlockInteractListener;
import com.betterlocks.listeners.BlockBreakListener;
import com.betterlocks.listeners.KeyPressListener;
import com.betterlocks.storage.LockStorage;
import com.betterlocks.util.MessageUtil;
import org.bukkit.plugin.java.JavaPlugin;

public class BetterLocks extends JavaPlugin {
    private LockStorage lockStorage;
    private MessageUtil messageUtil;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        
        this.lockStorage = new LockStorage(this);
        this.messageUtil = new MessageUtil(this);
        
        getServer().getPluginManager().registerEvents(new KeyPressListener(this), this);
        getServer().getPluginManager().registerEvents(new BlockInteractListener(this), this);
        getServer().getPluginManager().registerEvents(new BlockBreakListener(this), this);
        
        getLogger().info("BetterLocks has been enabled!");
    }

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

    public LockStorage getLockStorage() {
        return lockStorage;
    }

    public MessageUtil getMessageUtil() {
        return messageUtil;
    }
}