feat: add centralized configuration for component settings and update documentation to English

This commit is contained in:
Kariya 2025-12-16 10:36:38 +00:00
parent e72167c2ce
commit f1787b9b62
6 changed files with 137 additions and 38 deletions

View File

@ -1,35 +1,37 @@
# コンテンツの作成ガイド
# Content Creation Guide
このプロジェクトでは、HcuItemsプラグインを使用して新しいアイテムや機能コンポーネントを追加するための仕組みを提供しています。
イベント処理は`EventListener`によって統一的に管理され、アイテムのPersistentDataContainer (PDC)の情報に基づいて適切なクラスに委譲されます。
This project provides a framework for adding new items and features (components) using the HcuItems plugin.
## アーキテクチャ概要
Event handling is uniformly managed by the `EventListener`, which delegates to appropriate classes based on information in the item's PersistentDataContainer (PDC).
全てのイベント(右クリック、ダメージ、移動など)は `EventListener` で受信されます。
`EventListener` は以下の手順で処理を委譲します:
## Architecture Overview
1. イベントに関与したアイテムを取得します。
2. アイテムのPDCを確認します。
- `AbstractItem` ID (`hcu_items:id`) がある場合 -> `ItemRegistry` からアイテム定義を取得して実行。
- コンポーネント用のキー (`hcu_items:component_id`) がある場合 -> `ComponentRegistry` からコンポーネント定義を取得して実行。
All events (right-click, damage, movement, etc.) are received by the `EventListener`.
## 1. AbstractItem (独自のアイテム) の作成
The `EventListener` delegates processing through the following steps:
完全に独自の挙動を持つアイテムを作成する場合に使用します。
1. Retrieves the item involved in the event.
2. Checks the item's PDC.
- If an `AbstractItem` ID (`hcu_items:id`) exists → Retrieves the item definition from `ItemRegistry` and executes.
- If a component key (`hcu_items:component_id`) exists → Retrieves the component definition from `ComponentRegistry` and executes.
### 手順
## 1. Creating an AbstractItem (Custom Item)
1. `AbstractItem` クラスを継承した新しいクラスを作成します。
2. コンストラクタで一意のIDを指定します。
3. `buildItem` メソッドを実装し、アイテムの見た目Material, Name, Loreなどを定義します。
4. 必要なイベントハンドラ(`onInteract`, `onPlayerMove` など)をオーバーライドします。
5. `App.kt``onEnable``ItemRegistry.register(YourItem())` を呼び出して登録します。
Use this when creating an item with completely unique behavior.
### Steps
1. Create a new class that inherits from the `AbstractItem` class.
2. Specify a unique ID in the constructor.
3. Implement the `buildItem` method to define the item's appearance (Material, Name, Lore, etc.).
4. Override necessary event handlers (`onInteract`, `onPlayerMove`, etc.).
5. Register by calling `ItemRegistry.register(YourItem())` in `App.kt`'s `onEnable`.
```kotlin
class MyCustomItem : AbstractItem("my_custom_item") {
override fun buildItem(tier: Tier): ItemStack {
return ItemStack(Material.DIAMOND_SWORD).apply {
// Meta設定
// Meta configuration
}
}
@ -39,17 +41,17 @@ class MyCustomItem : AbstractItem("my_custom_item") {
}
```
## 2. CustomComponent (既存アイテムへの機能追加) の作成
## 2. Creating a CustomComponent (Adding Features to Existing Items)
既存のアイテムや、特定の条件を満たすアイテムに共通の機能(例:グライダー、パッシブ効果)を付与する場合に使用します。
Use this when adding common features (e.g., glider, passive effects) to existing items or items that meet specific conditions.
### 手順
### Steps
1. `AbstractComponent` を継承し、`CustomComponent` (または `EquippableComponent`) を実装したクラスを作成します。
2. コンストラクタで一意のコンポーネントIDを指定します。
3. `apply` メソッドでアイテムにコンポーネントを適用するロジックPDCへのキー登録は自動で行われますが、追加のメタデータが必要な場合は記述を実装します。
4. 必要なイベントハンドラをオーバーライドします。
5. `App.kt``onEnable``ComponentRegistry.register(YourComponent(this))` を呼び出して登録します。
1. Create a class that inherits from `AbstractComponent` and implements `CustomComponent` (or `EquippableComponent`).
2. Specify a unique component ID in the constructor.
3. Implement the `apply` method with logic to apply the component to the item (key registration to PDC is automatic, but describe if additional metadata is needed).
4. Override necessary event handlers.
5. Register by calling `ComponentRegistry.register(YourComponent(this))` in `App.kt`'s `onEnable`.
```kotlin
class MyComponent(plugin: App) : AbstractComponent(plugin, "my_component") {
@ -59,10 +61,59 @@ class MyComponent(plugin: App) : AbstractComponent(plugin, "my_component") {
}
```
### イベントの仕組み
`AbstractComponent` は初期化時に `NamespacedKey` を生成し、`apply` 時にこのキーをアイテムのPDCに書き込みます。
`EventListener` はアイテムのPDCにこのキーが存在することを確認すると、あなたのコンポーネントのイベントハンドラを呼び出します。
### Event Mechanism
## 注意事項
- `AbstractItem``CustomComponent` は共存可能です。1つのアイテムが `AbstractItem` であり、かつ複数の `CustomComponent` を持つことができます。
- イベントハンドラ内では、必要に応じて `event.isCancelled` などを適切に制御してください。
`AbstractComponent` generates a `NamespacedKey` during initialization and writes this key to the item's PDC during `apply`.
When the `EventListener` confirms this key exists in the item's PDC, it calls your component's event handler.
## Notes
- `AbstractItem` and `CustomComponent` can coexist. A single item can be an `AbstractItem` and have multiple `CustomComponent`s.
- Within event handlers, appropriately control `event.isCancelled` as needed.
## 3. Configuration Management
The project uses a centralized `Config` object to manage configuration values from `config.yml`. This allows for easy adjustment of values (like cooldowns) without code changes.
### Accessing Configuration
To access configuration values, simply access the public properties of the `Config` object:
```kotlin
import net.hareworks.hcu.items.config.Config
// Example usage
val cooldown = Cooldown(Config.blinkCooldown)
```
### Adding New Config Values
1. **Add Property to Config Object**: Add a new property to `net.hareworks.hcu.items.config.Config.kt`.
2. **Update Load Method**: Read the value from `plugin.config` in the `load` method.
3. **Update Defaults**: Add the default value in the `saveDefaults` method.
```kotlin
object Config {
// 1. Add Property
var newFeatureEnabled: Boolean = true
fun load(plugin: JavaPlugin) {
// ... existing code ...
// 2. Load Value
newFeatureEnabled = config.getBoolean("components.new_feature.enabled", true)
// ... existing code ...
}
private fun saveDefaults(plugin: JavaPlugin, config: FileConfiguration) {
// ... existing code ...
// 3. Set Default
config.addDefault("components.new_feature.enabled", true)
// ... existing code ...
}
}
```

