feat: Initial PAPIProxyBridge Support

This commit is contained in:
Adrian committed 2023-05-08 12:51:12 -05:00
1 parent 7fc53304ae
commit 771e2d11eb
6 files changed
+129 -3

No files matched your search

+2 -1
View File
@@ -4,7 +4,8 @@ plugins {
}
dependencies {
implementation(project(":placeholderapi-expansion-paper"))
implementation(projects.placeholderapiExpansionPaper)
implementation(projects.placeholderapiExpansionVelocity)
}
tasks {
+1 -1
View File
@@ -1,3 +1,3 @@
group = io.github.miniplaceholders
version = 1.1.0
version = 1.2.0
description = PlaceholderAPI-Expansion
+2
View File
@@ -14,9 +14,11 @@ adventure = "4.13.1"
[libraries]
velocity-api = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" }
paper-api = { group = "io.papermc.paper", name = "paper-api", version.ref = "paper" }
miniplaceholders = { group = "io.github.miniplaceholders", name = "miniplaceholders-api", version.ref = "miniplaceholders" }
placeholderapi = { group = "me.clip", name = "placeholderapi", version = "2.11.3" }
proxybridge = "net.william278:PAPIProxyBridge:1.2"
[plugins]
+1 -1
View File
@@ -6,7 +6,7 @@ plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
}
arrayOf("paper").forEach {
arrayOf("paper", "velocity").forEach {
include("placeholderapi-expansion-$it")
project(":placeholderapi-expansion-$it").projectDir = file(it)
+30
View File
@@ -0,0 +1,30 @@
plugins {
java
alias(libs.plugins.blossom)
}
repositories {
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://jitpack.io")
}
dependencies {
compileOnly(libs.proxybridge)
compileOnly(libs.miniplaceholders)
compileOnly(libs.velocity.api)
annotationProcessor(libs.velocity.api)
}
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
}
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
blossom {
replaceTokenIn("src/main/java/io/github/miniplaceholders/expansion/placeholderapi/velocity/VelocityPlugin.java")
replaceToken("{version}", project.version)
}
@@ -0,0 +1,93 @@
package io.github.miniplaceholders.expansion.placeholderapi.velocity;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.Player;
import io.github.miniplaceholders.api.Expansion;
import io.github.miniplaceholders.api.utils.LegacyUtils;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import net.william278.papiproxybridge.api.PlaceholderAPI;
import org.slf4j.Logger;
import java.util.UUID;
import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.AMPERSAND_CHAR;
import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.SECTION_CHAR;
@Plugin(
id = "placeholderapi-expansion",
name = "PlaceholderAPI Expansion",
version = "{version}",
authors = { "4drian3d" },
dependencies = {
@Dependency(id = "miniplaceholders"),
@Dependency(id = "papiproxybridge")
}
)
public final class VelocityPlugin {
@Inject
private Logger logger;
private static final UUID NULL_UUID = UUID.randomUUID();
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
this.logger.info("Starting PlaceholderAPI Expansion for MiniPlaceholders Velocity");
Expansion.builder("placeholderapi")
.filter(Player.class)
.globalPlaceholder("global", (queue, ctx) -> {
final String argument = queue.popOr("You need to provide a placeholder").value();
final String papiParsed = PlaceholderAPI.getInstance().formatPlaceholders(
argument,
NULL_UUID
).getNow(argument).replace(SECTION_CHAR, AMPERSAND_CHAR);
if (parseString(queue)) {
return Tag.preProcessParsed(miniMessage().serialize(LegacyUtils.parsePossibleLegacy(papiParsed)));
} else {
return Tag.selfClosingInserting(LegacyUtils.parsePossibleLegacy(papiParsed));
}
})
.audiencePlaceholder("player", (aud, queue, ctx) -> {
final String argument = queue.popOr("You need to provide a placeholder").value();
final Player player = (Player)aud;
final String papiParsed = PlaceholderAPI.getInstance().formatPlaceholders(
argument,
player.getUniqueId()
).getNow(argument).replace(SECTION_CHAR, AMPERSAND_CHAR);
if (parseString(queue)) {
return Tag.preProcessParsed(miniMessage().serialize(LegacyUtils.parsePossibleLegacy(papiParsed)));
} else {
return Tag.selfClosingInserting(LegacyUtils.parsePossibleLegacy(papiParsed));
}
})
.relationalPlaceholder("relational", (audience, audienceToShow, queue, ctx) -> {
final String argument = queue.popOr("You need to provide a placeholder").value();
final Player player = (Player) audience;
final Player toShow = (Player) audienceToShow;
final String papiParsed = PlaceholderAPI.getInstance().formatPlaceholders(
argument,
player.getUniqueId(),
toShow.getUniqueId()
).getNow(argument).replace(SECTION_CHAR, AMPERSAND_CHAR);
if (parseString(queue)) {
return Tag.preProcessParsed(miniMessage().serialize(LegacyUtils.parsePossibleLegacy(papiParsed)));
} else {
return Tag.selfClosingInserting(LegacyUtils.parsePossibleLegacy(papiParsed));
}
})
.build()
.register();
}
private boolean parseString(ArgumentQueue queue) {
return queue.hasNext() && queue.pop().lowerValue().equals("string");
}
}