Update nukkit module to support new PlaceholderAPI version (#1806)

This commit is contained in:
Creeperface01 2021-03-21 09:36:15 +01:00 committed by GitHub
parent 3e042c47b5
commit 0dd5d41955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 22 deletions

View File

@ -90,7 +90,7 @@ subprojects {
ext.guavaVersion = "28.0-jre" ext.guavaVersion = "28.0-jre"
ext.bstatsVersion = "2.2.1" ext.bstatsVersion = "2.2.1"
ext.placeholderapiVersion = "2.10.9" ext.placeholderapiVersion = "2.10.9"
ext.nkPlaceholderapiVersion = "1.3-SNAPSHOT" ext.nkPlaceholderapiVersion = "1.4-SNAPSHOT"
repositories { repositories {
mavenCentral() mavenCentral()
@ -113,7 +113,10 @@ subprojects {
url = "https://repo.velocitypowered.com/snapshots/" url = "https://repo.velocitypowered.com/snapshots/"
} }
maven { // Nukkit Repository 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 maven { // bStats Repository
url = "https://repo.codemc.org/repository/maven-public" url = "https://repo.codemc.org/repository/maven-public"

View File

@ -18,6 +18,8 @@ package com.djrapitops.plan.addons.placeholderapi;
import cn.nukkit.Player; import cn.nukkit.Player;
import com.creeperface.nukkit.placeholderapi.api.PlaceholderAPI; 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.PlanSystem;
import com.djrapitops.plan.delivery.domain.container.PlayerContainer; import com.djrapitops.plan.delivery.domain.container.PlayerContainer;
import com.djrapitops.plan.delivery.domain.keys.PlayerKeys; 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.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.io.Serializable;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
/** /**
* Placeholder expansion used to provide data from Plan on Nukkit. * Placeholder expansion used to provide data from Plan on Nukkit.
@ -56,27 +61,38 @@ public class NukkitPlaceholderRegistrar {
public void register() { public void register() {
PlaceholderAPI api = PlaceholderAPI.getInstance(); PlaceholderAPI api = PlaceholderAPI.getInstance();
placeholders.getPlaceholders().forEach((name, loader) -> placeholders.getPlaceholders().forEach((name, loader) -> api.builder(name, Serializable.class)
api.visitorSensitivePlaceholder(name, (player, params) -> { .visitorLoader(options -> {
try { try {
return loader.apply(getPlayer(player), params.get()); return loader.apply(
} catch (Exception e) { getPlayer(options.getPlayer()),
errorLogger.warn(e, ErrorContext.builder().related("Registering PlaceholderAPI").build()); getPlaceholderParameterValues(options.getParameters())
return null; );
} } catch (Exception e) {
} errorLogger.warn(e, ErrorContext.builder().related("Registering PlaceholderAPI").build());
)); return null;
}
}).build()
);
placeholders.getStaticPlaceholders().forEach((name, loader) -> placeholders.getStaticPlaceholders().forEach((name, loader) -> api.builder(name, Serializable.class)
api.staticPlaceholder(name, params -> { .loader(options -> {
try { try {
return loader.apply(params.get()); return loader.apply(
} catch (Exception e) { getPlaceholderParameterValues(options.getParameters())
errorLogger.warn(e, ErrorContext.builder().related("Registering PlaceholderAPI").build()); );
return null; } catch (Exception e) {
} errorLogger.warn(e, ErrorContext.builder().related("Registering PlaceholderAPI").build());
} return null;
)); }
}).build()
);
}
private List<String> getPlaceholderParameterValues(PlaceholderParameters parameters) {
return parameters.getAll().stream()
.map(Parameter::getValue)
.collect(Collectors.toList());
} }
private PlayerContainer getPlayer(Player player) { private PlayerContainer getPlayer(Player player) {