Compare commits

...
Author SHA1 Message Date
Adrian Gonzales eb4fba66eb misc: 3.1.1-SNAPSHOT 2025-10-10 03:05:27 -05:00
Adrian Gonzales 6a084a6d2e release: Version 3.1.0 2025-10-10 02:35:19 -05:00
Adrian Gonzales d02ac7abc1 [ci skip] Created CHANGELOG.md 2025-10-09 18:59:53 -05:00
Adrian 9bcefee265 Merge pull request #305 from MiniPlaceholders/renovate/fabric.loader
fix(deps): update dependency net.fabricmc:fabric-loader to v0.17.3
2025-10-09 18:42:13 -05:00
Adrian 47dd5a96e9 Merge pull request #302 from MiniPlaceholders/renovate/runtask
fix(deps): update runtask to v3.0.1
2025-10-09 18:42:02 -05:00
renovate[bot] 36dbeed21d fix(deps): update dependency net.fabricmc:fabric-loader to v0.17.3 2025-10-09 17:07:35 +00:00
renovate[bot] e19527a9d6 fix(deps): update runtask to v3.0.1 2025-10-09 12:44:34 +00:00
Adrian Gonzales f648dd8f83 misc: Added bstats metrics 2025-10-09 00:31:50 -05:00
Adrian Gonzales 079b88d99f docs: Use the NullMarked annotation throughout the module instead of in each file 2025-10-08 23:12:44 -05:00
Adrian Gonzales 0f48a4baed docs: Replaced some uses of JetBrains annotations with jspecify
This fixes a duplication of annotations in the generation of javadocs
2025-10-08 12:43:32 -05:00
Adrian Gonzales 2608e81fae fix: Enable expansion providers after the server initializes.
This allows all other plugins to initialize, and if any depend on MiniPlaceholders, they can register their expansions. After the server initializes, expansion providers will be enabled, and if anyone wants to remove an expansion or iterate between them, they can simply use a higher priority for late server initialization events
2025-10-08 12:04:18 -05:00
Adrian Gonzales afb4a4451d build: Added testing support for fabric and sponge modules 2025-10-05 01:27:09 -05:00
Adrian Gonzales df53a0a2fa build: Simplify example expansion loading 2025-10-05 00:52:33 -05:00
Adrian Gonzales 591df2e6df feat(build): Added the capability to test the example expansion using runtask 2025-10-05 00:33:35 -05:00
Adrian Gonzales bf995b7103 feat: Allow the use of injected constructors when creating an ExpansionProvider 2025-10-05 00:32:22 -05:00
Adrian Gonzales 02f30ead85 misc: Added deprecation message 2025-10-04 23:11:09 -05:00
51 changed files with 445 additions and 229 deletions

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
<!--
MiniPlaceholders Changelog
-->
## 3.1.1 (unreleased)
### Features
### Fixes
### API Additions
## 3.1.0 (10/10/2025)
### Features
- [feat: Sponge commands implementation](https://github.com/MiniPlaceholders/MiniPlaceholders/commit/7633ada70ed62571b707cbf709fbb5c027c44f46)
- [feat: Implement parserel subcommand](https://github.com/MiniPlaceholders/MiniPlaceholders/commit/ea725a81210911a8779545781b56a647d6b84cf3)
- [feat: Add --null argument to parse node](https://github.com/MiniPlaceholders/MiniPlaceholders/commit/3cdb7de9f2e675f494c84df693142a817535fe9a)
- [misc: Added bstats metrics](https://github.com/MiniPlaceholders/MiniPlaceholders/commit/f648dd8f836d5f2911eaf0bc53f6769ed2a0fdcc)
### Fixes
- [fix: Fixed multiple loading expansions](https://github.com/MiniPlaceholders/MiniPlaceholders/commit/f67690f41347031a32d4acd7bb4bb493b42bb4f9)
- [fix: Added nullability checks to RelationalAudience](https://github.com/MiniPlaceholders/MiniPlaceholders/commit/8aec3e592ff6774737602a3a3a6187ddb577a681)
- [fix: Fixed command formatting](https://github.com/MiniPlaceholders/MiniPlaceholders/commit/de7d14d55d6aeff8dbaf1706dd06bb6812b54390)
### API Additions
- [feat: Added LoadRequirement#requiredClass and LoadRequirement#anyOf](https://github.com/MiniPlaceholders/MiniPlaceholders/commit/31ee16e41234cabf992736f81eda5bbbdc09d954)
- [docs: Replaced some uses of JetBrains annotations with jspecify](https://github.com/MiniPlaceholders/MiniPlaceholders/commit/0f48a4baed91ec5d0fe285649822f189e69a5b57)
- [feat: Allow the use of injected constructors when creating an ExpansionProvider](https://github.com/MiniPlaceholders/MiniPlaceholders/commit/bf995b71030064a174532d38282407ab6baa7170)
+2 -1
View File
@@ -40,7 +40,8 @@ tasks {
o.encoding = Charsets.UTF_8.name()
o.links(
"https://jd.advntr.dev/api/${libs.versions.adventure.get()}/",
"https://jd.advntr.dev/text-minimessage/${libs.versions.adventure.get()}/"
"https://jd.advntr.dev/text-minimessage/${libs.versions.adventure.get()}/",
"https://javadoc.io/doc/org.jspecify/jspecify/latest/index.html"
)
o.tags(
"apiNote:a:API Note:",
@@ -13,7 +13,7 @@ import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import java.util.Collection;
@@ -37,7 +37,6 @@ import java.util.Collection;
*
* @since 1.0.0
*/
@NullMarked
public sealed interface Expansion permits ExpansionImpl {
/**
* Get the expansion name
@@ -111,8 +110,6 @@ public sealed interface Expansion permits ExpansionImpl {
*/
boolean registered();
// TODO: Docs and Tests
/**
* Get the registered audience placeholders
*
@@ -216,6 +213,8 @@ public sealed interface Expansion permits ExpansionImpl {
/**
* Get a shorter ToString with the details of this expansion.
* @return a shorter ToString
* @deprecated Starting with MiniPlaceholders 3.1, the way loaded expansions
* are displayed in the console has changed, so this method is no longer used
*/
@ApiStatus.Internal
@Deprecated(forRemoval = true, since = "3.1.0")
@@ -8,9 +8,8 @@ import io.github.miniplaceholders.api.types.PlaceholderType;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.intellij.lang.annotations.Subst;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.jspecify.annotations.NullUnmarked;
import java.util.*;
@@ -18,7 +17,6 @@ import java.util.*;
import static io.github.miniplaceholders.api.utils.Conditions.nonNullOrEmptyString;
import static java.util.Objects.requireNonNull;
@NullMarked
final class ExpansionImpl implements Expansion {
private static final AudiencePlaceholder<?>[] EMPTY_SINGLE_AUDIENCE = new AudiencePlaceholder[0];
private static final RelationalPlaceholder<?>[] EMPTY_RELATIONAL_AUDIENCE = new RelationalPlaceholder[0];
@@ -34,23 +32,23 @@ final class ExpansionImpl implements Expansion {
private final String version;
ExpansionImpl(
final String expansionName,
@Nullable final Collection<AudiencePlaceholder<?>> audiencePlaceholders,
@Nullable final Collection<RelationalPlaceholder<?>> relationalPlaceholders,
@Nullable final Collection<GlobalPlaceholder> globalPlaceholders,
@Nullable final String author,
@Nullable final String version
final String expansionName,
@Nullable final Collection<AudiencePlaceholder<?>> audiencePlaceholders,
@Nullable final Collection<RelationalPlaceholder<?>> relationalPlaceholders,
@Nullable final Collection<GlobalPlaceholder> globalPlaceholders,
@Nullable final String author,
@Nullable final String version
) {
this.name = expansionName;
this.audiencePlaceholders = audiencePlaceholders != null
? new PlaceholderTagResolver(audiencePlaceholders.toArray(EMPTY_SINGLE_AUDIENCE))
: PlaceholderTagResolver.EMPTY;
? new PlaceholderTagResolver(audiencePlaceholders.toArray(EMPTY_SINGLE_AUDIENCE))
: PlaceholderTagResolver.EMPTY;
this.relationalPlaceholders = relationalPlaceholders != null
? new PlaceholderTagResolver(relationalPlaceholders.toArray(EMPTY_RELATIONAL_AUDIENCE))
: PlaceholderTagResolver.EMPTY;
? new PlaceholderTagResolver(relationalPlaceholders.toArray(EMPTY_RELATIONAL_AUDIENCE))
: PlaceholderTagResolver.EMPTY;
this.globalPlaceholders = globalPlaceholders == null
? PlaceholderTagResolver.EMPTY
: new PlaceholderTagResolver(globalPlaceholders.toArray(EMPTY_GLOBAL_PLACEHOLDER));
? PlaceholderTagResolver.EMPTY
: new PlaceholderTagResolver(globalPlaceholders.toArray(EMPTY_GLOBAL_PLACEHOLDER));
this.author = author;
this.version = version;
}
@@ -174,16 +172,16 @@ final class ExpansionImpl implements Expansion {
private String author;
private String version;
Builder(@NotNull final String name) {
Builder(final @NonNull String name) {
this.expansionName = nonNullOrEmptyString(name, "Expansion name");
this.expansionPrefix = name.toLowerCase(Locale.ROOT).concat("_");
}
@Override
public <A extends Audience> @NotNull Builder audiencePlaceholder(
final @Nullable Class<A> targetClass,
@Subst("name") final @NotNull String key,
final @NotNull AudienceTagResolver<@NotNull A> audiencePlaceholder
public <A extends Audience> @NonNull Builder audiencePlaceholder(
final @Nullable Class<A> targetClass,
final @Subst("name") @NonNull String key,
final @NonNull AudienceTagResolver<@NonNull A> audiencePlaceholder
) {
nonNullOrEmptyString(key, "Placeholder key");
requireNonNull(audiencePlaceholder, "the audience placeholder cannot be null");
@@ -195,10 +193,10 @@ final class ExpansionImpl implements Expansion {
}
@Override
public <A extends Audience> @NotNull Builder relationalPlaceholder(
@Nullable Class<A> targetClass,
@Subst("relation") @NotNull String key,
@NotNull RelationalTagResolver<@NotNull A> relationalPlaceholder
public <A extends Audience> @NonNull Builder relationalPlaceholder(
final Class<A> targetClass,
final @Subst("relation") @NonNull String key,
final @NonNull RelationalTagResolver<@NonNull A> relationalPlaceholder
) {
nonNullOrEmptyString(key, "Placeholder key");
requireNonNull(relationalPlaceholder, "the relational placeholder cannot be null");
@@ -211,9 +209,9 @@ final class ExpansionImpl implements Expansion {
}
@Override
public @NotNull Builder globalPlaceholder(
@Subst("time") @NotNull final String key,
@NotNull final GlobalTagResolver function
public @NonNull Builder globalPlaceholder(
final @Subst("time") @NonNull String key,
final @NonNull GlobalTagResolver function
) {
nonNullOrEmptyString(key, "Placeholder key");
requireNonNull(function, "the global placeholder cannot be null");
@@ -226,26 +224,26 @@ final class ExpansionImpl implements Expansion {
}
@Override
public Expansion.@NotNull Builder author(@Nullable final String author) {
public @NonNull Builder author(final @Nullable String author) {
this.author = author;
return this;
}
@Override
public Expansion.@NotNull Builder version(@Nullable final String version) {
public @NonNull Builder version(final @Nullable String version) {
this.version = version;
return this;
}
@Override
public @NotNull Expansion build() {
public @NonNull Expansion build() {
return new ExpansionImpl(
this.expansionName,
this.audiencePlaceholders,
this.relationalPlaceholders,
this.globalPlaceholders,
this.author,
this.version
this.expansionName,
this.audiencePlaceholders,
this.relationalPlaceholders,
this.globalPlaceholders,
this.author,
this.version
);
}
}
@@ -266,12 +264,12 @@ final class ExpansionImpl implements Expansion {
@Override
public String toString() {
return "ExpansionImpl{" +
"name='" + name + '\'' +
", audiencePlaceholders=" + audiencePlaceholders +
", relationalPlaceholders=" + relationalPlaceholders +
", globalPlaceholders=" + globalPlaceholders +
", author='" + author + '\'' +
", version='" + version + '\'' +
'}';
"name='" + name + '\'' +
", audiencePlaceholders=" + audiencePlaceholders +
", relationalPlaceholders=" + relationalPlaceholders +
", globalPlaceholders=" + globalPlaceholders +
", author='" + author + '\'' +
", version='" + version + '\'' +
'}';
}
}
@@ -6,8 +6,8 @@ import io.github.miniplaceholders.api.types.RelationalAudience;
import io.github.miniplaceholders.connect.InternalPlatform;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import org.jspecify.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
@@ -39,7 +39,7 @@ public final class MiniPlaceholders {
* @return the platform
* @since 3.0.0
*/
public static @NotNull Platform platform() {
public static Platform platform() {
return switch (InternalPlatform.platform()) {
case PAPER -> Platform.PAPER;
case VELOCITY -> Platform.VELOCITY;
@@ -58,7 +58,7 @@ public final class MiniPlaceholders {
* @see TagResolver
* @since 3.0.0
*/
public static @NotNull TagResolver globalPlaceholders() {
public static TagResolver globalPlaceholders() {
final TagResolver.Builder builder = TagResolver.builder();
for (final Expansion expansion : expansions) {
final TagResolver resolver = expansion.globalPlaceholders();
@@ -79,7 +79,7 @@ public final class MiniPlaceholders {
* @return {@link TagResolver} with placeholders based on an audience
* @since 3.0.0
*/
public static @NotNull TagResolver audiencePlaceholders() {
public static TagResolver audiencePlaceholders() {
final TagResolver.Builder resolvers = TagResolver.builder();
for (final Expansion expansion : expansions) {
final TagResolver resolver = expansion.audiencePlaceholders();
@@ -103,7 +103,7 @@ public final class MiniPlaceholders {
* @since 3.0.0
* @see RelationalAudience
*/
public static @NotNull TagResolver relationalPlaceholders() {
public static TagResolver relationalPlaceholders() {
final TagResolver.Builder builder = TagResolver.builder();
for (final Expansion expansion : expansions) {
applyIfNotEmpty(expansion.relationalPlaceholders(), builder);
@@ -132,7 +132,7 @@ public final class MiniPlaceholders {
* @return {@link TagResolver} with placeholders based on an audience and the global placeholders
* @since 1.1.0
*/
public static @NotNull TagResolver audienceGlobalPlaceholders() {
public static TagResolver audienceGlobalPlaceholders() {
final TagResolver.Builder builder = TagResolver.builder();
for (final Expansion expansion : expansions) {
@@ -164,7 +164,7 @@ public final class MiniPlaceholders {
* @apiNote In the case of audience placeholders, the audience to be used will be the {@link RelationalAudience#audience()}
* @see RelationalAudience
*/
public static @NotNull TagResolver relationalGlobalPlaceholders() {
public static TagResolver relationalGlobalPlaceholders() {
final TagResolver.Builder builder = TagResolver.builder();
for (final Expansion expansion : expansions) {
applyIfNotEmpty(expansion.audiencePlaceholders(), builder);
@@ -221,7 +221,7 @@ public final class MiniPlaceholders {
* @see Expansion#builder(String)
* @since 3.0.0
*/
public static @Nullable Expansion expansionByName(final @NotNull String name) {
public static @Nullable Expansion expansionByName(final String name) {
for (final Expansion expansion : expansions) {
if (Objects.equals(expansion.name(), name)) {
return expansion;
@@ -236,6 +236,7 @@ public final class MiniPlaceholders {
* @return all available registered expansions
* @since 3.0.0
*/
@Unmodifiable
public static Collection<Expansion> expansionsAvailable() {
return Collections.unmodifiableSet(expansions);
}
@@ -9,7 +9,6 @@ import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.TagPattern;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import java.util.Objects;
@@ -24,7 +23,6 @@ import static java.util.Objects.requireNonNull;
* @param resolver the object responsible for obtaining audience information
* @param <A> the parametrized type
*/
@NullMarked
public record AudiencePlaceholder<A extends Audience>(
@Nullable Class<A> targetClass,
@TagPattern String key,
@@ -5,8 +5,7 @@ import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.TagPattern;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;
import java.util.Objects;
@@ -20,17 +19,17 @@ import java.util.Objects;
*/
public record GlobalPlaceholder(@TagPattern String key, String name, GlobalTagResolver resolver) implements Placeholder {
@Override
public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) {
public @Nullable Tag resolve(final String name, final ArgumentQueue arguments, final Context ctx) {
return this.has(name) ? resolver.tag(arguments, ctx) : null;
}
@Override
public boolean has(@NotNull String name) {
public boolean has(final String name) {
return key.equalsIgnoreCase(name);
}
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
@@ -1,12 +1,10 @@
package io.github.miniplaceholders.api.placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.jspecify.annotations.NullMarked;
/**
* Base class of all Placeholders
*/
@NullMarked
public sealed interface Placeholder extends TagResolver permits AudiencePlaceholder, GlobalPlaceholder, RelationalPlaceholder {
/**
* The key of this placeholder.<br>
@@ -5,7 +5,6 @@ import net.kyori.adventure.text.minimessage.ParsingException;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -16,7 +15,7 @@ public record PlaceholderTagResolver(Placeholder... placeholders) implements Tag
public static final PlaceholderTagResolver EMPTY = new PlaceholderTagResolver();
@Override
public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) throws ParsingException {
public @Nullable Tag resolve(final String name, final ArgumentQueue arguments, final Context ctx) throws ParsingException {
@Nullable Tag tag;
for (final Placeholder placeholder : placeholders) {
tag = placeholder.resolve(name, arguments, ctx);
@@ -28,7 +27,7 @@ public record PlaceholderTagResolver(Placeholder... placeholders) implements Tag
}
@Override
public boolean has(final @NotNull String name) {
public boolean has(final String name) {
for (final Placeholder placeholder : placeholders) {
if (placeholder.has(name)) {
return true;
@@ -9,9 +9,7 @@ import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.TagPattern;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import java.util.Objects;
@@ -24,47 +22,46 @@ import static java.util.Objects.requireNonNull;
* using a type-safe filter and a relational resolver.
*
* @param targetClass the target class, can be null
* @param key the key of the entire placeholder
* @param name the name of this placeholder
* @param resolver the relational resolver,
* in charge of obtaining data based on a relationship of 2 audiences
* @param <A> the audience type, if not specified, will be a generic {@linkplain Audience}
* @see RelationalTagResolver
* @param key the key of the entire placeholder
* @param name the name of this placeholder
* @param resolver the relational resolver,
* in charge of obtaining data based on a relationship of 2 audiences
* @param <A> the audience type, if not specified, will be a generic {@linkplain Audience}
* @apiNote The {@link #key()} method returns the full name of the placeholder,
* for example, if the placeholder is {@code <server_name>},
* the {@linkplain #key()} method will return {@code server_name}.
* @see RelationalTagResolver
*/
@NullMarked
public record RelationalPlaceholder<A extends Audience>(
@Nullable Class<A> targetClass,
@TagPattern String key,
String name,
RelationalTagResolver<A> resolver
@Nullable Class<A> targetClass,
@TagPattern String key,
String name,
RelationalTagResolver<A> resolver
) implements Placeholder {
/**
* Static method capable of creating an instance of a relational placeholder.
*
* @param targetClass the target class, can be null
* @param key the key of the entire placeholder
* @param name the name of this placeholder
* @param resolver the relational resolver,
* in charge of obtaining data based on a relationship of 2 audiences
* @param key the key of the entire placeholder
* @param name the name of this placeholder
* @param resolver the relational resolver,
* in charge of obtaining data based on a relationship of 2 audiences
* @param <A> the audience type, if not specified, will be a generic {@linkplain Audience}
* @return a new RelationalPlaceholder
* @param <A> the audience type, if not specified, will be a generic {@linkplain Audience}
* @since 3.0.0
*/
public static <A extends Audience> RelationalPlaceholder<A> relational(
@Nullable Class<A> targetClass,
@TagPattern String key,
String name,
RelationalTagResolver<A> resolver
final @Nullable Class<A> targetClass,
final @TagPattern String key,
final String name,
final RelationalTagResolver<A> resolver
) {
return new RelationalPlaceholder<>(targetClass, requireNonNull(key), name, requireNonNull(resolver));
}
@Override
public @Nullable Tag resolve(String name, ArgumentQueue arguments, Context ctx) {
public @Nullable Tag resolve(final String name, final ArgumentQueue arguments, final Context ctx) {
final Pointered targetRaw = ctx.target();
if (targetRaw == null) {
return null;
@@ -74,7 +71,7 @@ public record RelationalPlaceholder<A extends Audience>(
}
if (targetClass == null) {
//noinspection unchecked
return this.resolveA(name, (A)a, (A)b, arguments, ctx);
return this.resolveA(name, (A) a, (A) b, arguments, ctx);
}
final @Nullable A audience = forwardingFilter(a);
if (audience == null) {
@@ -88,15 +85,15 @@ public record RelationalPlaceholder<A extends Audience>(
}
private @Nullable Tag resolveA(
String name,
A audience,
A relationalAudience,
ArgumentQueue arguments,
Context ctx
final String name,
final A audience,
final A relationalAudience,
final ArgumentQueue arguments,
final Context ctx
) {
return this.has(name)
? resolver.tag(audience, relationalAudience, arguments, ctx)
: null;
? resolver.tag(audience, relationalAudience, arguments, ctx)
: null;
}
@SuppressWarnings("OverrideOnly")
@@ -112,7 +109,7 @@ public record RelationalPlaceholder<A extends Audience>(
}
@Override
public boolean has(@NotNull String name) {
public boolean has(final String name) {
return key.equalsIgnoreCase(name);
}
@@ -131,7 +128,7 @@ public record RelationalPlaceholder<A extends Audience>(
@Override
public String toString() {
return "RelationalPlaceholder{" +
"key='" + key + '\'' +
'}';
"key='" + key + '\'' +
'}';
}
}
@@ -5,9 +5,8 @@ import org.intellij.lang.annotations.Pattern;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
import java.util.Arrays;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.util.Objects.requireNonNull;
@@ -17,7 +16,6 @@ import static java.util.Objects.requireNonNull;
*
* @since 3.0.0
*/
@NullMarked
public sealed interface LoadRequirement {
/**
@@ -162,6 +160,12 @@ public sealed interface LoadRequirement {
@ApiStatus.Internal
@NullMarked
record MultiLoadRequirement(LoadRequirement... requirements) implements LoadRequirement {
@Override
public String toString() {
return "MultiLoadRequirement{" +
"requirements=" + Arrays.toString(requirements) +
'}';
}
}
/**
@@ -175,11 +179,8 @@ public sealed interface LoadRequirement {
record PlatformRequirement(Platform... platforms) implements LoadRequirement {
@Override
public String toString() {
final String platforms = Stream.of(this.platforms)
.map(Platform::name)
.collect(Collectors.joining(", "));
return "PlatformRequirement{" +
"platforms=" + platforms +
"platforms=" + Arrays.toString(platforms()) +
'}';
}
}
@@ -212,5 +213,11 @@ public sealed interface LoadRequirement {
@ApiStatus.Internal
@NullMarked
record AnyOfRequirement(LoadRequirement... requirements) implements LoadRequirement {
@Override
public String toString() {
return "AnyOfRequirement{" +
"requirements=" + Arrays.toString(requirements) +
'}';
}
}
}
@@ -0,0 +1,6 @@
/**
* Package responsible for providing tools to load expansions provided through installable files
*
* @since 3.0.0
*/
package io.github.miniplaceholders.api.provider;
@@ -1,12 +1,10 @@
package io.github.miniplaceholders.api.resolver;
import org.jetbrains.annotations.Nullable;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
/**
* Audience Placeholder based on an Audience
@@ -14,7 +12,6 @@ import org.jspecify.annotations.NullMarked;
* @param <A> the audience type
*/
@FunctionalInterface
@NullMarked
public interface AudienceTagResolver<A extends Audience> {
/**
* A Tag based on an Audience
@@ -3,7 +3,6 @@ package io.github.miniplaceholders.api.resolver;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
/**
@@ -20,5 +19,5 @@ public interface GlobalTagResolver {
* @since 3.0.0
*/
@Nullable
Tag tag(@NonNull ArgumentQueue queue, @NonNull Context context);
Tag tag(ArgumentQueue queue, Context context);
}
@@ -4,8 +4,7 @@ import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
/**
* Relational Placeholder based on two Audiences.
@@ -15,7 +14,6 @@ import org.jspecify.annotations.NullMarked;
* @since 3.0.0
*/
@FunctionalInterface
@NullMarked
public interface RelationalTagResolver<A extends Audience> {
/**
* A Tag based on two audiences
@@ -2,7 +2,6 @@ package io.github.miniplaceholders.api.types;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience;
import org.jspecify.annotations.NullMarked;
import static java.util.Objects.requireNonNull;
@@ -14,7 +13,6 @@ import static java.util.Objects.requireNonNull;
* @param <A> the audiences type
* @since 3.0.0
*/
@NullMarked
public record RelationalAudience<A extends Audience>(A audience, A relational) implements ForwardingAudience.Single {
public RelationalAudience {
requireNonNull(audience);
@@ -1,2 +1,4 @@
/**Plugin enums */
/**
* Plugin types
*/
package io.github.miniplaceholders.api.types;
@@ -4,7 +4,9 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
/**Common components used in expansions */
/**
* Common components used in expansions
*/
public final class Components {
private Components(){}
/**
@@ -1,7 +1,6 @@
package io.github.miniplaceholders.api.utils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;
import java.util.function.Supplier;
@@ -23,7 +22,7 @@ public final class Conditions {
* @throws IllegalStateException if the provided string is empty
* @since 1.0.0
*/
public static String nonNullOrEmptyString(@Nullable String string, @NotNull Supplier<@NotNull String> name) {
public static String nonNullOrEmptyString(final @Nullable String string, final Supplier<String> name) {
if (string == null)
throw new NullPointerException(name.get() + " cannot be null");
if (string.isBlank())
@@ -40,7 +39,7 @@ public final class Conditions {
* @throws IllegalStateException if the provided string is empty
* @since 2.2.0
*/
public static String nonNullOrEmptyString(@Nullable String string, @NotNull String name) {
public static String nonNullOrEmptyString(final @Nullable String string, final String name) {
if (string == null)
throw new NullPointerException(name + " cannot be null");
if (string.isBlank())
@@ -57,7 +56,7 @@ public final class Conditions {
* @throws IllegalStateException if the provided string is empty
* @since 1.0.0
*/
public static String nonEmptyString(@NotNull String string, @NotNull Supplier<@NotNull String> reason) {
public static String nonEmptyString(final String string, final Supplier<String> reason) {
if (string.isBlank()) throw new IllegalStateException(reason.get());
return string;
}
@@ -71,7 +70,7 @@ public final class Conditions {
* @throws IllegalStateException if the provided string is empty
* @since 2.2.0
*/
public static String nonEmptyString(@NotNull String string, @NotNull String reason) {
public static String nonEmptyString(final String string, final String reason) {
if (string.isBlank()) throw new IllegalStateException(reason);
return string;
}
@@ -4,8 +4,7 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.function.Function;
@@ -17,7 +16,6 @@ import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
*
* @since 3.0.0
*/
@NullMarked
public final class LegacyStrings {
private LegacyStrings() {
}
@@ -26,7 +24,10 @@ public final class LegacyStrings {
* Legacy serializer with hex support
* <p>Use this as the last available alternative,
* it is recommended to use MiniMessage instead of this serializer</p>
*
* @deprecated Legacy format “support” will be removed in future versions
*/
@Deprecated(since = "3.1.0")
public static final LegacyComponentSerializer LEGACY_HEX_SERIALIZER = LegacyComponentSerializer.builder()
.character('&')
.hexColors()
@@ -1,14 +1,12 @@
package io.github.miniplaceholders.api.utils;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.jspecify.annotations.NullMarked;
/**
* Class of utilities to manage TagResolvers.
*
* @since 1.2.0
*/
@NullMarked
public final class Resolvers {
private Resolvers() {}
@@ -6,7 +6,7 @@ import io.github.miniplaceholders.api.resolver.RelationalTagResolver;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
/**
* Tags basic instances.
@@ -29,7 +29,7 @@ public final class Tags {
*
* @since 3.0.0
*/
public static final Tag NULL_TAG = null;
public static final @Nullable Tag NULL_TAG = null;
/**
* An Audience placeholder that returns a null Tag
@@ -38,7 +38,7 @@ public final class Tags {
* @return an empty audience resolver
* @since 3.0.0
*/
public static <A extends Audience> AudienceTagResolver<@NonNull A> emptyAudienceResolver() {
public static <A extends Audience> AudienceTagResolver<A> emptyAudienceResolver() {
return (audience, queue, ctx) -> NULL_TAG;
}
@@ -49,17 +49,10 @@ public final class Tags {
* @return an empty relational resolver
* @since 3.0.0
*/
public static <A extends Audience> RelationalTagResolver<@NonNull A> emptyRelationalResolver() {
public static <A extends Audience> RelationalTagResolver<A> emptyRelationalResolver() {
return (audience, relational, queue, ctx) -> NULL_TAG;
}
/**
* A Global placeholder that returns a null tag
*
* @since 3.0.0
*/
private static final GlobalTagResolver EMPTY_GLOBAL_PLACEHOLDER = (queue, ctx) -> NULL_TAG;
/**
* A Global placeholder that returns a null tag
*
@@ -67,7 +60,7 @@ public final class Tags {
* @return an empty global placeholder
*/
public static GlobalTagResolver emptyGlobalPlaceholder() {
return EMPTY_GLOBAL_PLACEHOLDER;
return (queue, ctx) -> NULL_TAG;
}
}
+3
View File
@@ -1,6 +1,9 @@
import org.jspecify.annotations.NullMarked;
/**
* MiniPlaceholders API Module
*/
@NullMarked
open module io.github.miniplaceholders.api {
requires io.github.miniplaceholders.connect;
@@ -10,10 +10,9 @@ import net.kyori.adventure.text.minimessage.tag.ParserDirective;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NonNull;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TagTest implements MiniTest {
@@ -35,7 +34,7 @@ public class TagTest implements MiniTest {
public record FilteringTag(ArgumentQueue queue, Context context) implements Modifying {
@Override
public Component apply(@NotNull Component current, int depth) {
public Component apply(@NonNull Component current, int depth) {
if (depth != 0) {
return Component.empty();
}
@@ -1,7 +1,7 @@
package io.github.miniplaceholders.test.instances;
import org.jetbrains.annotations.NotNull;
import net.kyori.adventure.audience.Audience;
import org.jspecify.annotations.NullMarked;
public record TestAudience(@NotNull String name) implements Audience {}
@NullMarked
public record TestAudience(String name) implements Audience {}
@@ -1,11 +1,12 @@
package io.github.miniplaceholders.test.instances;
import net.kyori.adventure.audience.ForwardingAudience;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;
@NullMarked
public record TestAudienceHolder(TestAudience audience) implements ForwardingAudience.Single {
@Override
public @NotNull TestAudience audience() {
public TestAudience audience() {
return audience;
}
}
+1
View File
@@ -5,6 +5,7 @@ plugins {
dependencies {
implementation(libs.plugin.shadow)
implementation(libs.plugin.kotlin)
implementation(libs.plugin.runtask)
}
repositories {
+1 -1
View File
@@ -4,4 +4,4 @@ val Project.capitalizeName: String
get() = this.name.substring(17)
.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
fun Project.simpleName(): String = this.name.substring(17)
fun Project.simpleName(): String = this.name.substring(17)
@@ -23,6 +23,6 @@ tasks {
java{
toolchain{
languageVersion.set(JavaLanguageVersion.of(21))
//vendor.set(JvmVendorSpec.ADOPTIUM)
vendor.set(JvmVendorSpec.AZUL)
}
}
@@ -0,0 +1,32 @@
import org.gradle.api.tasks.bundling.Jar
import xyz.jpenilla.runtask.task.RunWithPlugins
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import kotlin.io.path.deleteIfExists
tasks {
withType<RunWithPlugins> {
val exampleExpansionProviderProject = project(":miniplaceholders-example-expansion-provider")
val exampleExpansionJarTask = exampleExpansionProviderProject.tasks.named<Jar>("jar")
dependsOn(exampleExpansionJarTask)
doFirst {
val folderName = if (project.name.contains("velocity")) "miniplaceholders" else "MiniPlaceholders"
val expansionsDirectory = runDirectory.get().file("plugins/$folderName/expansions").asFile.toPath()
if (Files.exists(expansionsDirectory)) {
Files.newDirectoryStream(expansionsDirectory).use {
it.forEach { file ->
file.deleteIfExists()
}
}
} else {
Files.createDirectories(expansionsDirectory)
}
val exampleExpansionFile = exampleExpansionJarTask.get().archiveFile.get().asFile.toPath()
Files.copy(
exampleExpansionFile,
expansionsDirectory.resolve(exampleExpansionFile.fileName),
StandardCopyOption.REPLACE_EXISTING
)
}
}
}
@@ -9,10 +9,8 @@ tasks {
archiveClassifier.set("")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
relocate("net.william278.desertwell", "io.github.miniplaceholders.libs.desertwell")
relocate("org.incendo.cloud", "io.github.miniplaceholders.libs.cloud")
// if (project.simpleName() != "sponge") {
// relocate("io.leangen.geantyref", "io.github.miniplaceholders.libs.geantyref")
// }
relocate("org.bstats", "io.github.miniplaceholders.libs.bstats")
destinationDirectory.set(file("${project.rootDir}/jar"))
}
build {
+1
View File
@@ -14,6 +14,7 @@ dependencies {
compileOnly(libs.adventure.minimessage)
compileOnly(libs.jspecify)
compileOnly(libs.brigadier)
compileOnly(libs.bstats.core)
}
sourceSets {
@@ -23,13 +23,13 @@ public interface PlaceholdersPlugin {
default void registerPlatformCommand() {
}
default void loadProvidedExpansions(Path providersFolderDirectory) throws Exception {
default void loadProvidedExpansions(final Path providersFolderDirectory) throws Exception {
final List<Expansion> loadedExpansions = new ArrayList<>();
final PlatformData platformData = new PlatformData(this.platformServerInstance(), this);
final Injector injector = Injector.create(binder -> binder.bind(PlatformData.class).toInstance(platformData));
for (ExpansionProvider provider : ExpansionProviderLoader.loadProvidersFromFolder(providersFolderDirectory)) {
injector.injectMembers(provider);
ProviderLoadResult loadResult = tryLoad(provider, provider.loadRequirement());
for (Class<?> providerClass : ExpansionProviderLoader.loadProvidersFromFolder(providersFolderDirectory)) {
final ExpansionProvider provider = (ExpansionProvider) injector.getInstance(providerClass);
final ProviderLoadResult loadResult = tryLoad(provider, provider.loadRequirement());
final ExpansionProvider loadedProvider = loadResult.provider();
if (loadedProvider != null) {
final Expansion loadedExpansion = loadedProvider.provideExpansion();
@@ -39,7 +39,7 @@ public interface PlaceholdersPlugin {
}
final FailedToLoadExpansion failedToLoad = loadResult.failed();
logError(Component.text("The expansion "
+ provider.getClass() +
+ providerClass +
" could not be loaded because the requirement " + failedToLoad.requirement() + " could not be resolved",
NamedTextColor.RED));
}
@@ -1,10 +1,10 @@
package io.github.miniplaceholders.common.command;
import net.kyori.adventure.audience.Audience;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
@FunctionalInterface
public interface AudienceConverter {
@Nullable Audience convert(@NotNull String string);
@Nullable Audience convert(@NonNull String string);
}
@@ -8,4 +8,6 @@ import org.jspecify.annotations.NullMarked;
@FunctionalInterface
public interface PermissionTester {
TriState permissionValue(Audience audience, String permission);
PermissionTester NO_OP = (audience, permission) -> TriState.NOT_SET;
}
@@ -21,7 +21,7 @@ import java.util.jar.JarInputStream;
@NullMarked
public final class ExpansionProviderLoader {
public static List<ExpansionProvider> loadProvidersFromFolder(final Path folferPath) throws Exception {
public static List<Class<?>> loadProvidersFromFolder(final Path folferPath) throws Exception {
if (Files.notExists(folferPath)) {
try {
Files.createDirectories(folferPath);
@@ -32,7 +32,7 @@ public final class ExpansionProviderLoader {
}
try (final DirectoryStream<Path> stream = Files.newDirectoryStream(folferPath,
filtered -> Files.isRegularFile(filtered) && filtered.toString().endsWith(".jar"))) {
final List<ExpansionProvider> providerList = new ArrayList<>();
final List<Class<?>> providerList = new ArrayList<>();
for (final Path possibleProviderPath : stream) {
loadPossibleProviderFromPath(possibleProviderPath, providerList);
}
@@ -42,7 +42,7 @@ public final class ExpansionProviderLoader {
private static void loadPossibleProviderFromPath(
final Path filePath,
final List<ExpansionProvider> providers
final List<Class<?>> providers
) throws Exception {
String mainClassName = null;
try (final JarInputStream jarStream = new JarInputStream(Files.newInputStream(filePath))) {
@@ -58,9 +58,7 @@ public final class ExpansionProviderLoader {
mainClassName = properties.getProperty("provider-class");
break;
} catch (IOException e) {
throw new IOException(
"Unable to read expansion_provider.properties from " + filePath + "file",
e);
throw new IOException("Unable to read expansion_provider.properties from " + filePath + "file", e);
}
}
}
@@ -74,13 +72,15 @@ public final class ExpansionProviderLoader {
private static void loadFoundProvider(
final String providerClass,
final List<ExpansionProvider> providers,
final List<Class<?>> providers,
final Path providerPath
) throws Exception {
//noinspection resource
final URLClassLoader classLoader = new URLClassLoader(new URL[] {
providerPath.toUri().toURL(),
}, ExpansionProviderLoader.class.getClassLoader());
final URLClassLoader classLoader = new URLClassLoader(
"MiniPlaceholders ClassLoader",
new URL[] { providerPath.toUri().toURL() },
ExpansionProviderLoader.class.getClassLoader()
);
Class<?> mainClass;
try {
mainClass = classLoader.loadClass(providerClass);
@@ -90,10 +90,6 @@ public final class ExpansionProviderLoader {
if (!ExpansionProvider.class.isAssignableFrom(mainClass) || mainClass.isInterface()) {
return;
}
try {
providers.add((ExpansionProvider) mainClass.getConstructors()[0].newInstance());
} catch (Exception e) {
throw new RuntimeException("Unable to create expansion provider from file " + providerPath, e);
}
providers.add(mainClass);
}
}
@@ -0,0 +1,12 @@
package io.github.miniplaceholders.common.metrics;
import io.github.miniplaceholders.api.MiniPlaceholders;
import java.util.concurrent.Callable;
public final class LoadedExpansionsMetric implements Callable<Integer> {
@Override
public Integer call() {
return MiniPlaceholders.expansionsAvailable().size();
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ plugins {
alias(libs.plugins.blossom)
}
version = "1.0.0"
version = "1.3.5"
dependencies {
compileOnly(projects.miniplaceholdersApi)
@@ -3,34 +3,44 @@ package io.miniplaceholders.provider.example;
import io.github.miniplaceholders.api.Expansion;
import io.github.miniplaceholders.api.provider.ExpansionProvider;
import io.github.miniplaceholders.api.provider.LoadRequirement;
import io.github.miniplaceholders.api.provider.PlatformData;
import io.github.miniplaceholders.api.types.Platform;
import io.github.miniplaceholders.provider.example.ExpansionConstants;
import net.kyori.adventure.text.minimessage.tag.Tag;
import team.unnamed.inject.Inject;
public final class ExampleProvider implements ExpansionProvider {
// For advanced usage only
@team.unnamed.inject.Inject
private io.github.miniplaceholders.api.provider.PlatformData platformData;
public record ExampleProvider(PlatformData platformData) implements ExpansionProvider {
@Inject
public ExampleProvider {}
@Override
public Expansion provideExpansion() {
@Override
public Expansion provideExpansion() {
return Expansion.builder("example")
.author("MiniPlaceholders Contributors")
.globalPlaceholder("test", (queue, context) ->
Tag.preProcessParsed("""
Platform Instance Class: %s
MiniPlaceholders Instance Class: %s
""".formatted(
platformData.serverInstance(),
platformData.complementInstance()
)))
.version(ExpansionConstants.VERSION)
.build();
}
return Expansion.builder("example")
.version("2.0.0")
.author("MiniPlaceholders Contributors")
.globalPlaceholder("test", (queue, context) ->
Tag.preProcessParsed("""
Platform Instance Class: %s
MiniPlaceholders Instance Class: %s
""".formatted(
platformData.serverInstance(),
platformData.complementInstance())))
.version(ExpansionConstants.VERSION)
.build();
}
@Override
public LoadRequirement loadRequirement() {
return LoadRequirement.allOf(LoadRequirement.allOf(LoadRequirement.platform(Platform.VELOCITY)));
}
@Override
public LoadRequirement loadRequirement() {
return LoadRequirement.anyOf(
LoadRequirement.platform(Platform.SPONGE),
LoadRequirement.allOf(
LoadRequirement.requiredComplement(
"MiniPlaceholders",
"miniplaceholders"
),
LoadRequirement.platform(Platform.PAPER)
),
LoadRequirement.requiredClass("io.github.miniplaceholders.common.command.node.PlayerCompleterNode")
);
}
}
+32 -2
View File
@@ -1,3 +1,7 @@
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import kotlin.io.path.deleteIfExists
plugins {
id("miniplaceholders.auto.module")
id("quiet-fabric-loom")
@@ -38,8 +42,6 @@ fun DependencyHandlerScope.includeDependency(dependency: Any) {
include(dependency)
}
tasks {
val projectVersion = project.version
val rootDir = project.rootDir
@@ -57,6 +59,34 @@ tasks {
shadowJar {
configurations = listOf(shade)
}
// I know it's exactly the same logic for all modules,
// but for some reason in this module it only works
// if it's declared in the same project configuration
// and not with a plugin like with all other projects...
// ¯\_(ツ)_/¯
runServer {
val exampleExpansionProviderProject = project(":miniplaceholders-example-expansion-provider")
val exampleExpansionJarTask = exampleExpansionProviderProject.tasks.named<Jar>("jar")
dependsOn(exampleExpansionJarTask)
doFirst {
val expansionsDirectory = projectDir.resolve("run/config/miniplaceholders/expansions").toPath()
if (Files.exists(expansionsDirectory)) {
Files.newDirectoryStream(expansionsDirectory).use {
it.forEach { file ->
file.deleteIfExists()
}
}
} else {
Files.createDirectories(expansionsDirectory)
}
val exampleExpansionFile = exampleExpansionJarTask.get().archiveFile.get().asFile.toPath()
Files.copy(
exampleExpansionFile,
expansionsDirectory.resolve(exampleExpansionFile.fileName),
StandardCopyOption.REPLACE_EXISTING
)
}
}
}
java {
+1 -1
View File
@@ -1,5 +1,5 @@
group = io.github.miniplaceholders
version = 3.1.0-SNAPSHOT
version = 3.1.1-SNAPSHOT
description = MiniMessage Component-based Placeholders API
org.gradle.jvmargs=-Xmx2G
+11 -4
View File
@@ -6,7 +6,7 @@ velocity = "3.4.0-SNAPSHOT"
paper = "1.21.8-R0.1-SNAPSHOT"
minecraft = "1.21.8"
runtask = "3.0.0"
runtask = "3.0.1"
blossom = "2.1.0"
shadow = "9.2.2"
jmh = "0.7.3"
@@ -16,10 +16,11 @@ adventure = "4.24.0"
adventureModded = "6.6.0"
kotlin = "2.2.20"
fabric-api = "0.133.14+1.21.9"
fabric-loader = "0.17.2"
fabric-api = "0.134.0+1.21.8"
fabric-loader = "0.17.3"
desertwell = "2.0.4"
bstats = "3.1.0"
[libraries]
@@ -38,8 +39,9 @@ adventure-serializer-legacy = { group = "net.kyori", name = "adventure-text-seri
adventure-serializer-plain = { group = "net.kyori", name = "adventure-text-serializer-plain", version.ref = "adventure" }
plugin-shadow = { module = "com.gradleup.shadow:shadow-gradle-plugin", version.ref = "shadow" }
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
plugin-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
plugin-runtask = { module = "xyz.jpenilla.run-velocity:xyz.jpenilla.run-velocity.gradle.plugin", version.ref = "runtask" }
desertwell = { group = "net.william278", name = "DesertWell", version.ref = "desertwell" }
@@ -49,6 +51,11 @@ jspecify = "org.jspecify:jspecify:1.0.0"
unnamedinject = "team.unnamed:inject:2.0.1"
brigadier = "com.mojang:brigadier:1.0.500"
bstats-core = { group = "org.bstats", name = "bstats-base", version.ref = "bstats" }
bstats-velocity = { group = "org.bstats", name = "bstats-velocity", version.ref = "bstats" }
bstats-sponge = { group = "org.bstats", name = "bstats-sponge", version.ref = "bstats" }
bstats-bukkit = { group = "org.bstats", name = "bstats-bukkit", version.ref = "bstats" }
[plugins]
runpaper = { id = "xyz.jpenilla.run-paper", version.ref = "runtask" }
+4 -1
View File
@@ -1,6 +1,7 @@
plugins {
id("miniplaceholders.auto.module")
id("miniplaceholders.shadow")
id("miniplaceholders.runtask")
alias(libs.plugins.runpaper)
}
@@ -9,15 +10,17 @@ dependencies {
implementation(projects.miniplaceholdersCommon)
implementation(projects.miniplaceholdersApi)
implementation(projects.miniplaceholdersConnect)
implementation(libs.bstats.bukkit)
}
tasks {
runServer {
jvmArgs("-Dcom.mojang.eula.agree=true")
minecraftVersion(libs.versions.minecraft.get())
}
val projectVersion = project.version
processResources {
//val version = project.version
filesMatching("paper-plugin.yml") {
expand("version" to projectVersion)
}
@@ -11,16 +11,17 @@ import net.kyori.adventure.util.TriState;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@SuppressWarnings({"unused", "UnstableApiUsage"})
@NullMarked
public final class PaperBootstrap implements PluginBootstrap {
@Override
public void bootstrap(@NotNull BootstrapContext bootstrapContext) {
public void bootstrap(final BootstrapContext bootstrapContext) {
InternalPlatform.platform(InternalPlatform.PAPER);
final LiteralCommandNode<CommandSourceStack> command = BrigadierCommandProvider.provideCommand(
"miniplaceholders",
@@ -1,9 +1,13 @@
package io.github.miniplaceholders.paper;
import io.github.miniplaceholders.common.PlaceholdersPlugin;
import io.github.miniplaceholders.common.metrics.LoadedExpansionsMetric;
import io.github.miniplaceholders.paper.listener.ServerFinishedLoadListener;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SingleLineChart;
import org.bukkit.plugin.java.JavaPlugin;
import static net.kyori.adventure.text.Component.text;
@@ -15,11 +19,9 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin
final ComponentLogger componentLogger = getComponentLogger();
componentLogger.info(text("Starting MiniPlaceholders Paper", NamedTextColor.GREEN));
try {
this.loadProvidedExpansions(getDataPath().resolve("expansions"));
} catch (Throwable e) {
componentLogger.error("Unable to load expansion providers", e);
}
new ServerFinishedLoadListener(this).register();
final Metrics metrics = new Metrics(this, 27515);
metrics.addCustomChart(new SingleLineChart("loaded_expansions", new LoadedExpansionsMetric()));
}
@Override
@@ -0,0 +1,32 @@
package io.github.miniplaceholders.paper.listener;
import io.github.miniplaceholders.paper.PaperPlugin;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.plugin.EventExecutor;
import org.jspecify.annotations.NonNull;
public record ServerFinishedLoadListener(PaperPlugin plugin) implements Listener, EventExecutor {
public void register() {
plugin.getServer()
.getPluginManager()
.registerEvent(ServerLoadEvent.class, this, EventPriority.HIGH, this, plugin);
}
@Override
public void execute(final @NonNull Listener listener, final @NonNull Event event) {
final ServerLoadEvent loadEvent = (ServerLoadEvent) event;
if (loadEvent.getType() != ServerLoadEvent.LoadType.STARTUP) {
return;
}
try {
plugin.loadProvidedExpansions(plugin.getDataPath().resolve("expansions"));
} catch (Throwable e) {
plugin.getComponentLogger().error("Unable to load expansion providers", e);
}
}
}
+30
View File
@@ -1,5 +1,8 @@
import org.spongepowered.gradle.plugin.config.PluginLoaders
import org.spongepowered.plugin.metadata.model.PluginDependency
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import kotlin.io.path.deleteIfExists
plugins {
id("miniplaceholders.auto.module")
@@ -13,6 +16,7 @@ dependencies {
implementation(projects.miniplaceholdersConnect)
compileOnly(libs.jspecify)
implementation(libs.bstats.sponge)
}
sponge {
@@ -41,3 +45,29 @@ sponge {
}
}
}
tasks {
runServer {
val exampleExpansionProviderProject = project(":miniplaceholders-example-expansion-provider")
val exampleExpansionJarTask = exampleExpansionProviderProject.tasks.named<Jar>("jar")
dependsOn(exampleExpansionJarTask)
doFirst {
val expansionsDirectory = projectDir.resolve("run/config/miniplaceholders/expansions").toPath()
if (Files.exists(expansionsDirectory)) {
Files.newDirectoryStream(expansionsDirectory).use {
it.forEach { file ->
file.deleteIfExists()
}
}
} else {
Files.createDirectories(expansionsDirectory)
}
val exampleExpansionFile = exampleExpansionJarTask.get().archiveFile.get().asFile.toPath()
Files.copy(
exampleExpansionFile,
expansionsDirectory.resolve(exampleExpansionFile.fileName),
StandardCopyOption.REPLACE_EXISTING
)
}
}
}
@@ -2,16 +2,20 @@ package io.github.miniplaceholders.sponge;
import com.google.inject.Inject;
import io.github.miniplaceholders.common.PlaceholdersPlugin;
import io.github.miniplaceholders.common.metrics.LoadedExpansionsMetric;
import io.github.miniplaceholders.connect.InternalPlatform;
import io.github.miniplaceholders.sponge.command.SpongeCommand;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.apache.logging.log4j.Logger;
import org.bstats.charts.SingleLineChart;
import org.bstats.sponge.Metrics;
import org.spongepowered.api.Server;
import org.spongepowered.api.command.Command;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.lifecycle.RegisterCommandEvent;
import org.spongepowered.api.event.lifecycle.StartedEngineEvent;
import org.spongepowered.api.event.lifecycle.StartingEngineEvent;
import org.spongepowered.plugin.PluginContainer;
import org.spongepowered.plugin.builtin.jvm.Plugin;
@@ -28,8 +32,11 @@ public class SpongePlugin implements PlaceholdersPlugin {
private Path configDir;
@Inject
private PluginContainer pluginContainer;
@Inject
private Metrics.Factory factory;
private Server server;
private Metrics metrics;
@Listener
public void onServerStart(final StartingEngineEvent<Server> event) {
@@ -37,11 +44,20 @@ public class SpongePlugin implements PlaceholdersPlugin {
InternalPlatform.platform(InternalPlatform.SPONGE);
logger.info("Starting MiniPlaceholders Sponge");
this.metrics = factory.make(27517);
}
@Listener
public void onLateServerStart(final StartedEngineEvent<Server> event) {
try {
this.loadProvidedExpansions(configDir.resolve("expansions"));
} catch (Throwable e) {
logger.error("Unable to load expansion providers", e);
}
// bstats sponge weird initialization workaround
this.metrics.startup(null);
this.metrics.addCustomChart(new SingleLineChart("expansions_loaded", new LoadedExpansionsMetric()));
}
@Listener
@@ -3,7 +3,6 @@ package io.github.miniplaceholders.sponge.command;
import io.github.miniplaceholders.common.command.*;
import io.github.miniplaceholders.common.command.node.*;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.util.TriState;
import org.jspecify.annotations.NullMarked;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.*;
@@ -22,7 +21,7 @@ import java.util.stream.Collectors;
public final class SpongeCommand {
public static Command.Parameterized provideCommand() {
final AudienceExtractor<CommandCause> audienceExtractor = CommandCause::audience;
final PermissionTester permissionTester = (audience, permission) -> TriState.NOT_SET; // Not really used here
final PermissionTester permissionTester = PermissionTester.NO_OP; // Not really used here
final PlayersNameProvider playerSuggestions = () -> Sponge.server().onlinePlayers()
.stream()
.map(ServerPlayer::user)
+3
View File
@@ -1,6 +1,7 @@
plugins {
id("miniplaceholders.shadow")
id("miniplaceholders.auto.module")
id("miniplaceholders.runtask")
alias(libs.plugins.runvelocity)
}
@@ -10,6 +11,8 @@ dependencies {
implementation(projects.miniplaceholdersCommon)
implementation(projects.miniplaceholdersApi)
implementation(projects.miniplaceholdersConnect)
implementation(libs.bstats.velocity)
}
tasks {
@@ -15,10 +15,13 @@ import com.velocitypowered.api.proxy.ProxyServer;
import io.github.miniplaceholders.common.PlaceholdersPlugin;
import io.github.miniplaceholders.common.PluginConstants;
import io.github.miniplaceholders.common.command.brigadier.BrigadierCommandProvider;
import io.github.miniplaceholders.common.metrics.LoadedExpansionsMetric;
import io.github.miniplaceholders.connect.InternalPlatform;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import org.bstats.charts.SingleLineChart;
import org.bstats.velocity.Metrics;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -41,6 +44,8 @@ public final class VelocityPlugin implements PlaceholdersPlugin {
private CommandManager commandManager;
@Inject
private ComponentLogger componentLogger;
@Inject
private Metrics.Factory metricsFactory;
@Subscribe(priority = 999)
public void onEarlyProxyInitialize(final ProxyInitializeEvent event) {
@@ -48,6 +53,9 @@ public final class VelocityPlugin implements PlaceholdersPlugin {
componentLogger.info(Component.text("Starting MiniPlaceholders Velocity", NamedTextColor.GREEN));
this.registerPlatformCommand();
final Metrics metrics = metricsFactory.make(this, 27516);
metrics.addCustomChart(new SingleLineChart("expansions_count", new LoadedExpansionsMetric()));
}
@Subscribe(priority = -404)
@@ -63,7 +71,7 @@ public final class VelocityPlugin implements PlaceholdersPlugin {
public void registerPlatformCommand() {
final LiteralCommandNode<CommandSource> node = BrigadierCommandProvider.provideCommand(
"vminiplaceholders",
() -> proxyServer.getAllPlayers()
() -> this.proxyServer.getAllPlayers()
.stream()
.map(Player::getUsername)
.collect(Collectors.toCollection(ArrayList::new)),
@@ -73,10 +81,10 @@ public final class VelocityPlugin implements PlaceholdersPlugin {
.toAdventureTriState()
);
final BrigadierCommand command = new BrigadierCommand(node);
final CommandMeta meta = commandManager.metaBuilder(command)
final CommandMeta meta = this.commandManager.metaBuilder(command)
.plugin(this)
.build();
commandManager.register(meta, command);
this.commandManager.register(meta, command);
}
@Override