Skip to content

MCEngine/mcbackpack

Repository files navigation

MCBackpack

MCBackpack is a robust, database-driven backpack plugin for Minecraft servers (Spigot/Paper). It features secure password protection, support for both MySQL and SQLite, and a unique "Creation Item" workflow that allows administrators to distribute backpack tokens that players initialize themselves.

🌟 Key Features

  • Database Storage: Supports SQLite (default, local file) and MySQL (for cross-server sync capability).
  • Secure Locking: Backpacks can be locked with a password.
    • Uses Salted SHA-256 Hashing for security.
    • Unlocking is done via a secure chat prompt (messages are hidden from public chat).
  • Creation Workflow: Admins spawn "Creation Items" (uninitialized heads). When a player right-clicks one, it generates a unique UUID and registers it in the database.
  • Custom Textures: Support for custom Base64 skull textures for backpack items.
  • Recursive Prevention: Prevents players from putting backpacks inside other backpacks.
  • Async I/O: All database operations are performed asynchronously to prevent server lag.

🚀 Installation

  1. Download the plugin .jar file.
  2. Place it in your server's plugins folder.
  3. Restart the server to generate the configuration file.
  4. (Optional) Edit config.yml to switch from SQLite to MySQL.

Configuration (config.yml)

db:
  # Connection type: 'sqlite' (local file) or 'mysql' (external database)
  type: sqlite

  # Settings for local SQLite database
  sqlite:
    # The name of the database file inside the plugin folder
    path: mcbackpack.db
  
  # Settings for external MySQL/MariaDB database
  mysql:
    host: localhost
    port: "3306"
    database: mcbackpack
    user: root
    password: mcbackpack
    ssl: "false"

🛠️ Usage Guide

1. Creating a Backpack

Unlike standard plugins where a command opens a virtual inventory immediately, MCBackpack gives you a physical item.

  1. Get a Creation Item: Run the command to get a "Backpack Creation" head. You can specify the size (multiples of 9) and an optional custom texture.

    • /backpack create 27
    • /backpack create 27 <"head texture base64">
  2. Initialize: Right-click the "Backpack Creation" item while holding it.

    • The item will be registered in the database with a unique UUID.
    • The item name changes to "Backpack (Size: 27)".
    • It is now ready for storage.

2. Protecting Your Backpack

You can lock your backpack so others cannot open it even if they steal the item.

  1. Set a Password: Hold the initialized backpack and run:
    • /backpack setpwd <your_password>
  2. Unlocking: When you (or anyone else) tries to open a locked backpack:
    • The inventory will not open.
    • You will receive a chat prompt: "Please type the password in chat to unlock."
    • Type the password in chat. Your message will not be seen by other players.
    • If correct, the backpack opens.
Command Arguments Permission Description
/bp create <size> [texture] mcbackpack.create "Gives you a Backpack Creation item. Size must be 9, 18, 27, 36, 45, or 54."
/bp setpwd <password> mcbackpack.setpwd Sets a password for the backpack currently held in your main hand.
/bp changepwd <old> <new> mcbackpack.changepwd Changes the password. Requires knowing the old password.
/bp deletepwd <password> mcbackpack.deletepwd Removes the password protection from the held backpack.
/bp help None None Displays the help menu.

Note: /bp is an alias for /backpack.

🔒 Security Details

  • Encryption: Passwords are never stored in plain text. We use a random Salt + SHA-256 hash strategy (salt$hash). This ensures that even if two players use the same password ("123456"), their stored database entries will look completely different.
  • Chat Interception: The plugin listens for chat packets at the lowest priority during the unlocking phase and cancels the event, ensuring the password never appears in the server log or chat box.

🚫 Restrictions

Recursive Storage: You cannot place a backpack inside another backpack. The plugin listens to InventoryClickEvent and InventoryDragEvent to block these actions specifically within the backpack GUI.