Skip to content

Refactor Funnel.kt: extract RayTraceHandler, ArmorStandManager, and FunnelTask#56

Open
Copilot wants to merge 5 commits intokotlinfrom
copilot/refactor-funnel-kt-code
Open

Refactor Funnel.kt: extract RayTraceHandler, ArmorStandManager, and FunnelTask#56
Copilot wants to merge 5 commits intokotlinfrom
copilot/refactor-funnel-kt-code

Conversation

Copy link

Copilot AI commented Mar 9, 2026

Funnel.kt had grown to 1673 lines with a 1250-line anonymous BukkitRunnable, 3× duplicated armor stand group setup (~90 lines each), deeply nested ray trace logic, and global hashPlayer/hashArmorstand state — all in one object.

Changes

RayTraceHandler (new object)

  • Extracts funnelShot ray trace + damage logic into performShot()
  • Flattens the nested armor stand hit dispatch with a when expression:
return when (name) {
    "SplashShield" -> { /* check team, damage, break */ true }
    "Kasa"         -> { /* check team, damage, break */ true }
    else           -> { ArmorStandMgr.giveDamageArmorStand(...); true }
}

ArmorStandManager (new object)

  • Owns hashPlayer and hashArmorstand maps (moved from Funnel)
  • spawnFunnelGroup() / sendEquipmentPackets() / cleanupFunnelGroup() collapse the three identical listremove* rebuild runnables into a single scheduleGroupRebuild(groupIndex, locp, l1, r1, delay) call

FunnelTask (new class, extends BukkitRunnable)

  • Houses the full per-tick logic previously in the anonymous runnable
  • Tick body decomposed into: initializeFunnelGroups, handleSpectatorDestruction, handleDestroyedGroups, checkGroupDestroyed, moveFunnelToTarget, moveStandTowards, performLockOnScan, tryLockOnPlayer/ArmorStand

Funnel (simplified)

  • Reduced from 1673 → ~230 lines
  • funnelFloatFunnelTask(player).start()
  • funnelShotRayTraceHandler.performShot() (preserving spectator guard + shot sound)
  • Shared spawnPursuitParticle() extracted from duplicated funnelPursuit/funnelPursuitPlayer bodies
  • Public API (funnelFloat, funnelPursuit, funnelPursuitPlayer) is unchanged

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • jitpack.io
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=384m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en (dns block)
  • scans-in.gradle.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=384m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

ok lets go

The user has attached the following files from their workspace:

  • src/main/kotlin/be4rjp/sclat/weapon/Funnel.kt

TITLE: Refactoring and Simplification of Funnel.kt for Better Maintainability

USER INTENT:

The user aims to refactor the Funnel.kt file to simplify its logic, extract repeated patterns into reusable methods, and split responsibilities into separate classes for better readability, maintainability, and modularity.


TASK DESCRIPTION:

  1. Simplify the existing code by removing redundancy and improving readability.
  2. Extract repeated logic (e.g., ArmorStand creation, ray tracing) into reusable methods.
  3. Split the class into smaller, focused classes:
    • RayTraceHandler: Manage ray tracing and damage application.
    • ArmorStandManager: Handle ArmorStand creation, initialization, and cleanup.
    • FunnelTask: Manage scheduled tasks for ArmorStand behavior.
  4. Refactor methods like funnelShot and funnelFloat to delegate responsibilities to the new classes and extracted methods.
  5. Ensure the refactored code maintains the original functionality.

EXISTING:

  • Funnel.kt:
    • Contains methods like funnelShot and funnelFloat that handle ray tracing, damage application, ArmorStand management, and task scheduling.
    • Uses global variables (hashPlayer, hashArmorstand) to manage state.
    • Includes repeated patterns for ArmorStand creation and interaction.

PENDING:

  1. Refactor funnelShot:
    • Extract ray tracing logic into RayTraceHandler.
    • Simplify nested conditions and move ArmorStand interaction logic to helper methods.
  2. Refactor funnelFloat:
    • Move ArmorStand initialization to ArmorStandManager.
    • Delegate task scheduling to FunnelTask.
  3. Encapsulate Global State:
    • Move hashPlayer and hashArmorstand to appropriate classes.
  4. Split Classes:
    • Create RayTraceHandler, ArmorStandManager, and FunnelTask classes.
  5. Test Refactored Code:
    • Verify that the refactored code behaves as expected.

CODE STATE:

Funnel.kt (Before Refactoring):

  • funnelShot:
    • Handles ray tracing, damage application, and ArmorStand interaction.
    • Contains nested loops and conditions, making it hard to read.
  • funnelFloat:
    • Manages multiple ArmorStand entities and uses BukkitRunnable for task scheduling.
    • Includes redundant logic for ArmorStand initialization.

RELEVANT CODE/DOCUMENTATION SNIPPETS:

Example of Repeated Logic in funnelFloat:

val kasa1 = KasaEntity(player, teamColor)
val kasa2 = KasaEntity(player, teamColor)
val kasa3 = KasaEntity(player, teamColor)

kasa1.initialize(location, Vector(0.0, 2.5, 0.0), Vector(0.0, 0.0, 0.0))
kasa2.initialize(location, Vector(0.0, 1.0, 0.0), leftOffset.multiply(1.5))
kasa3.initialize(location, Vector(0.0, 1.0, 0.0), rightOffset.multiply(1.5))

Example of Nested Logic in funnelShot:

for (armorStand in player.world.entities) {
    if (armorStand is ArmorStand) {
        if (armorStand.location.distanceSquared(position) <= maxDistSquad) {
            if (rayTrace.intersects(BoundingBox(armorStand as Entity), 4.0, 0.05)) {
                if (armorStand.customName != null) {
                    if (armorStand.customName == "SplashShield") {
                        // Logic for SplashShield
                    } else if (armorStand.customName == "Kasa") {
                        // Logic for Kasa
                    }
                }
            }
        }
    }
}

OTHER NOTES:

  • The user emphasized the need for minimal changes while improving the code's structure.
  • The refactoring should focus on simplifying logic, extracting reusable methods, and splitting responsibilities into separate classes.
  • The user expects the refactored code to maintain the original functionality and improve maintainability.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…lTask

Co-authored-by: sysnote8main <69232601+sysnote8main@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor and simplify Funnel.kt for better maintainability Refactor Funnel.kt: extract RayTraceHandler, ArmorStandManager, and FunnelTask Mar 9, 2026
@sysnote8main sysnote8main marked this pull request as ready for review March 9, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants