Back

FINAL_README.md

markdown
FINAL_README.md
# FrameworkPlugin - Production-Grade Modular Framework

## ๐ŸŽฏ Overview

FrameworkPlugin is a **production-ready**, **framework-level** plugin system for Minecraft Paper 1.21.8. It's not just a pluginโ€”it's a **mini game engine** inside Minecraft.

### Key Features

โœ… **Modular Architecture** - Clean Architecture with SOLID principles  
โœ… **Dependency Injection** - Lightweight custom DI container  
โœ… **JavaScript Support** - GraalVM with ECMAScript 2022  
โœ… **Custom Event Bus** - Cross-module communication  
โœ… **Item System** - Custom items with abilities and NBT  
โœ… **Task Scheduler** - CompletableFuture-based async operations  
โœ… **Hot Reload** - Reload modules and scripts without restart  
โœ… **Thread-Safe** - Concurrent collections and atomic operations  
โœ… **Zero Hardcoded Logic** - Everything configurable or scriptable  

## ๐Ÿ“ Project Structure

```
FrameworkPlugin/
โ”œโ”€โ”€ src/main/java/com/myplugin/
โ”‚   โ”œโ”€โ”€ FrameworkPlugin.java           # Main plugin class
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ api/                            # Public interfaces (API layer)
โ”‚   โ”‚   โ”œโ”€โ”€ module/                     # Module system API
โ”‚   โ”‚   โ”œโ”€โ”€ item/                       # Item system API
โ”‚   โ”‚   โ”œโ”€โ”€ event/                      # Event bus API
โ”‚   โ”‚   โ”œโ”€โ”€ scheduler/                  # Scheduler API
โ”‚   โ”‚   โ”œโ”€โ”€ script/                     # Script engine API
โ”‚   โ”‚   โ””โ”€โ”€ storage/                    # Storage API
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ core/                           # Implementation layer
โ”‚   โ”‚   โ”œโ”€โ”€ di/                         # Dependency injection
โ”‚   โ”‚   โ”œโ”€โ”€ module/                     # Module management
โ”‚   โ”‚   โ”œโ”€โ”€ item/                       # Item management
โ”‚   โ”‚   โ”œโ”€โ”€ event/                      # Event bus implementation
โ”‚   โ”‚   โ”œโ”€โ”€ scheduler/                  # Task scheduler
โ”‚   โ”‚   โ””โ”€โ”€ script/                     # GraalVM script engine
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ modules/                        # Built-in modules
โ”‚       โ””โ”€โ”€ demo/                       # Demo module
โ”‚           โ””โ”€โ”€ DemoModule.java
โ”‚
โ”œโ”€โ”€ src/main/resources/
โ”‚   โ”œโ”€โ”€ plugin.yml
โ”‚   โ”œโ”€โ”€ config.yml
โ”‚   โ”œโ”€โ”€ messages.yml
โ”‚   โ””โ”€โ”€ modules/demo/module.yml
โ”‚
โ”œโ”€โ”€ scripts/examples/                   # JavaScript examples
โ”‚   โ”œโ”€โ”€ custom_item_example.js
โ”‚   โ”œโ”€โ”€ scheduler_example.js
โ”‚   โ””โ”€โ”€ simple_command.js
โ”‚
โ”œโ”€โ”€ README.md                           # This file
โ”œโ”€โ”€ ARCHITECTURE.md                     # Architecture documentation
โ”œโ”€โ”€ BUILD.md                            # Build instructions
โ”œโ”€โ”€ INSTALL.md                          # Installation guide
โ””โ”€โ”€ pom.xml                             # Maven configuration
```

## ๐Ÿš€ Quick Start

### Prerequisites

- **Java 21+** (required for GraalVM)
- **Maven 3.8+**
- **Paper 1.21.8+**

### Build

```bash
mvn clean package
```

### Install

```bash
cp target/FrameworkPlugin-1.0.0.jar /path/to/server/plugins/
```

### Run

Start your Paper server. The plugin will:
1. Initialize DI container
2. Load core services
3. Load modules (demo module included)
4. Load JavaScript scripts

## ๐Ÿ“š Documentation

- **[ARCHITECTURE.md](ARCHITECTURE.md)** - Detailed architecture documentation
- **[BUILD.md](BUILD.md)** - Build and development guide
- **[INSTALL.md](INSTALL.md)** - Installation instructions
- **[PROJECT_STRUCTURE.md](PROJECT_STRUCTURE.md)** - Project organization

## ๐ŸŽฎ Demo Module

The included demo module showcases framework capabilities:

### Magic Wand Item
- Right-click to teleport forward 5 blocks
- Particle effects and sounds
- Cooldown system
- Given to new players automatically

### /fly Command
- Toggle flight mode
- Sound feedback
- Permission-based

### Welcome Message
- Customizable via config
- Sent on player join

## ๐Ÿ’ป JavaScript API

### Example: Custom Item

```javascript
// Register a fire sword
API.registerItem(
    "fire_sword",
    "DIAMOND_SWORD",
    "&c&lFire Sword",
    "&7Sets enemies on fire",
    "&6Epic Item"
);

// Give to player
var player = API.getPlayer("PlayerName");
API.giveItem(player, "fire_sword", 1);
```

### Example: Scheduler

