mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Update nukkit module to support new PlaceholderAPI version (#1806)
This commit is contained in:
parent
3e042c47b5
commit
0dd5d41955
@ -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"
|
||||
|
@ -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<String> getPlaceholderParameterValues(PlaceholderParameters parameters) {
|
||||
return parameters.getAll().stream()
|
||||
.map(Parameter::getValue)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private PlayerContainer getPlayer(Player player) {
|
||||
|
Loading…
Reference in New Issue
Block a user