From 0dd5d41955f87e44f49134d5e0aa175e352b29d0 Mon Sep 17 00:00:00 2001 From: Creeperface01 Date: Sun, 21 Mar 2021 09:36:15 +0100 Subject: [PATCH] Update nukkit module to support new PlaceholderAPI version (#1806) --- Plan/build.gradle | 7 ++- .../NukkitPlaceholderRegistrar.java | 56 ++++++++++++------- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/Plan/build.gradle b/Plan/build.gradle index ff0a54a6d..ad60376e8 100644 --- a/Plan/build.gradle +++ b/Plan/build.gradle @@ -90,7 +90,7 @@ subprojects { ext.guavaVersion = "28.0-jre" ext.bstatsVersion = "2.2.1" ext.placeholderapiVersion = "2.10.9" - ext.nkPlaceholderapiVersion = "1.3-SNAPSHOT" + ext.nkPlaceholderapiVersion = "1.4-SNAPSHOT" repositories { mavenCentral() @@ -113,7 +113,10 @@ subprojects { url = "https://repo.velocitypowered.com/snapshots/" } maven { // Nukkit Repository - url = "https://repo.nukkitx.com/main" + url = "https://repo.opencollab.dev/maven-snapshots/" + } + maven { // Nukkit Repository + url = "https://repo.opencollab.dev/maven-releases/" } maven { // bStats Repository url = "https://repo.codemc.org/repository/maven-public" diff --git a/Plan/nukkit/src/main/java/com/djrapitops/plan/addons/placeholderapi/NukkitPlaceholderRegistrar.java b/Plan/nukkit/src/main/java/com/djrapitops/plan/addons/placeholderapi/NukkitPlaceholderRegistrar.java index 8b7cee8b4..c511a23d3 100644 --- a/Plan/nukkit/src/main/java/com/djrapitops/plan/addons/placeholderapi/NukkitPlaceholderRegistrar.java +++ b/Plan/nukkit/src/main/java/com/djrapitops/plan/addons/placeholderapi/NukkitPlaceholderRegistrar.java @@ -18,6 +18,8 @@ package com.djrapitops.plan.addons.placeholderapi; import cn.nukkit.Player; import com.creeperface.nukkit.placeholderapi.api.PlaceholderAPI; +import com.creeperface.nukkit.placeholderapi.api.PlaceholderParameters; +import com.creeperface.nukkit.placeholderapi.api.PlaceholderParameters.Parameter; import com.djrapitops.plan.PlanSystem; import com.djrapitops.plan.delivery.domain.container.PlayerContainer; import com.djrapitops.plan.delivery.domain.keys.PlayerKeys; @@ -29,7 +31,10 @@ import com.djrapitops.plan.utilities.logging.ErrorLogger; import javax.inject.Inject; import javax.inject.Singleton; +import java.io.Serializable; +import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; /** * Placeholder expansion used to provide data from Plan on Nukkit. @@ -56,27 +61,38 @@ public class NukkitPlaceholderRegistrar { public void register() { PlaceholderAPI api = PlaceholderAPI.getInstance(); - placeholders.getPlaceholders().forEach((name, loader) -> - api.visitorSensitivePlaceholder(name, (player, params) -> { - try { - return loader.apply(getPlayer(player), params.get()); - } catch (Exception e) { - errorLogger.warn(e, ErrorContext.builder().related("Registering PlaceholderAPI").build()); - return null; - } - } - )); + placeholders.getPlaceholders().forEach((name, loader) -> api.builder(name, Serializable.class) + .visitorLoader(options -> { + try { + return loader.apply( + getPlayer(options.getPlayer()), + getPlaceholderParameterValues(options.getParameters()) + ); + } catch (Exception e) { + errorLogger.warn(e, ErrorContext.builder().related("Registering PlaceholderAPI").build()); + return null; + } + }).build() + ); - placeholders.getStaticPlaceholders().forEach((name, loader) -> - api.staticPlaceholder(name, params -> { - try { - return loader.apply(params.get()); - } catch (Exception e) { - errorLogger.warn(e, ErrorContext.builder().related("Registering PlaceholderAPI").build()); - return null; - } - } - )); + placeholders.getStaticPlaceholders().forEach((name, loader) -> api.builder(name, Serializable.class) + .loader(options -> { + try { + return loader.apply( + getPlaceholderParameterValues(options.getParameters()) + ); + } catch (Exception e) { + errorLogger.warn(e, ErrorContext.builder().related("Registering PlaceholderAPI").build()); + return null; + } + }).build() + ); + } + + private List getPlaceholderParameterValues(PlaceholderParameters parameters) { + return parameters.getAll().stream() + .map(Parameter::getValue) + .collect(Collectors.toList()); } private PlayerContainer getPlayer(Player player) {