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.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"
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user