feat: Introduce configurable global component tick interval, enhance Glider and Vein Miner components, fix component dependency resolution, and improve item comparison.

This commit is contained in:
Kariya 2025-12-16 16:01:02 +00:00
parent 6752d075f4
commit 32dbebb228
7 changed files with 52 additions and 11 deletions

View File

@ -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
}
}

View File

@ -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!")

View File

@ -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<String>)
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)

View File

@ -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?) {

View File

@ -34,6 +34,18 @@ class VeinMinerComponent(private val plugin: JavaPlugin) : ToolComponent {
private val activeHighlights = mutableMapOf<UUID, HighlightSession>()
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<BlockDisplay>,
@ -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 {

View File

@ -21,9 +21,11 @@ class EventListener(private val plugin: Plugin) : Listener {
private val lastHeldItems = java.util.concurrent.ConcurrentHashMap<java.util.UUID, Pair<ItemStack?, ItemStack?>>()
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)

View File

@ -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<org.bukkit.NamespacedKey>) {
// 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)
}
}