From 03080fbd483b179a689b2bc14629815f3cac29cd Mon Sep 17 00:00:00 2001 From: Kariya Date: Thu, 11 Dec 2025 15:48:35 +0000 Subject: [PATCH] refactor: DoubleJumpComponent to track usage and reset on landing, and adjust max tiers for DoubleJump, Glider, and Grappling items. --- .kotlin/errors/errors-1765457724573.log | 35 ++++++++++++ .../content/components/DoubleJumpComponent.kt | 55 +++++++++++++++---- .../content/components/GliderComponent.kt | 2 +- .../hcu/items/content/items/GrapplingItem.kt | 2 + 4 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 .kotlin/errors/errors-1765457724573.log diff --git a/.kotlin/errors/errors-1765457724573.log b/.kotlin/errors/errors-1765457724573.log new file mode 100644 index 0000000..29daee3 --- /dev/null +++ b/.kotlin/errors/errors-1765457724573.log @@ -0,0 +1,35 @@ +kotlin version: 2.2.21 +error message: Incremental compilation failed: /home/nixos/projects/minecraft/crafters-toolbox/components/plugins/hcu-items/build/kotlin/compileKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin (No such file or directory) +java.io.FileNotFoundException: /home/nixos/projects/minecraft/crafters-toolbox/components/plugins/hcu-items/build/kotlin/compileKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin (No such file or directory) + at java.base/java.io.FileInputStream.open0(Native Method) + at java.base/java.io.FileInputStream.open(FileInputStream.java:213) + at java.base/java.io.FileInputStream.(FileInputStream.java:152) + at org.jetbrains.kotlin.incremental.storage.ExternalizersKt.loadFromFile(externalizers.kt:184) + at org.jetbrains.kotlin.incremental.snapshots.LazyClasspathSnapshot.getSavedShrunkClasspathAgainstPreviousLookups(LazyClasspathSnapshot.kt:86) + at org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotShrinkerKt.shrinkAndSaveClasspathSnapshot(ClasspathSnapshotShrinker.kt:267) + at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.performWorkAfterCompilation(IncrementalJvmCompilerRunner.kt:76) + at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.performWorkAfterCompilation(IncrementalJvmCompilerRunner.kt:23) + at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:418) + at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.tryCompileIncrementally$lambda$0$compile(IncrementalCompilerRunner.kt:249) + at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.tryCompileIncrementally(IncrementalCompilerRunner.kt:267) + at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:119) + at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:684) + at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:94) + at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1810) + at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) + at java.base/java.lang.reflect.Method.invoke(Method.java:580) + at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360) + at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) + at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) + at java.base/java.security.AccessController.doPrivileged(AccessController.java:714) + at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) + at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:598) + at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:844) + at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:721) + at java.base/java.security.AccessController.doPrivileged(AccessController.java:400) + at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:720) + at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) + at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) + at java.base/java.lang.Thread.run(Thread.java:1583) + + diff --git a/src/main/kotlin/net/hareworks/hcu/items/content/components/DoubleJumpComponent.kt b/src/main/kotlin/net/hareworks/hcu/items/content/components/DoubleJumpComponent.kt index 267731d..48190af 100644 --- a/src/main/kotlin/net/hareworks/hcu/items/content/components/DoubleJumpComponent.kt +++ b/src/main/kotlin/net/hareworks/hcu/items/content/components/DoubleJumpComponent.kt @@ -16,15 +16,22 @@ import org.bukkit.entity.Player import org.bukkit.event.entity.EntityToggleGlideEvent import org.bukkit.inventory.ItemStack import org.bukkit.util.Vector +import java.util.UUID +import java.util.concurrent.ConcurrentHashMap class DoubleJumpComponent(private val plugin: App) : AbstractComponent(plugin, "double_jump_component"), EquippableComponent { override val displayName: String = "Double Jump" - override val maxTier: Int = 3 + override val maxTier: Int = 1 override val dataComponentDependencies: List get() = listOf(DataComponentTypes.GLIDER) + companion object { + // Track players who have used their double jump (GLIDER is removed) + private val usedDoubleJump = ConcurrentHashMap.newKeySet() + } + override fun apply(item: ItemStack, tier: Tier?) { if (isBoots(item.type)) { super.apply(item, tier) @@ -32,33 +39,57 @@ class DoubleJumpComponent(private val plugin: App) : AbstractComponent(plugin, " } private fun isBoots(material: Material): Boolean { - // Only apply to boots return material.name.endsWith("_BOOTS") } + @Suppress("DEPRECATION") override fun onTick(player: Player, item: ItemStack) { - // No custom tick login currently + // Ensure GLIDER is present if this component is on the item + // This handles the case where equipment is removed/re-equipped while GLIDER was off + if (!item.hasData(DataComponentTypes.GLIDER) && !usedDoubleJump.contains(player.uniqueId)) { + item.setData(DataComponentTypes.GLIDER) + } + + // Reset double jump when player lands on ground + if (player.isOnGround && usedDoubleJump.contains(player.uniqueId)) { + usedDoubleJump.remove(player.uniqueId) + + // Re-add GLIDER component + if (!item.hasData(DataComponentTypes.GLIDER)) { + item.setData(DataComponentTypes.GLIDER) + } + } } override fun onToggleGlide(player: Player, item: ItemStack, event: EntityToggleGlideEvent) { if (player.gameMode == GameMode.CREATIVE || player.gameMode == GameMode.SPECTATOR) return - // When user initiates gliding (pressing Jump in air with Elytra/Glider capability) - // event.isGliding will be true. - if (event.isGliding) { - // Cancel the glide start - event.isCancelled = true - - // Execute Double Jump - handleDoubleJump(player, item) + // Only handle glide start events + if (!event.isGliding) return + + // If player has already used double jump, don't cancel - let them glide normally + // (though GLIDER should be removed, so this shouldn't fire anyway) + if (usedDoubleJump.contains(player.uniqueId)) { + return } + + // Cancel the glide start + event.isCancelled = true + + // Mark as used + usedDoubleJump.add(player.uniqueId) + + // Execute Double Jump + handleDoubleJump(player, item) + + // Remove GLIDER component to prevent further glide triggers + item.unsetData(DataComponentTypes.GLIDER) } private fun handleDoubleJump(player: Player, item: ItemStack) { val tier = getTier(item) ?: Tier.ONE // Physics Calculation - // Vector: Up + Forward direction val direction = player.location.direction.clone().setY(0).normalize() val currentVelocity = player.velocity 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 241c011..f4d45b7 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 @@ -23,7 +23,7 @@ import kotlin.math.pow class GliderComponent(private val plugin: App) : AbstractComponent(plugin, "glider_component"), EquippableComponent { override val displayName: String = "Glider" - override val maxTier: Int = 10 + override val maxTier: Int = 3 companion object { val activeGliders = ConcurrentHashMap() diff --git a/src/main/kotlin/net/hareworks/hcu/items/content/items/GrapplingItem.kt b/src/main/kotlin/net/hareworks/hcu/items/content/items/GrapplingItem.kt index a2b6f88..2ff3b83 100644 --- a/src/main/kotlin/net/hareworks/hcu/items/content/items/GrapplingItem.kt +++ b/src/main/kotlin/net/hareworks/hcu/items/content/items/GrapplingItem.kt @@ -10,6 +10,8 @@ import org.bukkit.event.player.PlayerFishEvent import org.bukkit.inventory.ItemStack class GrapplingItem : AbstractItem("grappling_hook") { + + override val maxTier: Int = 5 override fun buildItem(tier: Tier): ItemStack { val item = ItemStack(Material.FISHING_ROD)