Skip to content

Latest commit

 

History

History
161 lines (148 loc) · 5.17 KB

File metadata and controls

161 lines (148 loc) · 5.17 KB

ModularPlugin - Production Architecture

Project Structure

ModularPlugin/
├── pom.xml
├── README.md
├── INSTALL.md
├── .gitignore
│
├── src/main/java/com/myplugin/
│   │
│   ├── ModularPlugin.java                    # Main plugin class
│   │
│   ├── api/                                   # Public API interfaces
│   │   ├── module/
│   │   │   ├── Module.java
│   │   │   ├── ModuleManager.java
│   │   │   └── ModuleDescriptor.java
│   │   ├── item/
│   │   │   ├── CustomItem.java
│   │   │   ├── ItemManager.java
│   │   │   └── ItemAbility.java
│   │   ├── command/
│   │   │   ├── CommandExecutor.java
│   │   │   └── CommandManager.java
│   │   ├── script/
│   │   │   ├── ScriptEngine.java
│   │   │   └── ScriptContext.java
│   │   ├── storage/
│   │   │   ├── StorageProvider.java
│   │   │   └── DataRepository.java
│   │   ├── event/
│   │   │   ├── EventBus.java
│   │   │   └── Event.java
│   │   └── scheduler/
│   │       └── TaskScheduler.java
│   │
│   ├── core/                                  # Core implementation
│   │   ├── di/
│   │   │   ├── Container.java
│   │   │   ├── Injectable.java
│   │   │   └── ServiceRegistry.java
│   │   ├── module/
│   │   │   ├── ModuleManagerImpl.java
│   │   │   ├── ModuleLoader.java
│   │   │   └── DependencyResolver.java
│   │   ├── item/
│   │   │   ├── ItemManagerImpl.java
│   │   │   ├── ItemRegistry.java
│   │   │   └── AbilityExecutor.java
│   │   ├── command/
│   │   │   ├── CommandManagerImpl.java
│   │   │   ├── CommandRegistry.java
│   │   │   └── TabCompleter.java
│   │   ├── script/
│   │   │   ├── GraalScriptEngine.java
│   │   │   ├── ScriptSandbox.java
│   │   │   ├── ScriptAPI.java
│   │   │   └── ScriptLoader.java
│   │   ├── storage/
│   │   │   ├── StorageManager.java
│   │   │   ├── YamlProvider.java
│   │   │   ├── JsonProvider.java
│   │   │   ├── SQLiteProvider.java
│   │   │   └── CacheLayer.java
│   │   ├── event/
│   │   │   ├── EventBusImpl.java
│   │   │   ├── EventDispatcher.java
│   │   │   └── EventSubscriber.java
│   │   ├── scheduler/
│   │   │   ├── TaskSchedulerImpl.java
│   │   │   └── TaskRegistry.java
│   │   └── config/
│   │       ├── ConfigManager.java
│   │       └── MessageManager.java
│   │
│   ├── modules/                               # Built-in modules
│   │   └── demo/
│   │       ├── DemoModule.java
│   │       ├── MagicWandItem.java
│   │       └── FlyCommand.java
│   │
│   ├── gui/                                   # GUI system
│   │   ├── InventoryGUI.java
│   │   ├── GUIBuilder.java
│   │   └── GUIManager.java
│   │
│   └── utils/                                 # Utilities
│       ├── TextUtils.java
│       ├── LocationUtils.java
│       ├── ItemBuilder.java
│       └── Validate.java
│
├── src/main/resources/
│   ├── plugin.yml
│   ├── config.yml
│   ├── messages.yml
│   └── modules/
│       └── demo/
│           └── module.yml
│
└── scripts/                                   # JavaScript files
    ├── examples/
    │   ├── custom_item.js
    │   ├── custom_command.js
    │   └── event_handler.js
    └── modules/
        └── demo/
            └── welcome.js

Architecture Layers

1. API Layer (api/)

  • Pure interfaces
  • No implementation details
  • Contracts for all systems

2. Core Layer (core/)

  • Implementation of API
  • Business logic
  • Thread-safe operations
  • Dependency injection

3. Module Layer (modules/)

  • Pluggable modules
  • Self-contained functionality
  • Can depend on other modules

4. Script Layer (scripts/)

  • JavaScript integration
  • Hot-reloadable
  • Sandboxed execution

Key Design Patterns

  • Dependency Injection: Custom lightweight DI container
  • Repository Pattern: Storage abstraction
  • Observer Pattern: Event bus
  • Strategy Pattern: Storage providers
  • Builder Pattern: Item creation, GUI building
  • Factory Pattern: Module creation
  • Singleton: Service registry (thread-safe)

Thread Safety

  • All managers use ConcurrentHashMap
  • Async operations use CompletableFuture
  • Proper synchronization on shared state
  • Lock-free where possible

Performance Optimizations

  • Lazy loading of modules
  • Caching layer for storage
  • Batch operations for saves
  • Async I/O operations
  • Object pooling for frequent allocations
  • Efficient event dispatching