Skip to content

Fix memory usage and chunkcache#18

Open
Trainboy15 wants to merge 49 commits into
TuffNetwork:mainfrom
Trainboy15:main
Open

Fix memory usage and chunkcache#18
Trainboy15 wants to merge 49 commits into
TuffNetwork:mainfrom
Trainboy15:main

Conversation

@Trainboy15
Copy link
Copy Markdown

@Trainboy15 Trainboy15 commented May 18, 2026

IDK if it works put it compiled so...

Also u might want to add back the deploy to testers repo, but i had to remove it

Summary by CodeRabbit

  • New Features

    • Automated testing infrastructure via CI/CD pipeline now runs tests on code changes.
  • Bug Fixes

    • Plugin now properly cleans up resources during shutdown.
    • Enhanced null-safety checks to prevent potential runtime errors.
  • Tests

    • Comprehensive test suite added to verify plugin functionality.

@Trainboy15
Copy link
Copy Markdown
Author

@UplandJacob If you could test the TuffXPlus-1.0.0-patch that would be great

@bobhenl
Copy link
Copy Markdown

bobhenl commented May 18, 2026

image Still seems to be a bit crazy @Trainboy15

maybe resetting cache more often or not saving so many things to it?
https://spark.lucko.me/JKyN8ssn5p

@Trainboy15
Copy link
Copy Markdown
Author

I agree, it prob shouldent use 24GB, but it seems at least a bit better than 36GB

@Trainboy15 Trainboy15 marked this pull request as draft May 18, 2026 20:45
@bobhenl

This comment was marked as resolved.

@Trainboy15

This comment was marked as resolved.

@Trainboy15

This comment was marked as resolved.

@Trainboy15
Copy link
Copy Markdown
Author

@bobhenl If you could test it now that would be great

@bobhenl
Copy link
Copy Markdown

bobhenl commented May 19, 2026

where can be the build downloaded btw, I don't see it in actions

@Trainboy15
Copy link
Copy Markdown
Author

@Trainboy15 Trainboy15 marked this pull request as ready for review May 21, 2026 17:17
@bobhenl
Copy link
Copy Markdown

bobhenl commented May 22, 2026

image btw is it checking just eagler players? https://spark.lucko.me/pvGBrzMdbI image https://spark.lucko.me/CfTf6fEcPk image

@Trainboy15
Copy link
Copy Markdown
Author

Not sure 100%. will look into it

Comment thread src/main/java/tf/tuff/viablocks/CustomBlockListener.java Outdated
Comment thread src/main/java/tf/tuff/TuffX.java Outdated
Comment thread src/main/java/tf/tuff/TuffX.java Outdated
Comment thread src/main/java/tf/tuff/TuffX.java Outdated
Comment thread builds/TuffXPlus-1.0.1-beta.jar
@Trainboy15 Trainboy15 marked this pull request as draft May 26, 2026 13:01
@Trainboy15 Trainboy15 marked this pull request as ready for review May 29, 2026 14:50
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 29f5d705-c48b-495c-9a92-1eea5d2a9c1a

📥 Commits

Reviewing files that changed from the base of the PR and between 126fd78 and 7a8a860.

📒 Files selected for processing (1)
  • src/test/TuffXTest.java
💤 Files with no reviewable changes (1)
  • src/test/TuffXTest.java

📝 Walkthrough

Walkthrough

This PR adds test infrastructure, improves plugin robustness through null-safety checks and lifecycle cleanup, optimizes chunk processing with fastutil collections and refactored payload serialization, and introduces a test suite using MockBukkit to validate core plugin behaviors.

Changes

Testing Infrastructure and Plugin Improvements

Layer / File(s) Summary
Testing Infrastructure Setup
.github/workflows/test.yml, build.gradle
GitHub Actions CI workflow runs tests on push and pull request with Java 17 and Gradle caching. Build configuration adds MockBukkit and JUnit Jupiter dependencies from a new Maven repository, and introduces a test task with JUnit Platform support and detailed test logging.
Plugin Robustness and Lifecycle Management
src/main/java/tf/tuff/TuffX.java, src/main/java/tf/tuff/viablocks/CustomBlockListener.java, src/main/java/tf/tuff/y0/Y0Plugin.java
Plugin shutdown now explicitly unregisters incoming plugin message channels before terminating PacketEvents. Both CustomBlockListener and Y0Plugin prevent null assignments to chunkInjector by returning early when a null injector is provided.
Chunk Processing Optimization
src/main/java/tf/tuff/viablocks/CustomBlockListener.java, src/main/java/tf/tuff/y0/Y0Plugin.java
CustomBlockListener refactors findModernBlocksInChunk to use fastutil Int2ObjectMap and LongList instead of HashMap and ArrayList, expands air-block detection to include CAVE_AIR and VOID_AIR. Y0Plugin rewrites createSectionPayload with optimized loop traversal, explicit null-check caching strategy, and try-with-resources buffer serialization.
Plugin Behavior Validation Tests
src/test/TuffXTest.java
New JUnit 5 test class using MockBukkit to verify plugin enablement after load and safe completion of the reload operation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Tests now run on every push,
With null-guards and fastutil rush,
Chunks process quick, payloads refined,
Plugin safety and speed combined.
hops away satisfied

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix memory usage and chunkcache' directly addresses the PR's core objectives: reducing memory consumption and modifying chunk cache behavior, which are evident from the code changes and test discussions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/test.yml:
- Around line 15-16: The checkout step currently uses actions/checkout@v4
without disabling token persistence; update the Checkout repository step
(actions/checkout) to set persist-credentials: false so the GitHub token is not
written to local git config during this job. Locate the step that uses
actions/checkout@v4 and add the persist-credentials: false option under that
step's with: block.
- Around line 15-16: Replace floating version tags for GitHub Actions with full
commit SHAs: update each uses: entry (e.g., uses: actions/checkout@v4 and the
other uses: lines flagged at 19 and 33) to reference the corresponding action's
full commit SHA (for example actions/checkout@<full-sha>) by looking up the
canonical commit for the tagged release in the action's GitHub repo and
substituting the tag with that SHA so the workflow is pinned to an immutable
commit.

