Skip to content

Andromedov/JsonExpansion

Repository files navigation

🧩 JSON Expansion

A custom PlaceholderAPI expansion for reading JSON files.

Java Gradle PlaceholderAPI


✨ Features

  • 📂 Local File Loading Automatically scans and reads .json files from the plugins/PlaceholderAPI/json/ directory.
  • ⚡ Smart Caching & Hot-Reload Caches JSON content in RAM for instant access. Automatically detects file changes on disk and reloads only when necessary. Zero performance impact.
  • 🔍 Deep Nesting Support Full support for dot notation to access nested keys (e.g., messages.welcome.text).
  • 🧠 Intelligent Matching Correctly distinguishes between similar filenames (e.g., shop.json vs shop_items.json).

🛠️ Prerequisites

To build this project, you need:

  • JDK 21 or higher.
  • Gradle (optional, wrapper is included).

🚀 Installation & Build

1. Build the JAR

Open your terminal in the project directory and run:

Windows (PowerShell/CMD):

.\gradlew build

Linux/macOS:

./gradlew build

The compiled file will be located at: build/libs/LocalJsonExpansion-1.x.x.jar

2. Install on Server

  1. Stop your Minecraft server.
  2. Navigate to plugins/PlaceholderAPI/expansions/.
  3. Drop the JsonExpansion-1.x.x.jar file there.
  4. Start the server.

📖 Usage Guide

1. File Placement

The expansion looks for files in a specific folder. You must create it if it doesn't exist:

plugins/PlaceholderAPI/json/

2. Placeholder Syntax

The pattern is:

%json_<filename>_<path_to_key>%
Parameter Description
<filename> The name of the file.
<path_to_key> The key inside the JSON. Use dots . for nested objects.

3. Examples

Scenario A: Simple Key

File: plugins/PlaceholderAPI/json/holidays.json

{
  "first": "New Year",
  "second": "Christmas"
}

Placeholders:

  • %json_holidays_first% → Returns: New Year
  • %json_holidays_second% → Returns: Christmas

Scenario B: Nested Objects

File: plugins/PlaceholderAPI/json/server.json

{
  "status": "online",
  "motd": {
    "line1": "Welcome to Paradise!",
    "maintenance": false
  }
}

Placeholders:

  • %json_server_status% → Returns: online
  • %json_server_motd.line1% → Returns: Welcome to Paradise!

🔧 Troubleshooting

❌ Placeholder returns File not found
  • Ensure the file exists in plugins/PlaceholderAPI/json/.
  • Check if the filename in the placeholder matches the actual filename (case-insensitive, but exact spelling required).
  • Do not include .json in the placeholder macro.
❌ Placeholder returns Invalid JSON
  • The file exists but contains syntax errors.
  • Validate your JSON content using a site like jsonlint.com.
❌ Placeholder returns ...
  • The file was found, but the specific key does not exist.
  • Check for typos in the path (e.g., motd.line1 vs motd.line_1).

About

Json Expansion for PlaceholderAPI

Resources

License

Stars

Watchers

Forks

Contributors

Languages