From 6859d9bc10b3b709020be187926b161e05299ddc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 25 May 2021 12:49:38 +0200 Subject: [PATCH] Fix SWCommand --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 7c095f6..1753470 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -28,6 +28,7 @@ import org.bukkit.scheduler.BukkitRunnable; import java.lang.annotation.*; import java.lang.reflect.*; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.IntPredicate; @@ -151,16 +152,19 @@ public abstract class SWCommand { if (!field.getType().getTypeName().equals("de.steamwar.message.Message")) { return; } - Object o = Modifier.isStatic(field.getModifiers()) ? field.get(null) : field.get(this); + AtomicReference o = new AtomicReference<>(null); Method method = o.getClass().getMethod("parse"); message = (s, commandSender) -> { try { - return (String) method.invoke(o, s, commandSender); + if (o.get() == null) { + o.set(Modifier.isStatic(field.getModifiers()) ? field.get(null) : field.get(this)); + } + return (String) method.invoke(o.get(), s, commandSender); } catch (IllegalAccessException | InvocationTargetException e) { return s; } }; - } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException e) { + } catch (NoSuchFieldException | NoSuchMethodException e) { // Ignored } }