Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37b4ddcd84 |
No files matched your search
@@ -11,21 +11,21 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: 17
|
||||
distribution: 'temurin'
|
||||
cache: 'gradle'
|
||||
|
||||
- name: Build with Gradle
|
||||
uses: nick-invision/retry@v3
|
||||
uses: nick-invision/retry@v2
|
||||
with:
|
||||
timeout_minutes: 10
|
||||
max_attempts: 2
|
||||
command: gradle build
|
||||
|
||||
- name: Upload Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: MiniPlaceholders
|
||||
path: jar/MiniPlaceholders-*.jar
|
||||
@@ -43,20 +43,6 @@ 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
|
||||
@@ -231,25 +217,5 @@ 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,8 +27,6 @@ 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,
|
||||
@@ -36,10 +34,7 @@ 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 String author,
|
||||
@Nullable final String version
|
||||
) {
|
||||
@Nullable final Predicate<Audience> predicateFilter){
|
||||
this.name = expansionName+"-";
|
||||
this.audiencePlaceholders = audiencePlaceholders != null
|
||||
? audiencePlaceholders.toArray(EMPTY_SINGLE_AUDIENCE)
|
||||
@@ -50,8 +45,6 @@ final class ExpansionImpl implements Expansion {
|
||||
this.globalPlaceholders = globalPlaceholders;
|
||||
this.filterClass = filterClass;
|
||||
this.predicateFilter = predicateFilter;
|
||||
this.author = author;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,16 +52,6 @@ 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();
|
||||
@@ -153,8 +136,6 @@ 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")
|
||||
@@ -217,18 +198,6 @@ 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(
|
||||
@@ -237,9 +206,7 @@ final class ExpansionImpl implements Expansion {
|
||||
this.relationalPlaceholders,
|
||||
this.globalPlaceholders != null ? this.globalPlaceholders.build() : TagResolver.empty(),
|
||||
this.filterClass,
|
||||
this.predicateFilter,
|
||||
this.version,
|
||||
this.author
|
||||
this.predicateFilter
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -71,10 +68,7 @@ public final class LegacyUtils {
|
||||
* @return a parsed string
|
||||
* @since 2.2.1
|
||||
*/
|
||||
public static @NotNull Component parsePossibleLegacy(
|
||||
@Nullable String string,
|
||||
final @NotNull Context context
|
||||
) {
|
||||
public static @NotNull Component parsePossibleLegacy(@Nullable String string, @NotNull final 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);
|
||||
@@ -103,10 +97,7 @@ public final class LegacyUtils {
|
||||
* @return a parsed string
|
||||
* @since 2.2.1
|
||||
*/
|
||||
public static @NotNull Component parsePossibleLegacy(
|
||||
@Nullable String string,
|
||||
final @NotNull TagResolver resolver
|
||||
) {
|
||||
public static @NotNull Component parsePossibleLegacy(@Nullable String string, @NotNull final 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);
|
||||
@@ -121,47 +112,4 @@ 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,7 +41,6 @@ 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));
|
||||
}
|
||||
@@ -52,7 +51,6 @@ 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,13 +2,10 @@ 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.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class LegacyTest {
|
||||
@Test
|
||||
@@ -20,23 +17,4 @@ 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.8.0"
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "1.9.22" apply false
|
||||
kotlin("jvm") version "1.9.20" apply false
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package io.github.miniplaceholders.fabric;
|
||||
|
||||
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
|
||||
import cloud.commandframework.fabric.FabricServerCommandManager;
|
||||
import io.github.miniplaceholders.common.PlaceholdersCommand;
|
||||
import io.github.miniplaceholders.common.PlaceholdersPlugin;
|
||||
import io.github.miniplaceholders.connect.InternalPlatform;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public final class FabricClientMod implements ClientModInitializer, PlaceholdersPlugin {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
InternalPlatform.platform(InternalPlatform.FABRIC);
|
||||
registerPlatformCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDefaultExpansions() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlatformCommand() {
|
||||
final FabricServerCommandManager<CommandSourceStack> commandManager = new FabricServerCommandManager<>(
|
||||
AsynchronousCommandExecutionCoordinator.simpleCoordinator(),
|
||||
Function.identity(),
|
||||
Function.identity()
|
||||
);
|
||||
PlaceholdersCommand.<CommandSourceStack>builder()
|
||||
.hasPermissionCheck((source, permission) -> Permissions.check(source, permission, 4))
|
||||
.toAudience(string -> {
|
||||
var server = Minecraft.getInstance().getSingleplayerServer();
|
||||
if (server != null) {
|
||||
return server.getPlayerList().getPlayerByName(string);
|
||||
}
|
||||
return Minecraft.getInstance().player;
|
||||
})
|
||||
.playerSuggestions(() -> {
|
||||
var server = Minecraft.getInstance().getSingleplayerServer();
|
||||
if (server != null) {
|
||||
return new ArrayList<>(List.of(server.getPlayerList().getPlayerNamesArray()));
|
||||
}
|
||||
return new ArrayList<>();
|
||||
})
|
||||
.manager(commandManager)
|
||||
.command("miniplaceholders")
|
||||
.build()
|
||||
.register();
|
||||
}
|
||||
}
|
||||
+14
-8
@@ -7,7 +7,7 @@ import io.github.miniplaceholders.common.PlaceholdersCommand;
|
||||
import io.github.miniplaceholders.common.PlaceholdersPlugin;
|
||||
import io.github.miniplaceholders.connect.InternalPlatform;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
@@ -24,7 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class FabricMod implements ModInitializer, PlaceholdersPlugin {
|
||||
public final class FabricServerMod implements DedicatedServerModInitializer, PlaceholdersPlugin {
|
||||
private final Logger logger = LoggerFactory.getLogger("miniplaceholders");
|
||||
private static final DecimalFormat MSPT_FORMAT = new DecimalFormat("###.###");
|
||||
|
||||
@@ -32,7 +32,7 @@ public class FabricMod implements ModInitializer, PlaceholdersPlugin {
|
||||
private MinecraftServer minecraftServer;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
public void onInitializeServer() {
|
||||
logger.info("Starting MiniPlaceholders Fabric");
|
||||
InternalPlatform.platform(InternalPlatform.FABRIC);
|
||||
|
||||
@@ -47,15 +47,21 @@ public class FabricMod implements ModInitializer, PlaceholdersPlugin {
|
||||
@Override
|
||||
public void loadDefaultExpansions() {
|
||||
Expansion.builder("server")
|
||||
.globalPlaceholder("name", Tag.preProcessParsed(this.minecraftServer.getServerModName()))
|
||||
.globalPlaceholder("name", Tag.selfClosingInserting(Component.text(this.minecraftServer.getServerModName())))
|
||||
.globalPlaceholder("online", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.minecraftServer.getPlayerCount())))
|
||||
.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("version", (ctx, queue) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getServerVersion())))
|
||||
.globalPlaceholder("max_players", (ctx, queue) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getMaxPlayers())))
|
||||
.globalPlaceholder("unique_joins", (queue, ctx) -> {
|
||||
final var profileCache = this.minecraftServer.getProfileCache();
|
||||
if (profileCache == null) {
|
||||
return null;
|
||||
}
|
||||
return Tag.preProcessParsed(Integer.toString(profileCache.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.preProcessParsed(Integer.toString(this.minecraftServer.getTickCount())))
|
||||
.globalPlaceholder("tick_count", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getTickCount())))
|
||||
.globalPlaceholder("has_whitelist", (queue, ctx) -> Tag.preProcessParsed(Boolean.toString(this.minecraftServer.getPlayerList().isUsingWhitelist())))
|
||||
.globalPlaceholder("total_chunks", (queue, ctx) -> {
|
||||
int chunks = 0;
|
||||
@@ -15,15 +15,18 @@
|
||||
"license": "Apache-2",
|
||||
"environment": "server",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"io.github.miniplaceholders.fabric.FabricMod"
|
||||
"server": [
|
||||
"io.github.miniplaceholders.fabric.FabricServerMod"
|
||||
],
|
||||
"client": [
|
||||
"io.github.miniplaceholders.fabric.FabricClientMod"
|
||||
]
|
||||
},
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.19",
|
||||
"fabric": "*",
|
||||
"java": ">=17",
|
||||
"minecraft": ">=1.20.2",
|
||||
"minecraft": ">=1.19.4",
|
||||
"fabric-permissions-api-v0": "*"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
group = io.github.miniplaceholders
|
||||
version = 2.3.0-SNAPSHOT
|
||||
version = 2.2.2
|
||||
description = MiniMessage Component-based Placeholders for Paper, Fabric, Sponge, Folia and Velocity platforms
|
||||
|
||||
org.gradle.jvmargs=-Xmx2G
|
||||
@@ -4,11 +4,12 @@ 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.3"
|
||||
runtask = "2.2.2"
|
||||
pluginyml = "0.6.0"
|
||||
userdev = "1.7.1"
|
||||
userdev = "1.5.9"
|
||||
blossom = "2.1.0"
|
||||
indra = "3.1.3"
|
||||
shadow = "8.1.1"
|
||||
@@ -16,13 +17,13 @@ jmh = "0.7.2"
|
||||
dokka = "1.9.10"
|
||||
|
||||
cloud = "1.8.4"
|
||||
adventure = "4.15.0"
|
||||
adventurefabric = "5.12.0"
|
||||
adventure = "4.14.0"
|
||||
adventurefabric = "5.10.1"
|
||||
brigadier = "1.0.500"
|
||||
kotlin="1.9.22"
|
||||
kotlin="1.9.20"
|
||||
|
||||
fabric-api = "0.96.4+1.20.5"
|
||||
fabric-loader = "0.15.7"
|
||||
fabric-api = "0.90.1+1.20.3"
|
||||
fabric-loader = "0.14.24"
|
||||
|
||||
desertwell = "2.0.4"
|
||||
|
||||
@@ -30,6 +31,7 @@ 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" }
|
||||
@@ -52,6 +54,8 @@ 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" }
|
||||
@@ -60,7 +64,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.2"
|
||||
junit-bom = "org.junit:junit-bom:5.10.1"
|
||||
|
||||
[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.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
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))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
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,6 +3,7 @@ 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;
|
||||
@@ -43,38 +44,38 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin
|
||||
@Override
|
||||
public void loadDefaultExpansions() {
|
||||
Expansion.builder("server")
|
||||
.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("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("total_chunks", (queue, ctx) -> {
|
||||
int chunkCount = 0;
|
||||
for (World world : this.getServer().getWorlds()){
|
||||
chunkCount += world.getLoadedChunks().length;
|
||||
}
|
||||
return Tag.preProcessParsed(Integer.toString(chunkCount));
|
||||
return TagsUtils.staticTag(Component.text(chunkCount));
|
||||
})
|
||||
.globalPlaceholder("total_entities", (queue, ctx) -> {
|
||||
int entityCount = 0;
|
||||
for (World world : this.getServer().getWorlds()){
|
||||
entityCount += world.getEntityCount();
|
||||
}
|
||||
return Tag.preProcessParsed(Integer.toString(entityCount));
|
||||
return TagsUtils.staticTag(Component.text(entityCount));
|
||||
})
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> Tag.preProcessParsed(MSPT_FORMAT.format(this.getServer().getAverageTickTime())))
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> TagsUtils.staticTag(MSPT_FORMAT.format(this.getServer().getAverageTickTime())))
|
||||
.globalPlaceholder("datapack_list", (queue, ctx) -> {
|
||||
final TextComponent.Builder builder = Component.text();
|
||||
for (final Datapack datapack : this.getServer().getDatapackManager().getEnabledPacks()) {
|
||||
for (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.preProcessParsed(Integer.toString(this.getServer().getDatapackManager().getEnabledPacks().size())))
|
||||
.globalPlaceholder("datapack_count", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.getServer().getDatapackManager().getEnabledPacks().size())))
|
||||
.build()
|
||||
.register();
|
||||
}
|
||||
|
||||
+2
-2
@@ -30,9 +30,9 @@ dependencyResolutionManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("fabric-loom") version "1.5.8"
|
||||
id("fabric-loom") version "1.4.4"
|
||||
id("org.spongepowered.gradle.plugin") version "2.2.0"
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
|
||||
}
|
||||
|
||||
arrayOf(
|
||||
|
||||
@@ -4,12 +4,13 @@ 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.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.Server;
|
||||
@@ -58,26 +59,26 @@ public class SpongePlugin implements PlaceholdersPlugin {
|
||||
@Override
|
||||
public void loadDefaultExpansions() {
|
||||
Expansion.builder("server")
|
||||
.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("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("total_chunks", (queue, ctx) -> {
|
||||
int chunkCount = 0;
|
||||
for (ServerWorld world : server.worldManager().worlds()){
|
||||
chunkCount += world.entities().size();
|
||||
}
|
||||
return Tag.preProcessParsed(Integer.toString(chunkCount));
|
||||
return TagsUtils.staticTag(Component.text(chunkCount));
|
||||
})
|
||||
.globalPlaceholder("total_entities", (queue, ctx) -> {
|
||||
int entityCount = 0;
|
||||
for (ServerWorld world : server.worldManager().worlds()){
|
||||
entityCount += world.entities().size();
|
||||
}
|
||||
return Tag.preProcessParsed(Integer.toString(entityCount));
|
||||
return TagsUtils.staticTag(Component.text(entityCount));
|
||||
})
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> Tag.preProcessParsed(Double.toString(server.averageTickTime())))
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> TagsUtils.staticTag(Component.text(server.averageTickTime())))
|
||||
.build()
|
||||
.register();
|
||||
|
||||
|
||||
@@ -15,10 +15,12 @@ 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;
|
||||
|
||||
@@ -65,14 +67,14 @@ public final class VelocityPlugin implements PlaceholdersPlugin {
|
||||
.map(size -> Integer.toString(size))
|
||||
.orElse("0"));
|
||||
}
|
||||
return Tag.preProcessParsed(Integer.toString(proxy.getPlayerCount()));
|
||||
return Tag.selfClosingInserting(Component.text(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 Tag.selfClosingInserting(proxy.getPlayer(playerName).isPresent() ? Components.YES_COMPONENT : Components.NO_COMPONENT);
|
||||
return TagsUtils.staticTag(proxy.getPlayer(playerName).isPresent() ? Components.YES_COMPONENT : Components.NO_COMPONENT);
|
||||
})
|
||||
.globalPlaceholder("version", Tag.preProcessParsed(proxy.getVersion().getVersion()))
|
||||
.globalPlaceholder("version", TagsUtils.staticTag(proxy.getVersion().getVersion()))
|
||||
.build()
|
||||
.register();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user