Compare commits

..
Author SHA1 Message Date
renovate[bot] 4a6a616211 chore(deps): update dependency io.papermc.paperweight.userdev to v1.7.1 2024-05-11 23:18:37 +00:00
Adrian 3808fc9d89 Add LegacyUtils methods to check if a string contains legacy characters (#191)
* feat: Add LegacyUtils methods to check if a string contains legacy characters

* chore: Rename to #mapLegacyOrElse
2024-03-03 15:48:43 -05:00
renovate[bot] a7cc73fe7d fix(deps): update dependency net.kyori:adventure-platform-fabric to v5.12.0 (#189)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-28 22:27:16 -05:00
renovate[bot] 8ac0c398d7 chore(deps): update plugin fabric-loom to v1.5.8 (#190)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-28 22:27:07 -05:00
renovate[bot] 25618c0d42 fix(deps): update dependency net.fabricmc.fabric-api:fabric-api to v0.96.4+1.20.5 (#187)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-28 22:27:00 -05:00
renovate[bot] 9b61e8efa0 fix(deps): update dependency net.fabricmc.fabric-api:fabric-api to v0.96.2+1.20.5 (#177)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-17 09:37:01 -05:00
renovate[bot] ad95e239bc fix(deps): update dependency net.fabricmc:fabric-loader to v0.15.7 (#184)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-15 12:14:09 -05:00
powercas_gamer d18ff640d2 feat(api): expansion metadata (#185)
* feat(api): expansion metadata

* more

* actually expose it

* javadoc

* oopsie whoopsie import

* change javadoc version
2024-02-15 12:13:47 -05:00
Adrian 7536d32055 Merge pull request #182 from MiniPlaceholders/renovate/runtask
chore(deps): update dependency xyz.jpenilla.run-velocity to v2.2.3
2024-02-04 15:14:01 -05:00
Adrian 5dffb9c251 Merge pull request #183 from MiniPlaceholders/renovate/junit5-monorepo
fix(deps): update dependency org.junit:junit-bom to v5.10.2
2024-02-04 15:13:54 -05:00
renovate[bot] e75baceb77 fix(deps): update dependency org.junit:junit-bom to v5.10.2 2024-02-04 11:23:07 +00:00
renovate[bot] 16e3d09204 chore(deps): update runtask to v2.2.3 2024-02-04 02:55:42 +00:00
7 changed files with 154 additions and 13 deletions

No files matched your search

@@ -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);
}
}
}
@@ -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);
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
group = io.github.miniplaceholders
version = 2.2.4
version = 2.3.0-SNAPSHOT
description = MiniMessage Component-based Placeholders for Paper, Fabric, Sponge, Folia and Velocity platforms
org.gradle.jvmargs=-Xmx2G
+6 -6
View File
@@ -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.11"
userdev = "1.7.1"
blossom = "2.1.0"
indra = "3.1.3"
shadow = "8.1.1"
@@ -17,12 +17,12 @@ dokka = "1.9.10"
cloud = "1.8.4"
adventure = "4.15.0"
adventurefabric = "5.11.0"
adventurefabric = "5.12.0"
brigadier = "1.0.500"
kotlin="1.9.22"
fabric-api = "0.93.1+1.20.5"
fabric-loader = "0.15.6"
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]
+1 -1
View File
@@ -30,7 +30,7 @@ dependencyResolutionManagement {
}
plugins {
id("fabric-loom") version "1.5.7"
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.8.0"
}