From fd17b8315f6bd1bf45f4b6b2769744a4be18a2b1 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Mon, 22 Apr 2024 19:58:34 +0200 Subject: [PATCH 1/2] Fix trace Rserver null error ? --- .../steamwar/bausystem/features/tracer/Trace.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java index c46a1df3..f2f896c4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java @@ -188,7 +188,20 @@ public class Trace { * @param playerTraceShowData The showData for modifying the rendering */ protected void render(List records, Player player, PlayerTraceShowData playerTraceShowData) { - render(records, entityServerMap.get(player), playerTraceShowData); + REntityServer entityServer = entityServerMap.get(player); + if (entityServer == null) { + entityServer = new REntityServer(); + entityServer.addPlayer(player); + entityServer.setCallback((p, rEntity, entityAction) -> { + if (entityAction != REntityServer.EntityAction.INTERACT) return; + if (rEntity instanceof TraceEntity) { + ((TraceEntity) rEntity).printIntoChat(p); + } + }); + entityServerMap.put(player, entityServer); + } + + render(records, entityServer, playerTraceShowData); } /** From b602fb06d05c0416eac579b256a457645e101e00 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Mon, 22 Apr 2024 20:27:34 +0200 Subject: [PATCH 2/2] Used Compute if absent --- .../steamwar/bausystem/features/tracer/Trace.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java index f2f896c4..1706bca0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java @@ -188,18 +188,17 @@ public class Trace { * @param playerTraceShowData The showData for modifying the rendering */ protected void render(List records, Player player, PlayerTraceShowData playerTraceShowData) { - REntityServer entityServer = entityServerMap.get(player); - if (entityServer == null) { - entityServer = new REntityServer(); - entityServer.addPlayer(player); - entityServer.setCallback((p, rEntity, entityAction) -> { + REntityServer entityServer = entityServerMap.computeIfAbsent(player, k -> { + REntityServer newEntityServer = new REntityServer(); + newEntityServer.addPlayer(k); + newEntityServer.setCallback((p, rEntity, entityAction) -> { if (entityAction != REntityServer.EntityAction.INTERACT) return; if (rEntity instanceof TraceEntity) { ((TraceEntity) rEntity).printIntoChat(p); } }); - entityServerMap.put(player, entityServer); - } + return newEntityServer; + }); render(records, entityServer, playerTraceShowData); }