From f933d1321f64ce52d816ba02a4537e0833cf0b53 Mon Sep 17 00:00:00 2001 From: bivashy Date: Sat, 17 Feb 2024 20:19:37 +0600 Subject: [PATCH 1/8] Include minecraft-libraries repository --- settings.gradle | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/settings.gradle b/settings.gradle index 3e856a46..69522c11 100644 --- a/settings.gradle +++ b/settings.gradle @@ -33,6 +33,13 @@ dependencyResolutionManagement { includeGroup "com.destroystokyo.paper" } } + maven { + name "minecraft-libraries" + url "https://libraries.minecraft.net" + mavenContent { + includeGroup "com.mojang" + } + } } } From 53bf72f095db5b812ab1c594bb1e28cd026ee311 Mon Sep 17 00:00:00 2001 From: bivashy Date: Sat, 17 Feb 2024 20:24:25 +0600 Subject: [PATCH 2/8] Switch to BaseComponent in BossBar#setTitle for API compatibility --- .../net/kyori/adventure/platform/bungeecord/BungeeFacet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java index 96ad3220..69b1d513 100644 --- a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java +++ b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java @@ -44,9 +44,9 @@ import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.Connection; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.chat.TranslationRegistry; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -255,7 +255,7 @@ public void bossBarInitialized(final net.kyori.adventure.bossbar.@NotNull BossBa @Override public void bossBarNameChanged(final net.kyori.adventure.bossbar.@NotNull BossBar bar, final @NotNull Component oldName, final @NotNull Component newName) { if (!this.viewers.isEmpty()) { - this.bar.setTitle(ComponentSerializer.toString(this.createMessage(this.viewers.iterator().next(), newName))); + this.bar.setTitle(TextComponent.fromArray(this.createMessage(this.viewers.iterator().next(), newName))); this.broadcastPacket(ACTION_TITLE); } } From d36cd91799257a45a6febd1ba10408bdb849c7db Mon Sep 17 00:00:00 2001 From: bivashy Date: Sat, 17 Feb 2024 20:24:53 +0600 Subject: [PATCH 3/8] Bump BungeeCord version --- platform-bungeecord/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-bungeecord/build.gradle b/platform-bungeecord/build.gradle index aad0af0b..56a2736a 100644 --- a/platform-bungeecord/build.gradle +++ b/platform-bungeecord/build.gradle @@ -6,5 +6,5 @@ dependencies { } implementation project(":adventure-platform-facet") api project(":adventure-text-serializer-bungeecord") - compileOnly 'net.md-5:bungeecord-api:1.16-R0.4' + compileOnly 'net.md-5:bungeecord-api:1.20-R0.2' } From 7f4dc01f30a1d484f724adae5701de35203e4970 Mon Sep 17 00:00:00 2001 From: bivashy Date: Sun, 18 Feb 2024 19:13:35 +0600 Subject: [PATCH 4/8] Ensure backward compatibility when updating bossbar title --- .../platform/bungeecord/BungeeFacet.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java index 69b1d513..9c9d2ec4 100644 --- a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java +++ b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java @@ -23,6 +23,8 @@ */ package net.kyori.adventure.platform.bungeecord; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.Collection; import java.util.Set; import java.util.UUID; @@ -47,6 +49,7 @@ import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.Connection; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.chat.TranslationRegistry; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -255,11 +258,28 @@ public void bossBarInitialized(final net.kyori.adventure.bossbar.@NotNull BossBa @Override public void bossBarNameChanged(final net.kyori.adventure.bossbar.@NotNull BossBar bar, final @NotNull Component oldName, final @NotNull Component newName) { if (!this.viewers.isEmpty()) { - this.bar.setTitle(TextComponent.fromArray(this.createMessage(this.viewers.iterator().next(), newName))); + BaseComponent[] message = this.createMessage(this.viewers.iterator().next(), newName); + updateBarTitle(message); this.broadcastPacket(ACTION_TITLE); } } + private void updateBarTitle(BaseComponent[] message) { + if (!tryUpdateTitleWithMethod("setTitle", String.class, ComponentSerializer.toString(message))) { + tryUpdateTitleWithMethod("setTitle", BaseComponent.class, TextComponent.fromArray(message)); + } + } + + private boolean tryUpdateTitleWithMethod(String methodName, Class parameterType, Object argument) { + try { + Method setTitleMethod = net.md_5.bungee.protocol.packet.BossBar.class.getMethod(methodName, parameterType); + setTitleMethod.invoke(this.bar, argument); + return true; + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + return false; + } + } + @Override public void bossBarProgressChanged(final net.kyori.adventure.bossbar.@NotNull BossBar bar, final float oldPercent, final float newPercent) { this.bar.setHealth(newPercent); From 2e8fbf576a06c4ad2bfd8487e15374ef972b31f0 Mon Sep 17 00:00:00 2001 From: bivashy Date: Mon, 19 Feb 2024 20:44:31 +0600 Subject: [PATCH 5/8] Use MethodHandles.lookup() to invoke BossBar#setTitle --- .../platform/bungeecord/BungeeFacet.java | 40 +++++++----- .../platform/bungeecord/BungeeReflection.java | 62 +++++++++++++++++++ 2 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java diff --git a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java index 9c9d2ec4..bfdb5e63 100644 --- a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java +++ b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java @@ -23,8 +23,7 @@ */ package net.kyori.adventure.platform.bungeecord; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import java.lang.invoke.MethodHandle; import java.util.Collection; import java.util.Set; import java.util.UUID; @@ -54,6 +53,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static net.kyori.adventure.platform.bungeecord.BungeeReflection.findMethod; +import static net.kyori.adventure.platform.bungeecord.BungeeReflection.hasMethod; +import static net.kyori.adventure.platform.facet.Knob.logError; import static net.kyori.adventure.platform.facet.Knob.logUnsupported; class BungeeFacet extends FacetBase { @@ -222,6 +224,18 @@ public void resetTitle(final @NotNull ProxiedPlayer viewer) { } static class BossBar extends Message implements BossBarPacket { + private static MethodHandle SET_TITLE_STRING; + private static MethodHandle SET_TITLE_COMPONENT; + + static { + Class bossBarClass = net.md_5.bungee.protocol.packet.BossBar.class; + if (hasMethod(bossBarClass, "setTitle", String.class)) { + SET_TITLE_STRING = findMethod(bossBarClass, "setTitle", void.class, String.class); + } else { + SET_TITLE_COMPONENT = findMethod(bossBarClass, "setTitle", void.class, BaseComponent.class); + } + } + private final Set viewers; private final net.md_5.bungee.protocol.packet.BossBar bar; private volatile boolean initialized = false; @@ -265,19 +279,15 @@ public void bossBarNameChanged(final net.kyori.adventure.bossbar.@NotNull BossBa } private void updateBarTitle(BaseComponent[] message) { - if (!tryUpdateTitleWithMethod("setTitle", String.class, ComponentSerializer.toString(message))) { - tryUpdateTitleWithMethod("setTitle", BaseComponent.class, TextComponent.fromArray(message)); - } - } - - private boolean tryUpdateTitleWithMethod(String methodName, Class parameterType, Object argument) { - try { - Method setTitleMethod = net.md_5.bungee.protocol.packet.BossBar.class.getMethod(methodName, parameterType); - setTitleMethod.invoke(this.bar, argument); - return true; - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - return false; - } + try { + if (SET_TITLE_STRING != null) { + SET_TITLE_STRING.invoke(ComponentSerializer.toString(message)); + } else { + SET_TITLE_COMPONENT.invoke(TextComponent.fromArray(message)); + } + } catch (Throwable throwable) { + logError(throwable, "Cannot update the BossBar title"); + } } @Override diff --git a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java new file mode 100644 index 00000000..f5bd6ad0 --- /dev/null +++ b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java @@ -0,0 +1,62 @@ +package net.kyori.adventure.platform.bungeecord; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Reflection utilities for accessing legacy BungeeCord methods + */ +public class BungeeReflection { + + private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); + + private BungeeReflection() { + } + + /** + * Checks if the specified class has a method with the given name and parameter types. + * + * @param holderClass The class to check for the method. Can be {@code null}, in which case the method returns {@code false}. + * @param methodName The name of the method to check for. + * @param parameters The parameter types of the method. The method returns {@code false} if any parameter type is {@code null}. + * @return {@code true} if the method exists in the class; {@code false} otherwise. + */ + public static boolean hasMethod(final @Nullable Class holderClass, final String methodName, final Class... parameters) { + if (holderClass == null) return false; + for (Class parameter : parameters) { + if (parameter == null) return false; + } + try { + holderClass.getMethod(methodName, parameters); + return true; + } catch (NoSuchMethodException ignored) { + } + return false; + } + + /** + * Finds and returns a {@link MethodHandle} for the specified method of the given class. This allows for dynamic method invocation. + * + * @param holderClass The class containing the method. + * @param methodName The name of the method to find. + * @param returnType The return type of the method. + * @param parameters The parameter types of the method. + * @return A {@link MethodHandle} for the specified method, or {@code null} if the method cannot be found or if any parameter is {@code null}. + */ + public static MethodHandle findMethod(final @Nullable Class holderClass, final String methodName, final Class returnType, final Class... parameters) { + if (holderClass == null || returnType == null) return null; + for (Class parameter : parameters) { + if (parameter == null) return null; + } + try { + return LOOKUP.findVirtual(holderClass, methodName, MethodType.methodType(returnType, parameters)); + } catch (NoSuchMethodException | IllegalAccessException ignored) { + } + return null; + } + +} From de6e761bad4d6ddf63fdb3d7d5c825c88a0488a8 Mon Sep 17 00:00:00 2001 From: bivashy Date: Thu, 29 Feb 2024 21:48:36 +0600 Subject: [PATCH 6/8] Match code formatting with rest of the codebase --- .../platform/bungeecord/BungeeFacet.java | 38 ++++---- .../platform/bungeecord/BungeeReflection.java | 87 +++++++++---------- 2 files changed, 62 insertions(+), 63 deletions(-) diff --git a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java index bfdb5e63..da4e3dde 100644 --- a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java +++ b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java @@ -228,12 +228,12 @@ static class BossBar extends Message implements BossBarPacket { private static MethodHandle SET_TITLE_COMPONENT; static { - Class bossBarClass = net.md_5.bungee.protocol.packet.BossBar.class; - if (hasMethod(bossBarClass, "setTitle", String.class)) { - SET_TITLE_STRING = findMethod(bossBarClass, "setTitle", void.class, String.class); - } else { - SET_TITLE_COMPONENT = findMethod(bossBarClass, "setTitle", void.class, BaseComponent.class); - } + Class bossBarClass = net.md_5.bungee.protocol.packet.BossBar.class; + if (hasMethod(bossBarClass, "setTitle", String.class)) { + SET_TITLE_STRING = findMethod(bossBarClass, "setTitle", void.class, String.class); + } else { + SET_TITLE_COMPONENT = findMethod(bossBarClass, "setTitle", void.class, BaseComponent.class); + } } private final Set viewers; @@ -273,23 +273,11 @@ public void bossBarInitialized(final net.kyori.adventure.bossbar.@NotNull BossBa public void bossBarNameChanged(final net.kyori.adventure.bossbar.@NotNull BossBar bar, final @NotNull Component oldName, final @NotNull Component newName) { if (!this.viewers.isEmpty()) { BaseComponent[] message = this.createMessage(this.viewers.iterator().next(), newName); - updateBarTitle(message); + this.updateBarTitle(message); this.broadcastPacket(ACTION_TITLE); } } - private void updateBarTitle(BaseComponent[] message) { - try { - if (SET_TITLE_STRING != null) { - SET_TITLE_STRING.invoke(ComponentSerializer.toString(message)); - } else { - SET_TITLE_COMPONENT.invoke(TextComponent.fromArray(message)); - } - } catch (Throwable throwable) { - logError(throwable, "Cannot update the BossBar title"); - } - } - @Override public void bossBarProgressChanged(final net.kyori.adventure.bossbar.@NotNull BossBar bar, final float oldPercent, final float newPercent) { this.bar.setHealth(newPercent); @@ -348,6 +336,18 @@ private void broadcastPacket(final int action) { } } + private void updateBarTitle(BaseComponent[] message) { + try { + if (SET_TITLE_STRING != null) { + SET_TITLE_STRING.invoke(ComponentSerializer.toString(message)); + } else { + SET_TITLE_COMPONENT.invoke(TextComponent.fromArray(message)); + } + } catch (Throwable throwable) { + logError(throwable, "Cannot update the BossBar title"); + } + } + private void sendPacket(final int action, final ProxiedPlayer... viewers) { synchronized (this.bar) { final int lastAction = this.bar.getAction(); diff --git a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java index f5bd6ad0..9bf96151 100644 --- a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java +++ b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java @@ -4,7 +4,6 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -12,51 +11,51 @@ */ public class BungeeReflection { - private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); - - private BungeeReflection() { + private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); + + private BungeeReflection() { + } + + /** + * Checks if the specified class has a method with the given name and parameter types. + * + * @param holderClass The class to check for the method. Can be {@code null}, in which case the method returns {@code false}. + * @param methodName The name of the method to check for. + * @param parameters The parameter types of the method. The method returns {@code false} if any parameter type is {@code null}. + * @return {@code true} if the method exists in the class; {@code false} otherwise. + */ + public static boolean hasMethod(final @Nullable Class holderClass, final String methodName, final Class... parameters) { + if (holderClass == null) return false; + for (Class parameter : parameters) { + if (parameter == null) return false; } - - /** - * Checks if the specified class has a method with the given name and parameter types. - * - * @param holderClass The class to check for the method. Can be {@code null}, in which case the method returns {@code false}. - * @param methodName The name of the method to check for. - * @param parameters The parameter types of the method. The method returns {@code false} if any parameter type is {@code null}. - * @return {@code true} if the method exists in the class; {@code false} otherwise. - */ - public static boolean hasMethod(final @Nullable Class holderClass, final String methodName, final Class... parameters) { - if (holderClass == null) return false; - for (Class parameter : parameters) { - if (parameter == null) return false; - } - try { - holderClass.getMethod(methodName, parameters); - return true; - } catch (NoSuchMethodException ignored) { - } - return false; + try { + holderClass.getMethod(methodName, parameters); + return true; + } catch (NoSuchMethodException ignored) { } - - /** - * Finds and returns a {@link MethodHandle} for the specified method of the given class. This allows for dynamic method invocation. - * - * @param holderClass The class containing the method. - * @param methodName The name of the method to find. - * @param returnType The return type of the method. - * @param parameters The parameter types of the method. - * @return A {@link MethodHandle} for the specified method, or {@code null} if the method cannot be found or if any parameter is {@code null}. - */ - public static MethodHandle findMethod(final @Nullable Class holderClass, final String methodName, final Class returnType, final Class... parameters) { - if (holderClass == null || returnType == null) return null; - for (Class parameter : parameters) { - if (parameter == null) return null; - } - try { - return LOOKUP.findVirtual(holderClass, methodName, MethodType.methodType(returnType, parameters)); - } catch (NoSuchMethodException | IllegalAccessException ignored) { - } - return null; + return false; + } + + /** + * Finds and returns a {@link MethodHandle} for the specified method of the given class. This allows for dynamic method invocation. + * + * @param holderClass The class containing the method. + * @param methodName The name of the method to find. + * @param returnType The return type of the method. + * @param parameters The parameter types of the method. + * @return A {@link MethodHandle} for the specified method, or {@code null} if the method cannot be found or if any parameter is {@code null}. + */ + public static MethodHandle findMethod(final @Nullable Class holderClass, final String methodName, final Class returnType, final Class... parameters) { + if (holderClass == null || returnType == null) return null; + for (Class parameter : parameters) { + if (parameter == null) return null; + } + try { + return LOOKUP.findVirtual(holderClass, methodName, MethodType.methodType(returnType, parameters)); + } catch (NoSuchMethodException | IllegalAccessException ignored) { } + return null; + } } From 5964a611bd273bb264642b3061550faaf5060014 Mon Sep 17 00:00:00 2001 From: bivashy Date: Mon, 4 Mar 2024 17:53:38 +0500 Subject: [PATCH 7/8] Fix code format violations --- .../platform/bungeecord/BungeeFacet.java | 8 ++-- .../platform/bungeecord/BungeeReflection.java | 39 ++++++++++++++----- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java index da4e3dde..e036c153 100644 --- a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java +++ b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java @@ -228,7 +228,7 @@ static class BossBar extends Message implements BossBarPacket { private static MethodHandle SET_TITLE_COMPONENT; static { - Class bossBarClass = net.md_5.bungee.protocol.packet.BossBar.class; + final Class bossBarClass = net.md_5.bungee.protocol.packet.BossBar.class; if (hasMethod(bossBarClass, "setTitle", String.class)) { SET_TITLE_STRING = findMethod(bossBarClass, "setTitle", void.class, String.class); } else { @@ -272,7 +272,7 @@ public void bossBarInitialized(final net.kyori.adventure.bossbar.@NotNull BossBa @Override public void bossBarNameChanged(final net.kyori.adventure.bossbar.@NotNull BossBar bar, final @NotNull Component oldName, final @NotNull Component newName) { if (!this.viewers.isEmpty()) { - BaseComponent[] message = this.createMessage(this.viewers.iterator().next(), newName); + final BaseComponent[] message = this.createMessage(this.viewers.iterator().next(), newName); this.updateBarTitle(message); this.broadcastPacket(ACTION_TITLE); } @@ -336,14 +336,14 @@ private void broadcastPacket(final int action) { } } - private void updateBarTitle(BaseComponent[] message) { + private void updateBarTitle(final BaseComponent[] message) { try { if (SET_TITLE_STRING != null) { SET_TITLE_STRING.invoke(ComponentSerializer.toString(message)); } else { SET_TITLE_COMPONENT.invoke(TextComponent.fromArray(message)); } - } catch (Throwable throwable) { + } catch (final Throwable throwable) { logError(throwable, "Cannot update the BossBar title"); } } diff --git a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java index 9bf96151..f263a200 100644 --- a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java +++ b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeReflection.java @@ -1,21 +1,42 @@ +/* + * This file is part of adventure-platform, licensed under the MIT License. + * + * Copyright (c) 2018-2020 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package net.kyori.adventure.platform.bungeecord; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; - import org.jetbrains.annotations.Nullable; /** - * Reflection utilities for accessing legacy BungeeCord methods + * Reflection utilities for accessing legacy BungeeCord methods. */ -public class BungeeReflection { - - private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); - +final class BungeeReflection { private BungeeReflection() { } + private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); + /** * Checks if the specified class has a method with the given name and parameter types. * @@ -26,13 +47,13 @@ private BungeeReflection() { */ public static boolean hasMethod(final @Nullable Class holderClass, final String methodName, final Class... parameters) { if (holderClass == null) return false; - for (Class parameter : parameters) { + for (final Class parameter : parameters) { if (parameter == null) return false; } try { holderClass.getMethod(methodName, parameters); return true; - } catch (NoSuchMethodException ignored) { + } catch (final NoSuchMethodException ignored) { } return false; } @@ -48,7 +69,7 @@ public static boolean hasMethod(final @Nullable Class holderClass, final Stri */ public static MethodHandle findMethod(final @Nullable Class holderClass, final String methodName, final Class returnType, final Class... parameters) { if (holderClass == null || returnType == null) return null; - for (Class parameter : parameters) { + for (final Class parameter : parameters) { if (parameter == null) return null; } try { From c36534b0bb665554a8d7168fad23adacb2a0602c Mon Sep 17 00:00:00 2001 From: bivashy Date: Mon, 4 Mar 2024 18:21:07 +0500 Subject: [PATCH 8/8] Add missing argument into MethodHandle invocation --- .../net/kyori/adventure/platform/bungeecord/BungeeFacet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java index e036c153..2690bd8b 100644 --- a/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java +++ b/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeFacet.java @@ -339,9 +339,9 @@ private void broadcastPacket(final int action) { private void updateBarTitle(final BaseComponent[] message) { try { if (SET_TITLE_STRING != null) { - SET_TITLE_STRING.invoke(ComponentSerializer.toString(message)); + SET_TITLE_STRING.invoke(this.bar, ComponentSerializer.toString(message)); } else { - SET_TITLE_COMPONENT.invoke(TextComponent.fromArray(message)); + SET_TITLE_COMPONENT.invoke(this.bar, TextComponent.fromArray(message)); } } catch (final Throwable throwable) { logError(throwable, "Cannot update the BossBar title");