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:
parent
6752d075f4
commit
32dbebb228
|
|
@ -7,7 +7,7 @@ plugins {
|
||||||
id("com.gradleup.shadow") version "9.2.2"
|
id("com.gradleup.shadow") version "9.2.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "com.github.kaaariyaaa"
|
group = "net.hareworks.hcu"
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
@ -33,7 +33,7 @@ tasks {
|
||||||
}
|
}
|
||||||
shadowJar {
|
shadowJar {
|
||||||
archiveClassifier.set("min")
|
archiveClassifier.set("min")
|
||||||
minimize()
|
// minimize() - Removed to prevent accidental exclusion of required classes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ public class App : JavaPlugin() {
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
instance = this
|
instance = this
|
||||||
// Initialize Config
|
// Initialize Config
|
||||||
net.hareworks.hcu.items.config.Config.load(this)
|
|
||||||
saveDefaultConfig()
|
saveDefaultConfig()
|
||||||
|
net.hareworks.hcu.items.config.Config.load(this)
|
||||||
server.pluginManager.registerEvents(net.hareworks.hcu.items.listeners.EventListener(this), this)
|
server.pluginManager.registerEvents(net.hareworks.hcu.items.listeners.EventListener(this), this)
|
||||||
logger.info("Items plugin enabled!")
|
logger.info("Items plugin enabled!")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@ object Config {
|
||||||
var doubleJumpPowerVertical: Double = 0.5
|
var doubleJumpPowerVertical: Double = 0.5
|
||||||
var doubleJumpPowerForward: Double = 0.3
|
var doubleJumpPowerForward: Double = 0.3
|
||||||
|
|
||||||
|
// Global Settings
|
||||||
|
var componentTickInterval: Long = 1L
|
||||||
|
|
||||||
// Vein Miner
|
// Vein Miner
|
||||||
data class ToolCategory(val toolPattern: String, val allowedBlockPatterns: List<String>)
|
data class ToolCategory(val toolPattern: String, val allowedBlockPatterns: List<String>)
|
||||||
var veinMinerMaxBlocks: Int = 64
|
var veinMinerMaxBlocks: Int = 64
|
||||||
|
|
@ -22,6 +25,9 @@ object Config {
|
||||||
plugin.reloadConfig()
|
plugin.reloadConfig()
|
||||||
val config = plugin.config
|
val config = plugin.config
|
||||||
|
|
||||||
|
// Global
|
||||||
|
componentTickInterval = config.getLong("components.global.tick_interval", 1L).coerceAtLeast(1L)
|
||||||
|
|
||||||
// Blink
|
// Blink
|
||||||
blinkCooldown = config.getLong("components.blink.cooldown", 1500)
|
blinkCooldown = config.getLong("components.blink.cooldown", 1500)
|
||||||
|
|
||||||
|
|
@ -31,7 +37,14 @@ object Config {
|
||||||
doubleJumpPowerForward = config.getDouble("components.double_jump.power.forward", 0.3)
|
doubleJumpPowerForward = config.getDouble("components.double_jump.power.forward", 0.3)
|
||||||
|
|
||||||
// Vein Miner
|
// 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"
|
veinMinerActivationMode = config.getString("components.vein_miner.activation_mode", "SNEAK") ?: "SNEAK"
|
||||||
loadCompatibleGroups(config)
|
loadCompatibleGroups(config)
|
||||||
loadToolCategories(config)
|
loadToolCategories(config)
|
||||||
|
|
@ -41,6 +54,8 @@ object Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveDefaults(plugin: JavaPlugin, config: FileConfiguration) {
|
private fun saveDefaults(plugin: JavaPlugin, config: FileConfiguration) {
|
||||||
|
config.addDefault("components.global.tick_interval", 1L)
|
||||||
|
|
||||||
config.addDefault("components.blink.cooldown", 1500)
|
config.addDefault("components.blink.cooldown", 1500)
|
||||||
config.addDefault("components.double_jump.cooldown", 1500)
|
config.addDefault("components.double_jump.cooldown", 1500)
|
||||||
config.addDefault("components.double_jump.power.vertical", 0.5)
|
config.addDefault("components.double_jump.power.vertical", 0.5)
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ class GliderComponent(private val plugin: App) : AbstractComponent(plugin, "glid
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// Global Ticker for active gliders
|
// Global Ticker for active gliders
|
||||||
|
val interval = net.hareworks.hcu.items.config.Config.componentTickInterval
|
||||||
plugin.server.scheduler.runTaskTimer(plugin, Runnable {
|
plugin.server.scheduler.runTaskTimer(plugin, Runnable {
|
||||||
if (activeGliders.isEmpty()) return@Runnable
|
if (activeGliders.isEmpty()) return@Runnable
|
||||||
|
|
||||||
|
|
@ -78,7 +79,7 @@ class GliderComponent(private val plugin: App) : AbstractComponent(plugin, "glid
|
||||||
// Physics and Logic
|
// Physics and Logic
|
||||||
tickGliderPhysics(player, item, state)
|
tickGliderPhysics(player, item, state)
|
||||||
}
|
}
|
||||||
}, 1L, 1L)
|
}, 1L, interval)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun apply(item: ItemStack, tier: Tier?) {
|
override fun apply(item: ItemStack, tier: Tier?) {
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,18 @@ class VeinMinerComponent(private val plugin: JavaPlugin) : ToolComponent {
|
||||||
|
|
||||||
private val activeHighlights = mutableMapOf<UUID, HighlightSession>()
|
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(
|
data class HighlightSession(
|
||||||
val centerBlock: Block,
|
val centerBlock: Block,
|
||||||
val entities: List<BlockDisplay>,
|
val entities: List<BlockDisplay>,
|
||||||
|
|
@ -89,6 +101,8 @@ class VeinMinerComponent(private val plugin: JavaPlugin) : ToolComponent {
|
||||||
|
|
||||||
// クライアントのパフォーマンスを考慮し、最大ハイライト数を制限しても良いが、
|
// クライアントのパフォーマンスを考慮し、最大ハイライト数を制限しても良いが、
|
||||||
// ユーザー要望通り全てハイライトする
|
// ユーザー要望通り全てハイライトする
|
||||||
|
if (!supportsBlockDisplay) return
|
||||||
|
|
||||||
for (block in blocksToBreak) {
|
for (block in blocksToBreak) {
|
||||||
val loc = block.location.add(0.5, 0.5, 0.5)
|
val loc = block.location.add(0.5, 0.5, 0.5)
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,11 @@ class EventListener(private val plugin: Plugin) : Listener {
|
||||||
private val lastHeldItems = java.util.concurrent.ConcurrentHashMap<java.util.UUID, Pair<ItemStack?, ItemStack?>>()
|
private val lastHeldItems = java.util.concurrent.ConcurrentHashMap<java.util.UUID, Pair<ItemStack?, ItemStack?>>()
|
||||||
|
|
||||||
init {
|
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 {
|
plugin.server.scheduler.runTaskTimer(plugin, Runnable {
|
||||||
tickComponents()
|
tickComponents()
|
||||||
}, 1L, 1L)
|
}, 1L, interval)
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
@ -147,7 +149,7 @@ class EventListener(private val plugin: Plugin) : Listener {
|
||||||
val lastOffHand = lastItems?.second
|
val lastOffHand = lastItems?.second
|
||||||
|
|
||||||
// Check Main Hand Change
|
// Check Main Hand Change
|
||||||
if (lastMainHand != null && lastMainHand != currentMainHand) {
|
if (lastMainHand != null && !lastMainHand.isSimilar(currentMainHand)) {
|
||||||
dispatchToComponents(lastMainHand) { component ->
|
dispatchToComponents(lastMainHand) { component ->
|
||||||
if (component is ToolComponent) {
|
if (component is ToolComponent) {
|
||||||
component.onStopHolding(player, lastMainHand)
|
component.onStopHolding(player, lastMainHand)
|
||||||
|
|
@ -156,7 +158,7 @@ class EventListener(private val plugin: Plugin) : Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Off Hand Change
|
// Check Off Hand Change
|
||||||
if (lastOffHand != null && lastOffHand != currentOffHand) {
|
if (lastOffHand != null && !lastOffHand.isSimilar(currentOffHand)) {
|
||||||
dispatchToComponents(lastOffHand) { component ->
|
dispatchToComponents(lastOffHand) { component ->
|
||||||
if (component is ToolComponent) {
|
if (component is ToolComponent) {
|
||||||
component.onStopHolding(player, lastOffHand)
|
component.onStopHolding(player, lastOffHand)
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,13 @@ object ComponentRegistry {
|
||||||
* コンポーネントを依存関係を解決しながら適用する
|
* コンポーネントを依存関係を解決しながら適用する
|
||||||
*/
|
*/
|
||||||
fun applyWithDependencies(component: CustomComponent, item: ItemStack, tier: Tier? = null) {
|
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依存を適用
|
// 1. バニラDataComponent依存を適用
|
||||||
for (dataType in component.dataComponentDependencies) {
|
for (dataType in component.dataComponentDependencies) {
|
||||||
if (!item.hasData(dataType)) {
|
if (!item.hasData(dataType)) {
|
||||||
|
|
@ -40,7 +47,9 @@ object ComponentRegistry {
|
||||||
for (depKey in component.componentDependencies) {
|
for (depKey in component.componentDependencies) {
|
||||||
val dep = get(depKey)
|
val dep = get(depKey)
|
||||||
if (dep != null && !dep.has(item)) {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user