In `@src/main/java/tf/tuff/TuffX.java`:
- Around line 103-105: TuffX currently only calls
PacketEvents.getAPI().terminate() and unregisters incoming channels via
getServer().getMessenger().unregisterIncomingPluginChannel(this); update
TuffX.shutdown/disable logic to explicitly unregister any plugin channels that
other classes register by calling
getServer().getMessenger().unregisterOutgoingPluginChannel(...) and
getServer().getMessenger().unregisterIncomingPluginChannel(...) for the exact
channel names used in Y0Plugin (the channels registered in Y0Plugin.register...
at the Y0Plugin class) and in TuffActions (the channels registered in
TuffActions at its register calls), ensuring every
registerOutgoing/registerIncoming has a matching unregister to prevent
“registration already exists” on reload.

In `@src/test/TuffXTest.java`:
- Around line 31-65: Tests reference plugin.latestAvailableVersion but TuffX has
no such member, causing compile failures; add a package-visible String field
named latestAvailableVersion to class TuffX (initialize to null) so tests can
read/write it, and update any existing update-check logic (e.g., the method that
detects versions) to assign to this field when an available version is found;
alternatively, expose equivalent package-visible getter/setter on TuffX with the
name latestAvailableVersion so the tests can access the value.
- Around line 1-10: The test class TuffXTest is outside Gradle’s default test
source set; move the file TuffXTest (which declares package tf.tuff) into the
standard test directory so its path matches the package
(src/test/java/tf/tuff/TuffXTest.java) or alternatively update Gradle’s
sourceSets configuration to include its current location; ensure the package
declaration remains tf.tuff and that the class name TuffXTest and imports are
unchanged so JUnit (test { useJUnitPlatform() }) will run it in CI.
🪄 Autofix (Beta)

❌ Autofix failed (check again to retry)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d161060d-7acd-4b1c-9979-16b6cd9cd31d

📥 Commits

Reviewing files that changed from the base of the PR and between a20afff and 126fd78.