View File

@ -27,6 +27,8 @@ public class App : JavaPlugin() {
override fun onEnable() {
instance = this
// Initialize Config
net.hareworks.hcu.items.config.Config.load(this)
saveDefaultConfig()
server.pluginManager.registerEvents(net.hareworks.hcu.items.listeners.EventListener(this), this)
logger.info("Items plugin enabled!")

View File

@ -0,0 +1,39 @@
package net.hareworks.hcu.items.config
import org.bukkit.configuration.file.FileConfiguration
import org.bukkit.plugin.java.JavaPlugin
object Config {
// Component Settings
var blinkCooldown: Long = 1500
var doubleJumpCooldown: Long = 1500
var doubleJumpPowerVertical: Double = 0.5
var doubleJumpPowerForward: Double = 0.3
fun load(plugin: JavaPlugin) {
plugin.reloadConfig()
val config = plugin.config
// Blink
blinkCooldown = config.getLong("components.blink.cooldown", 1500)
// Double Jump
doubleJumpCooldown = config.getLong("components.double_jump.cooldown", 1500)
doubleJumpPowerVertical = config.getDouble("components.double_jump.power.vertical", 0.5)
doubleJumpPowerForward = config.getDouble("components.double_jump.power.forward", 0.3)
// Save back to ensure defaults are written if missing
saveDefaults(plugin, config)
}
private fun saveDefaults(plugin: JavaPlugin, config: FileConfiguration) {
config.addDefault("components.blink.cooldown", 1500)
config.addDefault("components.double_jump.cooldown", 1500)
config.addDefault("components.double_jump.power.vertical", 0.5)
config.addDefault("components.double_jump.power.forward", 0.3)
config.options().copyDefaults(true)
plugin.saveConfig()
}
}

View File

@ -35,7 +35,7 @@ class BlinkComponent(private val plugin: App) : AbstractComponent(plugin, "blink
companion object {
// Track players who have used their blink (GLIDER is removed until landing)
private val usedBlink = ConcurrentHashMap.newKeySet<UUID>()
private val cooldown = Cooldown(1500)
private val cooldown = Cooldown(net.hareworks.hcu.items.config.Config.blinkCooldown)
// Color scheme - Purple/Magenta for teleport/blink theme
private val PRIMARY_COLOR = TextColor.color(0xDA70D6) // Orchid

View File

@ -34,7 +34,7 @@ class DoubleJumpComponent(private val plugin: App) : AbstractComponent(plugin, "
companion object {
// Track players who have used their double jump (GLIDER is removed)
private val usedDoubleJump = ConcurrentHashMap.newKeySet<UUID>()
private val cooldown = Cooldown(1500)
private val cooldown = Cooldown(net.hareworks.hcu.items.config.Config.doubleJumpCooldown)
// Color scheme
private val PRIMARY_COLOR = TextColor.color(0x7DF9FF) // Electric Cyan
@ -127,8 +127,8 @@ class DoubleJumpComponent(private val plugin: App) : AbstractComponent(plugin, "
val currentVelocity = player.velocity
// Base power + Tier bonus
val verticalPower = 0.5 + (tier.level * 0.15)
val forwardPower = 0.3 + (tier.level * 0.1)
val verticalPower = net.hareworks.hcu.items.config.Config.doubleJumpPowerVertical + (tier.level * 0.15)
val forwardPower = net.hareworks.hcu.items.config.Config.doubleJumpPowerForward + (tier.level * 0.1)
player.velocity = currentVelocity.add(direction.multiply(forwardPower)).setY(verticalPower)

View File

@ -1 +1,8 @@
components:
blink:
cooldown: 1500 # Milliseconds
double_jump:
cooldown: 1500 # Milliseconds
power:
vertical: 0.5
forward: 0.3