Compare commits
61
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 |
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 {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
group = io.github.miniplaceholders
|
||||
version = 2.2.3
|
||||
version = 2.3.0-SNAPSHOT
|
||||
description = MiniMessage Component-based Placeholders for Paper, Fabric, Sponge, Folia and Velocity platforms
|
||||
|
||||
org.gradle.jvmargs=-Xmx2G
|
||||
@@ -6,9 +6,9 @@ velocity = "3.2.0-SNAPSHOT"
|
||||
paper = "1.20.2-R0.1-SNAPSHOT"
|
||||
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"
|
||||
@@ -16,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"
|
||||
|
||||
@@ -60,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)*/
|
||||
}
|
||||
}
|
||||
+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(
|
||||
|
||||
Reference in new issue
Block a user