⛔ Files ignored due to path filters (1)
  • builds/TuffXPlus-1.0.1-beta.jar is excluded by !**/*.jar
📒 Files selected for processing (6)
  • .github/workflows/test.yml
  • build.gradle
  • src/main/java/tf/tuff/TuffX.java
  • src/main/java/tf/tuff/viablocks/CustomBlockListener.java
  • src/main/java/tf/tuff/y0/Y0Plugin.java
  • src/test/TuffXTest.java

Comment on lines +15 to +16
- name: Checkout repository
uses: actions/checkout@v4
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Disable credential persistence on checkout.

This job only builds, tests, and uploads artifacts, so keeping the GitHub token in the local git config is unnecessary. Set persist-credentials: false on actions/checkout to narrow the workflow’s credential exposure.

🧰 Tools
🪛 zizmor (1.25.2)

[warning] 15-16: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)


[error] 16-16: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/test.yml around lines 15 - 16, The checkout step currently
uses actions/checkout@v4 without disabling token persistence; update the
Checkout repository step (actions/checkout) to set persist-credentials: false so
the GitHub token is not written to local git config during this job. Locate the
step that uses actions/checkout@v4 and add the persist-credentials: false option
under that step's with: block.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Pin every GitHub Action to a full commit SHA.

These uses: entries are still floating on major tags, so the workflow can pick up upstream changes without a PR here. That weakens the CI trust boundary and also matches the current static-analysis failure.

Also applies to: 19-19, 33-33

🧰 Tools
🪛 zizmor (1.25.2)

[warning] 15-16: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)


[error] 16-16: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/test.yml around lines 15 - 16, Replace floating version
tags for GitHub Actions with full commit SHAs: update each uses: entry (e.g.,
uses: actions/checkout@v4 and the other uses: lines flagged at 19 and 33) to
reference the corresponding action's full commit SHA (for example
actions/checkout@<full-sha>) by looking up the canonical commit for the tagged
release in the action's GitHub repo and substituting the tag with that SHA so
the workflow is pinned to an immutable commit.

Comment on lines 103 to +105
PacketEvents.getAPI().terminate();

getServer().getMessenger().unregisterIncomingPluginChannel(this);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Plugin message registrations:"
rg -n --type=java 'register(Incoming|Outgoing)PluginChannel|unregister(Incoming|Outgoing)PluginChannel' src

echo
echo "Expected: every registerOutgoingPluginChannel(...) has a matching unregisterOutgoingPluginChannel(...) on the disable path."

Repository: TuffNetwork/TuffXPlus

Length of output: 2239


Fix plugin-channel teardown: TuffX only unregisters incoming; missing outgoing/incoming unregisters are in Y0Plugin and TuffActions.

  • src/main/java/tf/tuff/TuffX.java:105 calls only getServer().getMessenger().unregisterIncomingPluginChannel(this) and TuffX has no registerOutgoingPluginChannel(...) usage, so “mirror outgoing cleanup here” doesn’t apply.
  • Ensure matching unregisterOutgoingPluginChannel(...) / unregisterIncomingPluginChannel(...) for the channels registered in:
    • src/main/java/tf/tuff/y0/Y0Plugin.java:232-233
    • src/main/java/tf/tuff/tuffactions/TuffActions.java:68-69 (missing any corresponding unregisters can trigger “registration already exists” on reload).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/tf/tuff/TuffX.java` around lines 103 - 105, TuffX currently
only calls PacketEvents.getAPI().terminate() and unregisters incoming channels
via getServer().getMessenger().unregisterIncomingPluginChannel(this); update
TuffX.shutdown/disable logic to explicitly unregister any plugin channels that
other classes register by calling
getServer().getMessenger().unregisterOutgoingPluginChannel(...) and
getServer().getMessenger().unregisterIncomingPluginChannel(...) for the exact
channel names used in Y0Plugin (the channels registered in Y0Plugin.register...
at the Y0Plugin class) and in TuffActions (the channels registered in
TuffActions at its register calls), ensuring every
registerOutgoing/registerIncoming has a matching unregister to prevent
“registration already exists” on reload.

Comment thread src/test/TuffXTest.java
Comment on lines +1 to +10
package tf.tuff;

import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
import be.seeseemelk.mockbukkit.entity.PlayerMock;
import org.junit.jupiter.api.*;

import static org.junit.jupiter.api.Assertions.*;

class TuffXTest {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Test file location:"
fd -p 'TuffXTest.java'

echo
echo "Gradle source-set configuration:"
rg -n 'sourceSets|useJUnitPlatform|test \{' build.gradle settings.gradle gradle.properties 2>/dev/null || true

echo
echo "Expected: either the test file lives under src/test/java/... or build.gradle defines a custom test source set that includes src/test."

Repository: TuffNetwork/TuffXPlus

Length of output: 340


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== build.gradle lines 70-120 =="
sed -n '70,120p' build.gradle

echo
echo "== Any sourceSets configuration in repo (limited to build.gradle/gradle/*.gradle) =="
rg -n "sourceSets" -S . || true

echo
echo "== List of Java test files under src/test =="
fd -e java . src/test 2>/dev/null | head -n 200

Repository: TuffNetwork/TuffXPlus

Length of output: 696


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Test file location:"
fd -p 'TuffXTest.java'

echo
echo "Gradle source-set configuration:"
rg -n 'sourceSets|sourceDirs|test \{' build.gradle settings.gradle gradle.properties 2>/dev/null || true

echo
echo "Expected: either the test file lives under src/test/java/... or build.gradle defines a custom test source set/sourceDirs including src/test."

Repository: TuffNetwork/TuffXPlus

Length of output: 308


Move TuffXTest into Gradle’s active test source set (src/test/java).

src/test/TuffXTest.java is not under src/test/java, and build.gradle only configures test { useJUnitPlatform() } with no sourceSets override—so this test can be skipped entirely in CI. Also, since it declares package tf.tuff;, it should be located at src/test/java/tf/tuff/TuffXTest.java.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/TuffXTest.java` around lines 1 - 10, The test class TuffXTest is
outside Gradle’s default test source set; move the file TuffXTest (which
declares package tf.tuff) into the standard test directory so its path matches
the package (src/test/java/tf/tuff/TuffXTest.java) or alternatively update
Gradle’s sourceSets configuration to include its current location; ensure the
package declaration remains tf.tuff and that the class name TuffXTest and
imports are unchanged so JUnit (test { useJUnitPlatform() }) will run it in CI.

Comment thread src/test/TuffXTest.java Outdated
@TuffNetwork TuffNetwork deleted a comment from coderabbitai Bot Jun 3, 2026
@TuffNetwork TuffNetwork deleted a comment from coderabbitai Bot Jun 3, 2026
@Trainboy15 Trainboy15 marked this pull request as draft June 3, 2026 14:37
@Trainboy15 Trainboy15 marked this pull request as ready for review June 3, 2026 14:38
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.

3 participants