From 296e82a1b8c4a0d7b03340397236857f07b31a9b Mon Sep 17 00:00:00 2001 From: Lilly Tempest <46890129+rainbowdashlabs@users.noreply.github.com> Date: Fri, 26 Jan 2024 13:51:06 +0100 Subject: [PATCH] Fix: rendering npe (#356) * Update version number in build.gradle.kts The version number in the build.gradle.kts file was updated from 2.6.0 to 2.6.1. This minor version update likely includes bug fixes or very small changes that do not substantially alter the functionality of the project. * Refactor PacketWorker's remove method The remove method in PacketWorker has been simplified. The comparison of player unique identifiers is now done in a single line, eliminating the repetitive and more complex boolean logic that existed before, making the code cleaner and easier to understand. * Refactor resolveBlocked method in RenderService class The resolveBlocked method in RenderService class has been refactored. We removed the process method and added the remove method from worker object, making the code easier to reason about. This also fixes the issue where playerSink object might not have been correctly updated before performing the remove operation. --- build.gradle.kts | 2 +- .../schematicbrush/rendering/PacketWorker.java | 12 +----------- .../schematicbrush/rendering/RenderService.java | 2 +- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8977c306..cb7b079e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "de.eldoria" -version = "2.6.0" +version = "2.6.1" var publishModules = setOf("schematicbrushreborn-api", "schematicbrushreborn-core", diff --git a/schematicbrushreborn-core/src/main/java/de/eldoria/schematicbrush/rendering/PacketWorker.java b/schematicbrushreborn-core/src/main/java/de/eldoria/schematicbrush/rendering/PacketWorker.java index 302c0a11..149a2f8a 100644 --- a/schematicbrushreborn-core/src/main/java/de/eldoria/schematicbrush/rendering/PacketWorker.java +++ b/schematicbrushreborn-core/src/main/java/de/eldoria/schematicbrush/rendering/PacketWorker.java @@ -81,17 +81,7 @@ public void queue(RenderSink renderSink) { public void remove(Player player) { - queue.removeIf(e -> e.sinkOwner().equals(player.getUniqueId())); - } - - public void process(Player player) { - queue.removeIf(e -> { - if (e.sinkOwner().equals(player.getUniqueId())) { - e.sendChanges(); - return true; - } - return false; - }); + queue.removeIf(e -> e == null || e.sinkOwner().equals(player.getUniqueId())); } public int packetQueueCount() { diff --git a/schematicbrushreborn-core/src/main/java/de/eldoria/schematicbrush/rendering/RenderService.java b/schematicbrushreborn-core/src/main/java/de/eldoria/schematicbrush/rendering/RenderService.java index 77ced588..b54f76f2 100644 --- a/schematicbrushreborn-core/src/main/java/de/eldoria/schematicbrush/rendering/RenderService.java +++ b/schematicbrushreborn-core/src/main/java/de/eldoria/schematicbrush/rendering/RenderService.java @@ -105,8 +105,8 @@ public void onPrePaste(PrePasteEvent event) { * @param player player to resolve */ private void resolveBlocked(Player player) { - worker.process(player); RenderSink playerSink = getSink(player); + worker.remove(player); // We push and send empty changes playerSink.pushAndSend(null); //getChanges(player).ifPresent(change -> new PaketWorker.ChangeEntry(player, change, null).sendChanges());