```javascript
// Run after 5 seconds
API.runLater(function() {
    API.broadcast("&aHello World!");
}, 100); // 100 ticks = 5 seconds

// Repeating task
API.runTimer(function() {
    console.log("This runs every 30 seconds");
}, 600, 600);
```

### Example: Player Management

```javascript
// Get online players
var players = API.getOnlinePlayers();

// Send message
players.forEach(function(player) {
    API.sendMessage(player, "&6Welcome!");
});

// Broadcast
API.broadcast("&aServer announcement!");
```

## ๐Ÿ—๏ธ Creating Modules

### 1. Create module.yml

```yaml
id: mymodule
name: My Module
version: 1.0.0
description: My custom module
authors: [YourName]
dependencies: []
soft-dependencies: []
load-order: STARTUP
enabled: true
```

### 2. Create Module Class

```java
package com.myplugin.modules.mymodule;

import com.myplugin.api.module.ModuleDescriptor;
import com.myplugin.core.module.BaseModule;

import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;

public class MyModule extends BaseModule {
    
    public MyModule(ModuleDescriptor descriptor, Path dataFolder) {
        super(descriptor, dataFolder);
    }
    
    @Override
    public CompletableFuture<Void> onEnable() {
        return super.onEnable().thenRun(() -> {
            log("My module enabled!");
            // Your initialization code
        });
    }
    
    @Override
    public CompletableFuture<Void> onDisable() {
        return super.onDisable().thenRun(() -> {
            log("My module disabled!");
            // Cleanup code
        });
    }
}
```

### 3. Place in modules/ folder

```
plugins/FrameworkPlugin/modules/mymodule/
โ”œโ”€โ”€ module.yml
โ””โ”€โ”€ config.yml
```

## ๐Ÿ”ง Configuration

### Main Config (config.yml)

```yaml
settings:
  debug: false
  language: en

modules:
  auto-load: true
  
scripting:
  enabled: true
  sandbox: true
  timeout: 5000

performance:
  async-loading: true
  cache-enabled: true
```

## ๐ŸŽฏ Architecture Highlights

### Dependency Injection

```java
Container container = Container.getInstance();
container.registerSingleton(EventBus.class, new EventBusImpl());

EventBus eventBus = container.resolve(EventBus.class).orElseThrow();
```

### Event Bus

```java
eventBus.subscribe(MyEvent.class, event -> {
    // Handle event
}, EventBus.EventPriority.NORMAL);

eventBus.post(new MyEvent()).join();
```

### Module System

- **Dependency Resolution**: Topological sorting
- **Load Order**: STARTUP โ†’ POSTWORLD โ†’ LAZY
- **Hot Reload**: Reload without restart
- **Isolation**: Each module has isolated state

### Script Engine

- **Sandboxed**: No file I/O, restricted class access
- **Hot Reload**: Reload scripts without restart
- **Error Isolation**: Script errors don't crash plugin
- **Performance**: Scripts compile once, execute many times

## ๐Ÿ”’ Security

- **Sandboxed Scripts**: No access to file system or dangerous APIs
- **Class Whitelisting**: Only allowed classes accessible
- **Permission System**: Fine-grained permissions
- **Input Validation**: All inputs validated
- **Error Isolation**: Errors contained to modules

## โšก Performance

- **Async Operations**: All I/O operations async
- **Lazy Loading**: Load on demand
- **Caching**: Frequently used data cached
- **Object Pooling**: Reuse expensive objects
- **Batch Operations**: Batch saves and updates

## ๐Ÿงช Testing

```bash
# Run tests
mvn test

# Run with coverage
mvn test jacoco:report

# Integration tests
mvn verify
```

## ๐Ÿ“Š Monitoring

The framework provides:
- Module load times
- Script execution times
- Event processing metrics
- Memory usage tracking
- Error rates

## ๐Ÿค Contributing

1. Fork the repository
2. Create feature branch
3. Follow code style (Google Java Style)
4. Write tests
5. Submit pull request

## ๐Ÿ“ License

This project is provided as-is for educational and production use.

## ๐Ÿ†˜ Support

### Common Issues

**Module won't load**
- Check module.yml syntax
- Verify dependencies
- Check logs for errors

**Script errors**
- Enable debug mode
- Check script syntax
- Verify API usage

**Performance issues**
- Enable profiling
- Check async operations
- Review module count

### Getting Help

1. Check documentation
2. Review examples
3. Enable debug logging
4. Check server logs

## ๐ŸŽ“ Learning Resources

- [Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
- [SOLID Principles](https://en.wikipedia.org/wiki/SOLID)
- [Paper API Docs](https://docs.papermc.io/)
- [GraalVM Docs](https://www.graalvm.org/latest/docs/)

## ๐Ÿš€ Roadmap

- [ ] Web dashboard
- [ ] Database integration (MySQL, PostgreSQL)
- [ ] Metrics system (Prometheus)
- [ ] Plugin marketplace
- [ ] REST API
- [ ] Distributed modules
- [ ] Hot code reload

## โœจ Credits

Built with:
- Paper API
- GraalVM
- Java 21
- Maven

---

**Version**: 1.0.0  
**Compatibility**: Paper 1.21.8+, Java 21+  
**Architecture**: Clean Architecture + SOLID  
**Status**: Production Ready โœ