-
Notifications
You must be signed in to change notification settings - Fork 7
Fix memory usage and chunkcache #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d6b2c05
6952825
743151f
0a82893
f499758
ecedd55
35d2da4
52ea90c
bcfb2b9
a632e1f
e6d7ee9
cd5988f
5b1cae7
abb5169
ab3107e
b64bd0d
d5d0b4c
d7da218
c327678
854f750
951fab7
ddd22ad
c97efac
8005e8f
509cf1b
2967f45
21ac55b
acf5f53
b2a43a6
707b3cf
844dbd9
9cc2862
c23163c
e5c2f5f
fe9c89c
6427b1e
fb46122
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| name: Build & Test | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ "**" ] | ||
| pull_request: | ||
| branches: [ "**" ] | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Unit Tests | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Java 17 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
| cache: gradle | ||
|
|
||
| - name: Grant execute permission for gradlew | ||
| run: chmod +x gradlew | ||
|
|
||
| - name: Run tests | ||
| run: ./gradlew test --no-daemon | ||
|
|
||
| - name: Upload test reports | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: test-reports | ||
| path: build/reports/tests/test/ |
|
Trainboy15 marked this conversation as resolved.
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because you've made this PR from your |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,12 @@ public class TuffX extends JavaPlugin implements Listener, PluginMessageListener | |
| public ViaBlocksPlugin viaBlocksPlugin; | ||
| public TuffActions tuffActions; | ||
| public ViaEntitiesPlugin viaEntitiesPlugin; | ||
| public String latestAvailableVersion = null; | ||
|
|
||
| private ChunkInjector chunkInjector; | ||
| private static final String CURRENT_VERSION = "1.0.0-patch"; | ||
| private static final String BUILDS_API_URL = "https://api.github.com/repos/Trainboy15/TuffXPlus/contents/builds"; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've still got a lot of update checker things here that should be in a new PR |
||
|
|
||
| @Override | ||
| public void onLoad() { | ||
|
|
@@ -101,6 +106,8 @@ public void onDisable() { | |
| } | ||
|
|
||
| PacketEvents.getAPI().terminate(); | ||
|
|
||
| getServer().getMessenger().unregisterIncomingPluginChannel(this); | ||
| } | ||
|
|
||
| public void reloadTuffX(){ | ||
|
|
@@ -143,6 +150,25 @@ public boolean TuffXCommand(CommandSender sender, Command command, String label, | |
| return true; | ||
| } | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also this |
||
| // Simple version comparator — handles semver-style and suffix strings | ||
| private int compareVersions(String a, String b) { | ||
| // Strip non-numeric suffixes for comparison (e.g. "1.0.0-patch" → "1.0.0") | ||
| String[] partsA = a.replaceAll("-.*", "").split("\\."); | ||
| String[] partsB = b.replaceAll("-.*", "").split("\\."); | ||
| int len = Math.max(partsA.length, partsB.length); | ||
| for (int i = 0; i < len; i++) { | ||
| int numA = i < partsA.length ? parseIntSafe(partsA[i]) : 0; | ||
| int numB = i < partsB.length ? parseIntSafe(partsB[i]) : 0; | ||
| if (numA != numB) return Integer.compare(numA, numB); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| private int parseIntSafe(String s) { | ||
| try { return Integer.parseInt(s); } catch (NumberFormatException e) { return 0; } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
| if (command.getName().equalsIgnoreCase("tuffx")) return TuffXCommand(sender, command, label, args); | ||
|
|
@@ -180,6 +206,15 @@ public void onBlockFade(BlockFadeEvent e) { | |
| @EventHandler(priority = EventPriority.MONITOR) | ||
| public void onPlayerJoin(PlayerJoinEvent e) { | ||
| y0Plugin.handlePlayerJoin(e); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this |
||
| if (latestAvailableVersion != null) { | ||
| Player p = e.getPlayer(); | ||
| if (p.hasPermission("tuffx.admin") || p.isOp()) { | ||
| p.sendMessage("§e[TuffX] §fA new version is available: §a" + latestAvailableVersion + | ||
| " §f(running §c" + CURRENT_VERSION + "§f)"); | ||
| p.sendMessage("§e[TuffX] §fDownload: §bhttps://github.com/Trainboy15/TuffXPlus/tree/main/builds"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,6 +35,11 @@ | |||||
|
|
||||||
| import tf.tuff.viablocks.version.VersionAdapter; | ||||||
|
|
||||||
| import it.unimi.dsi.fastutil.ints.Int2ObjectMap; | ||||||
| import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; | ||||||
| import it.unimi.dsi.fastutil.longs.LongArrayList; | ||||||
| import it.unimi.dsi.fastutil.longs.LongList; | ||||||
|
|
||||||
| public class CustomBlockListener { | ||||||
|
|
||||||
| public final ViaBlocksPlugin plugin; | ||||||
|
|
@@ -83,6 +88,7 @@ public byte[] getCachedChunkData(String worldName, int x, int z) { | |||||
| } | ||||||
|
|
||||||
| public void setChunkInjector(tf.tuff.netty.ChunkInjector injector) { | ||||||
| if (injector == null) { return; } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is what the meant. It literally doesn’t need a block at all. |
||||||
| this.chunkInjector = injector; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -258,21 +264,30 @@ public void cacheChunkWithCallback(World world, int x, int z, Consumer<byte[]> c | |||||
| } | ||||||
|
|
||||||
| private Map<Integer, List<Long>> findModernBlocksInChunk(ChunkSnapshot chunkSnapshot, int minHeight, int maxHeight) { | ||||||
| Map<Integer, List<Long>> foundBlocks = new HashMap<>(); | ||||||
| Int2ObjectMap<LongList> foundBlocks = new Int2ObjectOpenHashMap<>(); | ||||||
|
|
||||||
| int chunkX = chunkSnapshot.getX() << 4; | ||||||
| int chunkZ = chunkSnapshot.getZ() << 4; | ||||||
|
|
||||||
| for (int y = minHeight; y < maxHeight; y++) { | ||||||
| for (int x = 0; x < 16; x++) { | ||||||
| for (int z = 0; z < 16; z++) { | ||||||
|
|
||||||
| for (int x = 0; x < 16; x++) { | ||||||
| int worldX = chunkX + x; | ||||||
| for (int z = 0; z < 16; z++) { | ||||||
| int worldZ = chunkZ + z; | ||||||
| for (int y = minHeight; y < maxHeight; y++) { | ||||||
|
|
||||||
| // Check material FIRST — getBlockType() returns an enum, no allocation | ||||||
| Material blockType = chunkSnapshot.getBlockType(x, y, z); | ||||||
| if (blockType == Material.AIR || !this.modernMaterials.contains(blockType)) { | ||||||
|
|
||||||
| if (blockType == Material.AIR | ||||||
| || blockType == Material.CAVE_AIR | ||||||
| || blockType == Material.VOID_AIR | ||||||
| || !this.modernMaterials.contains(blockType)) { | ||||||
| continue; | ||||||
| } | ||||||
| @SuppressWarnings("null") | ||||||
| @Nonnull BlockData data = chunkSnapshot.getBlockData(x, y, z); | ||||||
|
|
||||||
| // Only allocate BlockData for confirmed modern blocks | ||||||
| BlockData data = chunkSnapshot.getBlockData(x, y, z); | ||||||
|
|
||||||
| Integer cachedId = blockDataIdCache.getIfPresent(data); | ||||||
| int materialId; | ||||||
| if (cachedId != null) { | ||||||
|
|
@@ -281,22 +296,23 @@ private Map<Integer, List<Long>> findModernBlocksInChunk(ChunkSnapshot chunkSnap | |||||
| materialId = this.paletteManager.getOrCreateId(data.getAsString()); | ||||||
| blockDataIdCache.put(data, materialId); | ||||||
| } | ||||||
|
|
||||||
| if (materialId != -1) { | ||||||
| long packedLocation = packLocation(chunkX + x, y, chunkZ + z); | ||||||
| List<Long> locs = foundBlocks.get(materialId); | ||||||
| long packedLocation = packLocation(worldX, y, worldZ); | ||||||
| LongList locs = foundBlocks.get(materialId); | ||||||
| if (locs == null) { | ||||||
| locs = new ArrayList<>(); | ||||||
| locs = new LongArrayList(); | ||||||
| foundBlocks.put(materialId, locs); | ||||||
| } | ||||||
| locs.add(packedLocation); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| return foundBlocks; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| return (Map<Integer, List<Long>>) (Map<?, ?>) foundBlocks; | ||||||
| } | ||||||
|
|
||||||
| public byte[] getExtraDataForMultiBlock(World world, List<Long> locations) { | ||||||
| Map<Integer, List<Long>> foundBlocks = new HashMap<>(); | ||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.