diff --git a/build.gradle.kts b/build.gradle.kts index 3b72118..93451b4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { id("com.gradleup.shadow") version "9.2.2" } -group = "com.github.kaaariyaaa" +group = "net.hareworks.hcu" version = "1.0" repositories { mavenCentral() @@ -33,7 +33,7 @@ tasks { } shadowJar { archiveClassifier.set("min") - minimize() + // minimize() - Removed to prevent accidental exclusion of required classes } } diff --git a/src/main/kotlin/net/hareworks/hcu/items/App.kt b/src/main/kotlin/net/hareworks/hcu/items/App.kt index 143fce3..067cf7c 100644 --- a/src/main/kotlin/net/hareworks/hcu/items/App.kt +++ b/src/main/kotlin/net/hareworks/hcu/items/App.kt @@ -28,9 +28,9 @@ public class App : JavaPlugin() { override fun onEnable() { instance = this - // Initialize Config - net.hareworks.hcu.items.config.Config.load(this) - saveDefaultConfig() + // Initialize Config + saveDefaultConfig() + net.hareworks.hcu.items.config.Config.load(this) server.pluginManager.registerEvents(net.hareworks.hcu.items.listeners.EventListener(this), this) logger.info("Items plugin enabled!") diff --git a/src/main/kotlin/net/hareworks/hcu/items/config/Config.kt b/src/main/kotlin/net/hareworks/hcu/items/config/Config.kt index 58bfaec..9c58ae6 100644 --- a/src/main/kotlin/net/hareworks/hcu/items/config/Config.kt +++ b/src/main/kotlin/net/hareworks/hcu/items/config/Config.kt @@ -11,6 +11,9 @@ object Config { var doubleJumpPowerVertical: Double = 0.5 var doubleJumpPowerForward: Double = 0.3 + // Global Settings + var componentTickInterval: Long = 1L + // Vein Miner data class ToolCategory(val toolPattern: String, val allowedBlockPatterns: List) var veinMinerMaxBlocks: Int = 64 @@ -22,6 +25,9 @@ object Config { plugin.reloadConfig() val config = plugin.config + // Global + componentTickInterval = config.getLong("components.global.tick_interval", 1L).coerceAtLeast(1L) + // Blink blinkCooldown = config.getLong("components.blink.cooldown", 1500) @@ -31,7 +37,14 @@ object Config { doubleJumpPowerForward = config.getDouble("components.double_jump.power.forward", 0.3) // Vein Miner - veinMinerMaxBlocks = config.getInt("components.vein_miner.max_blocks", 64) + val rawMaxBlocks = config.getInt("components.vein_miner.max_blocks", 64) + if (rawMaxBlocks > 2048) { + plugin.logger.warning("Vein miner max blocks set to $rawMaxBlocks, which is very high. Capping at 2048 to prevent crashes.") + veinMinerMaxBlocks = 2048 + } else { + veinMinerMaxBlocks = rawMaxBlocks + } + veinMinerActivationMode = config.getString("components.vein_miner.activation_mode", "SNEAK") ?: "SNEAK" loadCompatibleGroups(config) loadToolCategories(config) @@ -41,6 +54,8 @@ object Config { } private fun saveDefaults(plugin: JavaPlugin, config: FileConfiguration) { + config.addDefault("components.global.tick_interval", 1L) + config.addDefault("components.blink.cooldown", 1500) config.addDefault("components.double_jump.cooldown", 1500) config.addDefault("components.double_jump.power.vertical", 0.5) diff --git a/src/main/kotlin/net/hareworks/hcu/items/content/components/GliderComponent.kt b/src/main/kotlin/net/hareworks/hcu/items/content/components/GliderComponent.kt index f4d45b7..77e2d13 100644 --- a/src/main/kotlin/net/hareworks/hcu/items/content/components/GliderComponent.kt +++ b/src/main/kotlin/net/hareworks/hcu/items/content/components/GliderComponent.kt @@ -45,6 +45,7 @@ class GliderComponent(private val plugin: App) : AbstractComponent(plugin, "glid init { // Global Ticker for active gliders + val interval = net.hareworks.hcu.items.config.Config.componentTickInterval plugin.server.scheduler.runTaskTimer(plugin, Runnable { if (activeGliders.isEmpty()) return@Runnable @@ -78,7 +79,7 @@ class GliderComponent(private val plugin: App) : AbstractComponent(plugin, "glid // Physics and Logic tickGliderPhysics(player, item, state) } - }, 1L, 1L) + }, 1L, interval) } override fun apply(item: ItemStack, tier: Tier?) { diff --git a/src/main/kotlin/net/hareworks/hcu/items/content/components/VeinMinerComponent.kt b/src/main/kotlin/net/hareworks/hcu/items/content/components/VeinMinerComponent.kt index 5b98f7c..dba920b 100644 --- a/src/main/kotlin/net/hareworks/hcu/items/content/components/VeinMinerComponent.kt +++ b/src/main/kotlin/net/hareworks/hcu/items/content/components/VeinMinerComponent.kt @@ -34,6 +34,18 @@ class VeinMinerComponent(private val plugin: JavaPlugin) : ToolComponent { private val activeHighlights = mutableMapOf() + companion object { + var supportsBlockDisplay: Boolean = false + init { + try { + Class.forName("org.bukkit.entity.BlockDisplay") + supportsBlockDisplay = true + } catch (e: ClassNotFoundException) { + supportsBlockDisplay = false + } + } + } + data class HighlightSession( val centerBlock: Block, val entities: List, @@ -89,6 +101,8 @@ class VeinMinerComponent(private val plugin: JavaPlugin) : ToolComponent { // クライアントのパフォーマンスを考慮し、最大ハイライト数を制限しても良いが、 // ユーザー要望通り全てハイライトする + if (!supportsBlockDisplay) return + for (block in blocksToBreak) { val loc = block.location.add(0.5, 0.5, 0.5) try { diff --git a/src/main/kotlin/net/hareworks/hcu/items/listeners/EventListener.kt b/src/main/kotlin/net/hareworks/hcu/items/listeners/EventListener.kt index 347ffa7..582ad84 100644 --- a/src/main/kotlin/net/hareworks/hcu/items/listeners/EventListener.kt +++ b/src/main/kotlin/net/hareworks/hcu/items/listeners/EventListener.kt @@ -21,9 +21,11 @@ class EventListener(private val plugin: Plugin) : Listener { private val lastHeldItems = java.util.concurrent.ConcurrentHashMap>() init { + // Use configurable tick interval (defaulting to 1L if something goes wrong, though Config handles defaults) + val interval = net.hareworks.hcu.items.config.Config.componentTickInterval plugin.server.scheduler.runTaskTimer(plugin, Runnable { tickComponents() - }, 1L, 1L) + }, 1L, interval) } @EventHandler @@ -147,7 +149,7 @@ class EventListener(private val plugin: Plugin) : Listener { val lastOffHand = lastItems?.second // Check Main Hand Change - if (lastMainHand != null && lastMainHand != currentMainHand) { + if (lastMainHand != null && !lastMainHand.isSimilar(currentMainHand)) { dispatchToComponents(lastMainHand) { component -> if (component is ToolComponent) { component.onStopHolding(player, lastMainHand) @@ -156,7 +158,7 @@ class EventListener(private val plugin: Plugin) : Listener { } // Check Off Hand Change - if (lastOffHand != null && lastOffHand != currentOffHand) { + if (lastOffHand != null && !lastOffHand.isSimilar(currentOffHand)) { dispatchToComponents(lastOffHand) { component -> if (component is ToolComponent) { component.onStopHolding(player, lastOffHand) diff --git a/src/main/kotlin/net/hareworks/hcu/items/registry/ComponentRegistry.kt b/src/main/kotlin/net/hareworks/hcu/items/registry/ComponentRegistry.kt index 1552bc2..fdec0d6 100644 --- a/src/main/kotlin/net/hareworks/hcu/items/registry/ComponentRegistry.kt +++ b/src/main/kotlin/net/hareworks/hcu/items/registry/ComponentRegistry.kt @@ -29,6 +29,13 @@ object ComponentRegistry { * コンポーネントを依存関係を解決しながら適用する */ fun applyWithDependencies(component: CustomComponent, item: ItemStack, tier: Tier? = null) { + applyRecursive(component, item, tier, mutableSetOf()) + } + + private fun applyRecursive(component: CustomComponent, item: ItemStack, tier: Tier?, visited: MutableSet) { + // Cycle detection + if (!visited.add(component.key)) return + // 1. バニラDataComponent依存を適用 for (dataType in component.dataComponentDependencies) { if (!item.hasData(dataType)) { @@ -40,7 +47,9 @@ object ComponentRegistry { for (depKey in component.componentDependencies) { val dep = get(depKey) if (dep != null && !dep.has(item)) { - applyWithDependencies(dep, item, null) + // Propagate tier to dependencies (or decide per logic; usually null is safe for deps if they are passive, + // but request says "decide whether to propagate". Propagating same tier seems consistent for "bundled" components). + applyRecursive(dep, item, tier, visited) } }