Compare commits
63
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a6a616211 | ||
|
|
3808fc9d89 | ||
|
|
a7cc73fe7d | ||
|
|
8ac0c398d7 | ||
|
|
25618c0d42 | ||
|
|
9b61e8efa0 | ||
|
|
ad95e239bc | ||
|
|
d18ff640d2 | ||
|
|
7536d32055 | ||
|
|
5dffb9c251 | ||
|
|
e75baceb77 | ||
|
|
f2c6aa08f4 | ||
|
|
7727dca940 | ||
|
|
151b2dc2a4 | ||
|
|
16e3d09204 | ||
|
|
62c11dd84a | ||
|
|
77913be0fa | ||
|
|
685f67146d | ||
|
|
6f524b056a | ||
|
|
36f1cce813 | ||
|
|
4061c8acbe | ||
|
|
319731cef0 | ||
|
|
9e29afa9c5 | ||
|
|
9655509c2f | ||
|
|
26f1042d17 | ||
|
|
84c39e9205 | ||
|
|
77327661f3 | ||
|
|
b725fd2bae | ||
|
|
f9a5acaaaf | ||
|
|
fe613ce82d | ||
|
|
21839e1e37 | ||
|
|
25d1588032 | ||
|
|
92583013db | ||
|
|
89a7bdb208 | ||
|
|
0e7d4cb6dd | ||
|
|
159b96579f | ||
|
|
efb155a171 | ||
|
|
71ad7fb399 | ||
|
|
8b219fd553 | ||
|
|
9899f0bab4 | ||
|
|
7044e43483 | ||
|
|
36f1739704 | ||
|
|
d173de4250 | ||
|
|
410fe06117 | ||
|
|
e198769698 | ||
|
|
41ff8c1e12 | ||
|
|
344af47d19 | ||
|
|
756b1e9b43 | ||
|
|
85b7a24770 | ||
|
|
7f484f33f0 | ||
|
|
5d21522fa7 | ||
|
|
176266c9d5 | ||
|
|
c5bf073888 | ||
|
|
f2cbd1db75 | ||
|
|
e995e5441e | ||
|
|
f776f8ae61 | ||
|
|
a26f92e75c | ||
|
|
b030f02aac | ||
|
|
4336746bf3 | ||
|
|
e7e87a72dd | ||
|
|
0dce995222 | ||
|
|
a280cf16cb | ||
|
|
b37fad9611 |
No files matched your search
@@ -11,21 +11,21 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: 17
|
||||
distribution: 'temurin'
|
||||
cache: 'gradle'
|
||||
|
||||
- name: Build with Gradle
|
||||
uses: nick-invision/retry@v2
|
||||
uses: nick-invision/retry@v3
|
||||
with:
|
||||
timeout_minutes: 10
|
||||
max_attempts: 2
|
||||
command: gradle build
|
||||
|
||||
- name: Upload Artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: MiniPlaceholders
|
||||
path: jar/MiniPlaceholders-*.jar
|
||||
@@ -43,6 +43,20 @@ public sealed interface Expansion permits ExpansionImpl {
|
||||
*/
|
||||
@NotNull String name();
|
||||
|
||||
/**
|
||||
* Get the author of this expansion
|
||||
* @return the author or null
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Nullable String author();
|
||||
|
||||
/**
|
||||
* Get the version of this expansion
|
||||
* @return the version or null
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Nullable String version();
|
||||
|
||||
/**
|
||||
* Get the {@link TagResolver} of the desired {@link Audience}
|
||||
* @param audience the audience
|
||||
@@ -217,5 +231,25 @@ public sealed interface Expansion permits ExpansionImpl {
|
||||
*/
|
||||
@Contract("_ -> this")
|
||||
@NotNull Builder filter(final @Nullable Predicate<@NotNull Audience> predicate);
|
||||
|
||||
/**
|
||||
* Sets the author of this expansion
|
||||
*
|
||||
* @param author the author of this expansion
|
||||
* @return the {@link Builder} itself
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Contract("_ -> this")
|
||||
@NotNull Builder author(final @Nullable String author);
|
||||
|
||||
/**
|
||||
* Sets the version of this expansion
|
||||
*
|
||||
* @param version the version of this expansion
|
||||
* @return the {@link Builder} itself
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Contract("_ -> this")
|
||||
@NotNull Builder version(final @Nullable String version);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ final class ExpansionImpl implements Expansion {
|
||||
private final TagResolver globalPlaceholders;
|
||||
private final Class<? extends Audience> filterClass;
|
||||
private final Predicate<Audience> predicateFilter;
|
||||
private final String author;
|
||||
private final String version;
|
||||
|
||||
ExpansionImpl(
|
||||
@NotNull final String expansionName,
|
||||
@@ -34,7 +36,10 @@ final class ExpansionImpl implements Expansion {
|
||||
@Nullable final Collection<Tags.Relational> relationalPlaceholders,
|
||||
@Nullable final TagResolver globalPlaceholders,
|
||||
@Nullable final Class<? extends Audience> filterClass,
|
||||
@Nullable final Predicate<Audience> predicateFilter){
|
||||
@Nullable final Predicate<Audience> predicateFilter,
|
||||
@Nullable final String author,
|
||||
@Nullable final String version
|
||||
) {
|
||||
this.name = expansionName+"-";
|
||||
this.audiencePlaceholders = audiencePlaceholders != null
|
||||
? audiencePlaceholders.toArray(EMPTY_SINGLE_AUDIENCE)
|
||||
@@ -45,6 +50,8 @@ final class ExpansionImpl implements Expansion {
|
||||
this.globalPlaceholders = globalPlaceholders;
|
||||
this.filterClass = filterClass;
|
||||
this.predicateFilter = predicateFilter;
|
||||
this.author = author;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,6 +59,16 @@ final class ExpansionImpl implements Expansion {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String author(){
|
||||
return this.author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String version(){
|
||||
return this.version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TagResolver audiencePlaceholders(@NotNull Audience audience) {
|
||||
if (audiencePlaceholders.length == 0) return TagResolver.empty();
|
||||
@@ -136,6 +153,8 @@ final class ExpansionImpl implements Expansion {
|
||||
private TagResolver.Builder globalPlaceholders;
|
||||
private Class<? extends Audience> filterClass;
|
||||
private Predicate<Audience> predicateFilter;
|
||||
private String author;
|
||||
private String version;
|
||||
|
||||
Builder(@NotNull final String name){
|
||||
this.expansionName = nonNullOrEmptyString(name, "Expansion name")
|
||||
@@ -198,6 +217,18 @@ final class ExpansionImpl implements Expansion {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expansion.@NotNull Builder author(@Nullable final String author) {
|
||||
this.author = author;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expansion.@NotNull Builder version(@Nullable final String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Expansion build(){
|
||||
return new ExpansionImpl(
|
||||
@@ -206,7 +237,9 @@ final class ExpansionImpl implements Expansion {
|
||||
this.relationalPlaceholders,
|
||||
this.globalPlaceholders != null ? this.globalPlaceholders.build() : TagResolver.empty(),
|
||||
this.filterClass,
|
||||
this.predicateFilter
|
||||
this.predicateFilter,
|
||||
this.version,
|
||||
this.author
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
|
||||
|
||||
/**
|
||||
@@ -68,7 +71,10 @@ public final class LegacyUtils {
|
||||
* @return a parsed string
|
||||
* @since 2.2.1
|
||||
*/
|
||||
public static @NotNull Component parsePossibleLegacy(@Nullable String string, @NotNull final Context context) {
|
||||
public static @NotNull Component parsePossibleLegacy(
|
||||
@Nullable String string,
|
||||
final @NotNull Context context
|
||||
) {
|
||||
if (string == null || string.isEmpty()) return Component.empty();
|
||||
if (string.indexOf(LegacyComponentSerializer.SECTION_CHAR) != -1) {
|
||||
string = string.replace(LegacyComponentSerializer.SECTION_CHAR, LegacyComponentSerializer.AMPERSAND_CHAR);
|
||||
@@ -97,7 +103,10 @@ public final class LegacyUtils {
|
||||
* @return a parsed string
|
||||
* @since 2.2.1
|
||||
*/
|
||||
public static @NotNull Component parsePossibleLegacy(@Nullable String string, @NotNull final TagResolver resolver) {
|
||||
public static @NotNull Component parsePossibleLegacy(
|
||||
@Nullable String string,
|
||||
final @NotNull TagResolver resolver
|
||||
) {
|
||||
if (string == null || string.isEmpty()) return Component.empty();
|
||||
if (string.indexOf(LegacyComponentSerializer.SECTION_CHAR) != -1) {
|
||||
string = string.replace(LegacyComponentSerializer.SECTION_CHAR, LegacyComponentSerializer.AMPERSAND_CHAR);
|
||||
@@ -112,4 +121,47 @@ public final class LegacyUtils {
|
||||
resolver
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provided string contains legacy formatting.
|
||||
*
|
||||
* @param string the string input
|
||||
* @return whether the string has legacy content
|
||||
* @see LegacyComponentSerializer#AMPERSAND_CHAR
|
||||
* @see LegacyComponentSerializer#SECTION_CHAR
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static boolean hasLegacyFormat(final String string) {
|
||||
requireNonNull(string, "string");
|
||||
return string.indexOf(LegacyComponentSerializer.SECTION_CHAR) != -1
|
||||
|| string.indexOf(LegacyComponentSerializer.AMPERSAND_CHAR) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the input to a type depending on whether it contains legacy formatting or not.
|
||||
*
|
||||
* @param string the string input
|
||||
* @param legacyMapping the mapping function in case the string contains legacy formatting
|
||||
* @param modernMapping the mapping function in case the string does not contain any legacy character type,
|
||||
* being safe to use with MiniMessage
|
||||
* @return the mapped result
|
||||
* @param <R> the result type
|
||||
* @see LegacyComponentSerializer#AMPERSAND_CHAR
|
||||
* @see LegacyComponentSerializer#SECTION_CHAR
|
||||
* @see #hasLegacyFormat(String)
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static <R> R mapLegacyOrElse(
|
||||
final @NotNull String string,
|
||||
final @NotNull Function<String, R> legacyMapping,
|
||||
final @NotNull Function<String, R> modernMapping
|
||||
) {
|
||||
requireNonNull(legacyMapping, "legacyMapping");
|
||||
requireNonNull(modernMapping, "modernInput");
|
||||
if (hasLegacyFormat(string)) {
|
||||
return legacyMapping.apply(string);
|
||||
} else {
|
||||
return modernMapping.apply(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ public final class TagsUtils {
|
||||
* @return a new basic self closing Tag of a string
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Deprecated
|
||||
public static @NotNull Tag staticTag(@NotNull String string) {
|
||||
return Tag.selfClosingInserting(Component.text(string));
|
||||
}
|
||||
@@ -51,6 +52,7 @@ public final class TagsUtils {
|
||||
* @return a new basic self closing Tag of a component
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Deprecated
|
||||
public static @NotNull Tag staticTag(@NotNull Component component) {
|
||||
return Tag.selfClosingInserting(component);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package io.github.miniplaceholders.test;
|
||||
|
||||
import io.github.miniplaceholders.api.utils.LegacyUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Inserting;
|
||||
import net.kyori.adventure.text.minimessage.tag.PreProcess;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LegacyTest {
|
||||
@Test
|
||||
@@ -17,4 +20,23 @@ class LegacyTest {
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMapLegacyOrElse() {
|
||||
final String legacyInput = "&fhi <red>aaaa";
|
||||
Tag legacyProcessedTag = LegacyUtils.mapLegacyOrElse(
|
||||
legacyInput,
|
||||
legacy -> Tag.inserting(LegacyUtils.parsePossibleLegacy(legacy)),
|
||||
Tag::preProcessParsed
|
||||
);
|
||||
assertInstanceOf(Inserting.class, legacyProcessedTag);
|
||||
|
||||
final String modernInput = "<rainbow>aaaaaaaaaaaaa";
|
||||
Tag modernProcessedTag = LegacyUtils.mapLegacyOrElse(
|
||||
modernInput,
|
||||
__ -> fail(),
|
||||
Tag::preProcessParsed
|
||||
);
|
||||
assertInstanceOf(PreProcess.class, modernProcessedTag);
|
||||
}
|
||||
}
|
||||
@@ -15,5 +15,5 @@ dependencyResolutionManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "1.9.20" apply false
|
||||
kotlin("jvm") version "1.9.22" apply false
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
@@ -47,15 +47,15 @@ public class FabricMod implements ModInitializer, PlaceholdersPlugin {
|
||||
@Override
|
||||
public void loadDefaultExpansions() {
|
||||
Expansion.builder("server")
|
||||
.globalPlaceholder("name", Tag.selfClosingInserting(Component.text(this.minecraftServer.getServerModName())))
|
||||
.globalPlaceholder("name", Tag.preProcessParsed(this.minecraftServer.getServerModName()))
|
||||
.globalPlaceholder("online", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.minecraftServer.getPlayerCount())))
|
||||
.globalPlaceholder("version", (ctx, queue) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getServerVersion())))
|
||||
.globalPlaceholder("max_players", (ctx, queue) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getMaxPlayers())))
|
||||
.globalPlaceholder("version", (ctx, queue) -> Tag.preProcessParsed(this.minecraftServer.getServerVersion()))
|
||||
.globalPlaceholder("max_players", (ctx, queue) -> Tag.preProcessParsed(Integer.toString(this.minecraftServer.getMaxPlayers())))
|
||||
.globalPlaceholder("unique_joins", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.minecraftServer.getProfileCache().load().size())))
|
||||
.globalPlaceholder("tps_1m", (ctx, queue) -> Tag.preProcessParsed(tickManager.getTps1m().formattedAverage()))
|
||||
.globalPlaceholder("tps_5m", (ctx, queue) -> Tag.preProcessParsed(tickManager.getTps5m().formattedAverage()))
|
||||
//.globalPlaceholder("tps_15m", (ctx, queue) -> Tag.preProcessParsed(tickManager.getTps15m().formattedAverage()))
|
||||
.globalPlaceholder("tick_count", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getTickCount())))
|
||||
.globalPlaceholder("tick_count", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.minecraftServer.getTickCount())))
|
||||
.globalPlaceholder("has_whitelist", (queue, ctx) -> Tag.preProcessParsed(Boolean.toString(this.minecraftServer.getPlayerList().isUsingWhitelist())))
|
||||
.globalPlaceholder("total_chunks", (queue, ctx) -> {
|
||||
int chunks = 0;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
"fabricloader": ">=0.14.19",
|
||||
"fabric": "*",
|
||||
"java": ">=17",
|
||||
"minecraft": ">=1.19.4",
|
||||
"minecraft": ">=1.20.2",
|
||||
"fabric-permissions-api-v0": "*"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
group = io.github.miniplaceholders
|
||||
version = 2.2.2
|
||||
version = 2.3.0-SNAPSHOT
|
||||
description = MiniMessage Component-based Placeholders for Paper, Fabric, Sponge, Folia and Velocity platforms
|
||||
|
||||
org.gradle.jvmargs=-Xmx2G
|
||||
@@ -4,12 +4,11 @@ metadata.format.version = "1.1"
|
||||
|
||||
velocity = "3.2.0-SNAPSHOT"
|
||||
paper = "1.20.2-R0.1-SNAPSHOT"
|
||||
krypton = "7796647145"
|
||||
minecraft = "1.20.2"
|
||||
|
||||
runtask = "2.2.2"
|
||||
runtask = "2.2.3"
|
||||
pluginyml = "0.6.0"
|
||||
userdev = "1.5.9"
|
||||
userdev = "1.7.1"
|
||||
blossom = "2.1.0"
|
||||
indra = "3.1.3"
|
||||
shadow = "8.1.1"
|
||||
@@ -17,13 +16,13 @@ jmh = "0.7.2"
|
||||
dokka = "1.9.10"
|
||||
|
||||
cloud = "1.8.4"
|
||||
adventure = "4.14.0"
|
||||
adventurefabric = "5.10.1"
|
||||
adventure = "4.15.0"
|
||||
adventurefabric = "5.12.0"
|
||||
brigadier = "1.0.500"
|
||||
kotlin="1.9.20"
|
||||
kotlin="1.9.22"
|
||||
|
||||
fabric-api = "0.90.1+1.20.3"
|
||||
fabric-loader = "0.14.24"
|
||||
fabric-api = "0.96.4+1.20.5"
|
||||
fabric-loader = "0.15.7"
|
||||
|
||||
desertwell = "2.0.4"
|
||||
|
||||
@@ -31,7 +30,6 @@ desertwell = "2.0.4"
|
||||
|
||||
velocity = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" }
|
||||
paper = { group = "io.papermc.paper", name = "paper-api", version.ref = "paper" }
|
||||
krypton-server = { group = "org.kryptonmc", name = "krypton-server", version.ref = "krypton" }
|
||||
minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft" }
|
||||
|
||||
fabric-api = { group = "net.fabricmc.fabric-api", name = "fabric-api", version.ref = "fabric-api" }
|
||||
@@ -54,8 +52,6 @@ cloud-extras = { group = "cloud.commandframework", name = "cloud-minecraft-extra
|
||||
|
||||
brigadier = { group = "com.mojang", name = "brigadier", version.ref = "brigadier" }
|
||||
|
||||
krypton-annotation = { group = "org.kryptonmc", name = "krypton-annotation-processor", version.ref = "krypton" }
|
||||
|
||||
plugin-shadow = { group = "com.github.johnrengelman", name = "shadow", version.ref = "shadow" }
|
||||
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
||||
plugin-indra-common = { module = "net.kyori:indra-common", version.ref = "indra" }
|
||||
@@ -64,7 +60,7 @@ plugin-dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.9.10"
|
||||
|
||||
desertwell = { group = "net.william278", name = "DesertWell", version.ref = "desertwell" }
|
||||
|
||||
junit-bom = "org.junit:junit-bom:5.10.1"
|
||||
junit-bom = "org.junit:junit-bom:5.10.2"
|
||||
|
||||
[plugins]
|
||||
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
kotlin("kapt")
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://repo.kryptonmc.org/releases")
|
||||
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
|
||||
maven("https://repo.kryptonmc.org/snapshots")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.krypton.server)
|
||||
compileOnly(kotlin("stdlib"))
|
||||
kapt(libs.krypton.annotation)
|
||||
implementation(projects.miniplaceholdersCommon)
|
||||
implementation(projects.miniplaceholdersApi)
|
||||
implementation(projects.miniplaceholdersConnect)
|
||||
implementation(projects.miniplaceholdersKotlinExt)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package io.github.miniplaceholders.krypton
|
||||
|
||||
import com.google.inject.Inject
|
||||
import io.github.miniplaceholders.api.utils.TagsUtils
|
||||
import io.github.miniplaceholders.common.PlaceholdersCommand
|
||||
import io.github.miniplaceholders.common.PlaceholdersPlugin
|
||||
import io.github.miniplaceholders.common.PluginConstants
|
||||
import io.github.miniplaceholders.connect.InternalPlatform
|
||||
import io.github.miniplaceholders.kotlin.asClosingTag
|
||||
import io.github.miniplaceholders.kotlin.expansion
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.apache.logging.log4j.Logger
|
||||
import org.kryptonmc.api.command.BrigadierCommand
|
||||
import org.kryptonmc.api.command.CommandExecutionContext
|
||||
import org.kryptonmc.api.event.Listener
|
||||
import org.kryptonmc.api.event.server.ServerStartEvent
|
||||
import org.kryptonmc.api.plugin.annotation.Plugin
|
||||
import org.kryptonmc.krypton.KryptonServer
|
||||
import org.kryptonmc.krypton.command.KryptonCommandMeta
|
||||
|
||||
@Plugin(
|
||||
name = "MiniPlaceholders",
|
||||
id = "miniplaceholders",
|
||||
version = PluginConstants.VERSION,
|
||||
authors = ["4drian3d"]
|
||||
)
|
||||
class KotlinKryptonPlugin @Inject constructor(
|
||||
private val server: KryptonServer,
|
||||
private val logger: Logger
|
||||
) : PlaceholdersPlugin {
|
||||
|
||||
init {
|
||||
InternalPlatform.platform(InternalPlatform.KRYPTON)
|
||||
}
|
||||
|
||||
@Listener
|
||||
@Suppress("UNUSED")
|
||||
fun onServerStart(event: ServerStartEvent) {
|
||||
logger.info("Starting MiniPlaceholders Krypton")
|
||||
this.loadDefaultExpansions()
|
||||
this.registerPlatformCommand()
|
||||
}
|
||||
|
||||
override fun loadDefaultExpansions() {
|
||||
expansion("server") {
|
||||
globalPlaceholder("total_entities") { _, _ ->
|
||||
var entityCount = 0
|
||||
for ((_, value) in server.worldManager.worlds) {
|
||||
entityCount += value.entities.size
|
||||
}
|
||||
Component.text(entityCount).asClosingTag()
|
||||
}
|
||||
globalPlaceholder("total_chunks") { _, _ ->
|
||||
var chunkCount = 0
|
||||
for ((_, value) in server.worldManager.worlds) {
|
||||
chunkCount += value.chunks.size
|
||||
}
|
||||
Component.text(chunkCount).asClosingTag()
|
||||
}
|
||||
globalPlaceholder("name", TagsUtils.staticTag(server.platform.name))
|
||||
globalPlaceholder("online") { queue, _ ->
|
||||
if (queue.hasNext()) {
|
||||
val worldName = queue.pop().value()
|
||||
val players = server.players.filter { it.world.name == worldName }
|
||||
|
||||
return@globalPlaceholder Component.text(players.joinToString(", ")).asClosingTag()
|
||||
}
|
||||
Component.text(server.players.size).asClosingTag()
|
||||
}
|
||||
globalPlaceholder("version", TagsUtils.staticTag(server.platform.version))
|
||||
globalPlaceholder("max_players", Component.text(server.config.maxPlayers).asClosingTag())
|
||||
}.register()
|
||||
}
|
||||
|
||||
override fun registerPlatformCommand() {
|
||||
/*val command = PlaceholdersCommand.builder<CommandExecutionContext>()
|
||||
.fromSourceToAudience { it.sender }
|
||||
.playerSuggestions { server.players.map { it.name } }
|
||||
.toAudience { server.getPlayer(it) }
|
||||
.build()
|
||||
val brigadierCMD = BrigadierCommand.of(command.asNode("miniplaceholders"))
|
||||
val meta = KryptonCommandMeta.Builder("miniplaceholders").build()
|
||||
server.commandManager.register(brigadierCMD, meta)*/
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package io.github.miniplaceholders.paper;
|
||||
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
|
||||
import cloud.commandframework.paper.PaperCommandManager;
|
||||
import io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.miniplaceholders.api.utils.TagsUtils;
|
||||
import io.github.miniplaceholders.common.PlaceholdersCommand;
|
||||
import io.github.miniplaceholders.common.PlaceholdersPlugin;
|
||||
import io.github.miniplaceholders.connect.InternalPlatform;
|
||||
@@ -44,38 +43,38 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin
|
||||
@Override
|
||||
public void loadDefaultExpansions() {
|
||||
Expansion.builder("server")
|
||||
.globalPlaceholder("name", TagsUtils.staticTag(Component.text(this.getServer().getName())))
|
||||
.globalPlaceholder("online", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().getOnlinePlayers().size())))
|
||||
.globalPlaceholder("version", TagsUtils.staticTag(this.getServer().getVersion()))
|
||||
.globalPlaceholder("max_players", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().getMaxPlayers())))
|
||||
.globalPlaceholder("unique_joins", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().getOfflinePlayers().length)))
|
||||
.globalPlaceholder("tps_1", (queue, ctx) -> TagsUtils.staticTag(TPS_FORMAT.format(this.getServer().getTPS()[0])))
|
||||
.globalPlaceholder("tps_5", (queue, ctx) -> TagsUtils.staticTag(TPS_FORMAT.format(this.getServer().getTPS()[1])))
|
||||
.globalPlaceholder("tps_15", (queue, ctx) -> TagsUtils.staticTag(TPS_FORMAT.format(this.getServer().getTPS()[2])))
|
||||
.globalPlaceholder("has_whitelist", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().hasWhitelist())))
|
||||
.globalPlaceholder("name", Tag.preProcessParsed(this.getServer().getName()))
|
||||
.globalPlaceholder("online", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.getServer().getOnlinePlayers().size())))
|
||||
.globalPlaceholder("version", Tag.preProcessParsed(this.getServer().getVersion()))
|
||||
.globalPlaceholder("max_players", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.getServer().getMaxPlayers())))
|
||||
.globalPlaceholder("unique_joins", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.getServer().getOfflinePlayers().length)))
|
||||
.globalPlaceholder("tps_1", (queue, ctx) -> Tag.preProcessParsed(TPS_FORMAT.format(this.getServer().getTPS()[0])))
|
||||
.globalPlaceholder("tps_5", (queue, ctx) -> Tag.preProcessParsed(TPS_FORMAT.format(this.getServer().getTPS()[1])))
|
||||
.globalPlaceholder("tps_15", (queue, ctx) -> Tag.preProcessParsed(TPS_FORMAT.format(this.getServer().getTPS()[2])))
|
||||
.globalPlaceholder("has_whitelist", (queue, ctx) -> Tag.preProcessParsed(Boolean.toString(this.getServer().hasWhitelist())))
|
||||
.globalPlaceholder("total_chunks", (queue, ctx) -> {
|
||||
int chunkCount = 0;
|
||||
for (World world : this.getServer().getWorlds()){
|
||||
chunkCount += world.getLoadedChunks().length;
|
||||
}
|
||||
return TagsUtils.staticTag(Component.text(chunkCount));
|
||||
return Tag.preProcessParsed(Integer.toString(chunkCount));
|
||||
})
|
||||
.globalPlaceholder("total_entities", (queue, ctx) -> {
|
||||
int entityCount = 0;
|
||||
for (World world : this.getServer().getWorlds()){
|
||||
entityCount += world.getEntityCount();
|
||||
}
|
||||
return TagsUtils.staticTag(Component.text(entityCount));
|
||||
return Tag.preProcessParsed(Integer.toString(entityCount));
|
||||
})
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> TagsUtils.staticTag(MSPT_FORMAT.format(this.getServer().getAverageTickTime())))
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> Tag.preProcessParsed(MSPT_FORMAT.format(this.getServer().getAverageTickTime())))
|
||||
.globalPlaceholder("datapack_list", (queue, ctx) -> {
|
||||
final TextComponent.Builder builder = Component.text();
|
||||
for (Datapack datapack : this.getServer().getDatapackManager().getEnabledPacks()){
|
||||
for (final Datapack datapack : this.getServer().getDatapackManager().getEnabledPacks()) {
|
||||
builder.append(Component.text("[").append(Component.text(datapack.getName()).append(Component.text("] "))));
|
||||
}
|
||||
return Tag.selfClosingInserting(builder.build());
|
||||
})
|
||||
.globalPlaceholder("datapack_count", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.getServer().getDatapackManager().getEnabledPacks().size())))
|
||||
.globalPlaceholder("datapack_count", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.getServer().getDatapackManager().getEnabledPacks().size())))
|
||||
.build()
|
||||
.register();
|
||||
}
|
||||
|
||||
+2
-2
@@ -30,9 +30,9 @@ dependencyResolutionManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("fabric-loom") version "1.4.4"
|
||||
id("fabric-loom") version "1.5.8"
|
||||
id("org.spongepowered.gradle.plugin") version "2.2.0"
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
|
||||
}
|
||||
|
||||
arrayOf(
|
||||
|
||||
@@ -4,13 +4,12 @@ import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||
import cloud.commandframework.sponge.SpongeCommandManager;
|
||||
import com.google.inject.Inject;
|
||||
import io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.miniplaceholders.api.utils.TagsUtils;
|
||||
import io.github.miniplaceholders.common.PlaceholdersCommand;
|
||||
import io.github.miniplaceholders.common.PlaceholdersPlugin;
|
||||
import io.github.miniplaceholders.connect.InternalPlatform;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.Server;
|
||||
@@ -59,26 +58,26 @@ public class SpongePlugin implements PlaceholdersPlugin {
|
||||
@Override
|
||||
public void loadDefaultExpansions() {
|
||||
Expansion.builder("server")
|
||||
.globalPlaceholder("name", TagsUtils.staticTag("Sponge"))
|
||||
.globalPlaceholder("online", (queue, ctx) -> TagsUtils.staticTag(Component.text(server.onlinePlayers().size())))
|
||||
.globalPlaceholder("max_players", (queue, ctx) -> TagsUtils.staticTag(Component.text(server.maxPlayers())))
|
||||
.globalPlaceholder("unique_joins", (queue, ctx) -> TagsUtils.staticTag(Component.text(server.userManager().streamAll().count())))
|
||||
.globalPlaceholder("has_whitelist", (queue, ctx) -> TagsUtils.staticTag(Component.text(server.isWhitelistEnabled())))
|
||||
.globalPlaceholder("name", Tag.preProcessParsed("Sponge"))
|
||||
.globalPlaceholder("online", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(server.onlinePlayers().size())))
|
||||
.globalPlaceholder("max_players", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(server.maxPlayers())))
|
||||
.globalPlaceholder("unique_joins", (queue, ctx) -> Tag.preProcessParsed(Long.toString(server.userManager().streamAll().count())))
|
||||
.globalPlaceholder("has_whitelist", (queue, ctx) -> Tag.preProcessParsed(Boolean.toString(server.isWhitelistEnabled())))
|
||||
.globalPlaceholder("total_chunks", (queue, ctx) -> {
|
||||
int chunkCount = 0;
|
||||
for (ServerWorld world : server.worldManager().worlds()){
|
||||
chunkCount += world.entities().size();
|
||||
}
|
||||
return TagsUtils.staticTag(Component.text(chunkCount));
|
||||
return Tag.preProcessParsed(Integer.toString(chunkCount));
|
||||
})
|
||||
.globalPlaceholder("total_entities", (queue, ctx) -> {
|
||||
int entityCount = 0;
|
||||
for (ServerWorld world : server.worldManager().worlds()){
|
||||
entityCount += world.entities().size();
|
||||
}
|
||||
return TagsUtils.staticTag(Component.text(entityCount));
|
||||
return Tag.preProcessParsed(Integer.toString(entityCount));
|
||||
})
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> TagsUtils.staticTag(Component.text(server.averageTickTime())))
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> Tag.preProcessParsed(Double.toString(server.averageTickTime())))
|
||||
.build()
|
||||
.register();
|
||||
|
||||
|
||||
@@ -15,12 +15,10 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.miniplaceholders.api.utils.Components;
|
||||
import io.github.miniplaceholders.api.utils.TagsUtils;
|
||||
import io.github.miniplaceholders.common.PlaceholdersCommand;
|
||||
import io.github.miniplaceholders.common.PlaceholdersPlugin;
|
||||
import io.github.miniplaceholders.common.PluginConstants;
|
||||
import io.github.miniplaceholders.connect.InternalPlatform;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@@ -67,14 +65,14 @@ public final class VelocityPlugin implements PlaceholdersPlugin {
|
||||
.map(size -> Integer.toString(size))
|
||||
.orElse("0"));
|
||||
}
|
||||
return Tag.selfClosingInserting(Component.text(proxy.getPlayerCount()));
|
||||
return Tag.preProcessParsed(Integer.toString(proxy.getPlayerCount()));
|
||||
})
|
||||
.globalPlaceholder("server_count", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(proxy.getAllServers().size())))
|
||||
.globalPlaceholder("is_player_online", (queue, ctx) -> {
|
||||
String playerName = queue.popOr(() -> "you need to introduce an argument").value();
|
||||
return TagsUtils.staticTag(proxy.getPlayer(playerName).isPresent() ? Components.YES_COMPONENT : Components.NO_COMPONENT);
|
||||
return Tag.selfClosingInserting(proxy.getPlayer(playerName).isPresent() ? Components.YES_COMPONENT : Components.NO_COMPONENT);
|
||||
})
|
||||
.globalPlaceholder("version", TagsUtils.staticTag(proxy.getVersion().getVersion()))
|
||||
.globalPlaceholder("version", Tag.preProcessParsed(proxy.getVersion().getVersion()))
|
||||
.build()
|
||||
.register();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user