Compare commits

...
31 Commits
Author SHA1 Message Date
Adrian3d04 17a2ff73b2 feat: Initial extension support 2022-08-18 15:32:06 +00:00
Adrian3d04 e8635bc6c8 test: Remove unnecesary public modifier 2022-08-18 02:17:22 +00:00
Adrian3d04 a1e95295cc feat: Added java 9 Modules Support 2022-08-18 02:16:50 +00:00
4drian3d dac6354071 release: Version 1.2.0 2022-07-29 11:37:18 -05:00
4drian3d 01bb19213c misc: Use DecimalFormat instead of NumberFormat
misc: Updated some dependencies
2022-07-28 18:28:45 +00:00
Adrian 6ff764bf4c pr: Merge pull request #5 from Sliman4/make-gradlew-executable 2022-07-28 12:36:56 -05:00
Adrian 4a509e63a2 Merge branch 'main' into make-gradlew-executable 2022-07-28 12:35:15 -05:00
Adrian f9d3f01a34 pr: Merge pull request #4 from Sliman4/multiversion-with-reflection
(paper) Support more Minecraft versions
2022-07-28 12:34:40 -05:00
sliman4 e5cf5001eb Make gradlew executable 2022-07-28 20:19:34 +03:00
sliman4 a762a68901 Remove unused import 2022-07-28 19:54:55 +03:00
sliman4 20b7d92710 Use MinecraftServer.getServer() instead of reflection 2022-07-28 19:46:25 +03:00
sliman4 d0edacfafd Replace NMS tps placeholder with Paper's getTPS() 2022-07-28 19:37:33 +03:00
sliman4 43c034fc0b Support 1.18-1.19.1 using reflection 2022-07-28 19:30:49 +03:00
4drian3d 2337525e25 build: Update Adventure to 4.11.0 2022-06-18 17:32:18 +00:00
4drian3d 0bb6f6264a perf: Ignore resolvers if empty
api: Implement Resolvers utility class
2022-06-18 17:26:35 +00:00
4drian3d 24a7591a0f fix: connect module inclusion 2022-04-19 18:00:42 +00:00
4drian3d 6a73aa3f46 1.1.0 Release 2022-04-19 17:42:50 +00:00
4drian3d 7832d96d50 docs: Improved annotations, added Contract annotation 2022-04-19 17:39:05 +00:00
4drian3d 900214dfad test: added Expansion equality test 2022-04-14 17:36:32 +00:00
4drian3d 9de6aceac3 perf: improved performance of some methods of MiniPlaceholders
- Improved getAudienceGlobalPlaceholders and getRelationalGlobalPlaceholders performance by not creations multiple TagResolver.Builder instances
2022-04-14 17:34:44 +00:00
4drian3d 4e2599abd3 fix!: deprecated exposed platform setter
- Added connect module to control the internal platform
2022-04-14 16:17:06 +00:00
4drian3d dc5d4c5cc9 docs: change NotNull to Nullable annotation in Expansion.Builder#filter(Predicate) 2022-04-13 20:13:25 +00:00
4drian3d 782bd02a33 feat(api): added some util methods to MiniPlaceholders
- Added #getAudienceGlobalPlaceholders and #getRelationalGlobalPlaceholders
- Removed Collection#isEmpty call from MiniPlaceholders methods, the expansion collection cannot be empty
- Set as final the TagResolver.Builder of the MiniPlaceholders methods
2022-04-13 20:05:06 +00:00
4drian3d 25a3ce024d Added missing nullability annotations 2022-04-12 18:01:40 +00:00
4drian3d ece1252a6e Added more Tag Utilities 2022-04-12 17:28:13 +00:00
4drian3d 4df9c296c9 Implement Expansion#globalPlaceholder(String, Tag) 2022-04-12 17:22:20 +00:00
4drian3d 68e2034dd3 Added static utils components
- Improved documentation
2022-04-11 18:05:07 +00:00
4drian3d 9a7f204308 1.0.1 Release 2022-04-11 17:17:14 +00:00
4drian3d 8ec1f13661 Performance Improvements
- Use Arrays instead of Set in Tags collections
- Improved Tags creation and method performance
2022-04-11 17:14:39 +00:00
4drian3d 2c96be8796 Fix MiniPlaceholders name in Paper 2022-04-11 16:08:58 +00:00
4drian3d 20a8c111f5 Some improvements to build script 2022-03-18 11:42:03 +00:00
34 changed files with 744 additions and 176 deletions

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: https://paypal.me/4drian3d # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
+33 -13
View File
@@ -3,15 +3,21 @@ plugins {
`maven-publish`
}
repositories {
mavenCentral()
}
dependencies {
compileOnly("net.kyori:adventure-api:4.10.1")
compileOnly("net.kyori:adventure-text-minimessage:4.10.1")
compileOnly("net.kyori:adventure-text-serializer-legacy:4.10.1")
compileOnly("net.kyori:adventure-api:4.11.0")
compileOnly("net.kyori:adventure-text-minimessage:4.11.0")
compileOnly("net.kyori:adventure-text-serializer-legacy:4.11.0")
compileOnly(project(":miniplaceholders-connect"))
implementation("com.google.code.gson:gson:2.9.1")
testImplementation(platform("org.junit:junit-bom:5.8.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("net.kyori:adventure-api:4.10.1")
testImplementation("net.kyori:adventure-text-minimessage:4.10.1")
testImplementation("net.kyori:adventure-text-serializer-plain:4.10.1")
testImplementation("net.kyori:adventure-api:4.11.0")
testImplementation("net.kyori:adventure-text-minimessage:4.11.0")
testImplementation("net.kyori:adventure-text-serializer-plain:4.11.0")
}
tasks {
@@ -28,15 +34,15 @@ jmh {
iterations.set(2)
fork.set(2)
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withSourcesJar()
withJavadocJar()
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
val projectGroup = project.group as String
val projectVersion = project.version as String
val projectGroup: String = project.group as String
val projectVersion: String = project.version as String
publishing {
publications {
@@ -51,7 +57,21 @@ publishing {
tasks.withType<Javadoc> {
(options as StandardJavadocDocletOptions).links(
"https://jd.adventure.kyori.net/api/4.10.1/",
"https://jd.adventure.kyori.net/text-minimessage/4.10.1/"
"https://jd.adventure.kyori.net/api/4.10.0/",
"https://jd.adventure.kyori.net/text-minimessage/4.11.0/"
)
}
}
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(11)
}
javadoc {
options.encoding = Charsets.UTF_8.name()
}
processResources {
filteringCharset = Charsets.UTF_8.name()
}
}
@@ -1,5 +1,6 @@
package me.dreamerzero.miniplaceholders.api;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -9,6 +10,7 @@ import java.util.function.Predicate;
import me.dreamerzero.miniplaceholders.api.placeholder.AudiencePlaceholder;
import me.dreamerzero.miniplaceholders.api.placeholder.RelationalPlaceholder;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.builder.AbstractBuilder;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
@@ -47,7 +49,8 @@ public interface Expansion {
* @return A TagResolver with variable placeholders of an Audience
* @since 1.0.0
*/
@NotNull TagResolver audiencePlaceholders(@NotNull Audience audience);
@Contract("null -> fail; !null -> !null")
@NotNull TagResolver audiencePlaceholders(final @NotNull Audience audience);
/**
* Get the relational placeholders based on two audiences
@@ -60,7 +63,8 @@ public interface Expansion {
* @return A TagResolver with variable placeholders between 2 {@link Audience}s
* @since 1.0.0
*/
@NotNull TagResolver relationalPlaceholders(@NotNull Audience audience, @NotNull Audience otherAudience);
@Contract("_, null -> fail, null, _ -> fail; !null, !null -> !null")
@NotNull TagResolver relationalPlaceholders(final @NotNull Audience audience, final @NotNull Audience otherAudience);
/**
* Get global placeholders
@@ -81,7 +85,7 @@ public interface Expansion {
* @return a new expansion builder
* @since 1.0.0
*/
public static @NotNull Expansion.Builder builder(@NotNull String name){
public static @NotNull Expansion.Builder builder(final @NotNull String name){
return new ExpansionImpl.Builder(name);
}
@@ -107,7 +111,7 @@ public interface Expansion {
*
* @since 1.0.0
*/
public static interface Builder {
public static interface Builder extends AbstractBuilder<Expansion> {
/**
* Adds an audience placeholder
*
@@ -120,7 +124,8 @@ public interface Expansion {
* @return the {@link Builder} itself
* @since 1.0.0
*/
Builder audiencePlaceholder(@NotNull String key, @NotNull AudiencePlaceholder audiencePlaceholder);
@Contract("null, _ -> fail; _, null -> fail; !null, !null -> this")
@NotNull Builder audiencePlaceholder(final @NotNull String key, final @NotNull AudiencePlaceholder audiencePlaceholder);
/**
* Adds an Relational Placeholder based on two audiences
@@ -138,7 +143,8 @@ public interface Expansion {
* @return the {@link Builder} itself
* @since 1.0.0
*/
Builder relationalPlaceholder(@NotNull String key, @NotNull RelationalPlaceholder relationalPlaceholder);
@Contract("null, _ -> fail; _, null -> fail; !null, !null -> this")
@NotNull Builder relationalPlaceholder(final @NotNull String key, final @NotNull RelationalPlaceholder relationalPlaceholder);
/**
* Adds a global placeholder
@@ -150,7 +156,20 @@ public interface Expansion {
* @return the {@link Builder} itself
* @since 1.0.0
*/
Builder globalPlaceholder(@NotNull String key, BiFunction<ArgumentQueue, Context, Tag> function);
@Contract("null, _ -> fail; _, null -> fail; !null, !null -> this")
@NotNull Builder globalPlaceholder(final @NotNull String key, final @NotNull BiFunction<@NotNull ArgumentQueue, @NotNull Context, @Nullable Tag> function);
/**
* Adds a global placeholder
*
* <p>This placeholder is not cached and is inmutable</p>
* @param key the placeholder key, cannot be an empty or black string
* @param tag the tag of this placeholder
* @return the {@link Builder} itself
* @since 1.1.0
*/
@Contract("null, _ -> fail; _, null -> fail; !null, !null -> this")
@NotNull Builder globalPlaceholder(final @NotNull String key, final @NotNull Tag tag);
/**
* Filter the type of Audiences that this expansion can receive
@@ -165,7 +184,8 @@ public interface Expansion {
* @return the {@link Builder} itself
* @since 1.0.0
*/
Builder filter(@Nullable Class<? extends Audience> clazz);
@Contract("_ -> this")
@NotNull Builder filter(final @Nullable Class<? extends Audience> clazz);
/**
* Filters the audiences that this expansion can receive through a Predicate
@@ -179,13 +199,7 @@ public interface Expansion {
* @return the {@link Builder} itself
* @since 1.0.0
*/
Builder filter(@NotNull Predicate<Audience> predicate);
/**
* Build the Expansion
* @return a new {@link Expansion}
* @since 1.0.0
*/
@NotNull Expansion build();
@Contract("_ -> this")
@NotNull Builder filter(final @Nullable Predicate<Audience> predicate);
}
}
@@ -1,5 +1,6 @@
package me.dreamerzero.miniplaceholders.api;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
import java.util.Objects;
@@ -22,23 +23,29 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
final class ExpansionImpl implements Expansion {
private final String name;
private final Set<Tags.Single> audiencePlaceholders;
private final Set<Tags.Relational> relationalPlaceholders;
private final Tags.Single[] audiencePlaceholders;
private final Tags.Relational[] relationalPlaceholders;
private final TagResolver globalPlaceholders;
private final Class<? extends Audience> filterClass;
private final Predicate<Audience> predicateFilter;
ExpansionImpl(
@NotNull String expansionName,
@Nullable Set<Tags.Single> audiencePlaceholders,
@Nullable Set<Tags.Relational> relationalPlaceholders,
@Nullable TagResolver globalPlaceholders,
@Nullable Class<? extends Audience> filterClass,
@Nullable Predicate<Audience> predicateFilter){
@NotNull final String expansionName,
@Nullable final Collection<Tags.Single> audiencePlaceholders,
@Nullable final Collection<Tags.Relational> relationalPlaceholders,
@Nullable final TagResolver globalPlaceholders,
@Nullable final Class<? extends Audience> filterClass,
@Nullable final Predicate<Audience> predicateFilter){
this.name = expansionName+"-";
this.audiencePlaceholders = audiencePlaceholders;
this.relationalPlaceholders = relationalPlaceholders;
this.globalPlaceholders = globalPlaceholders;
this.audiencePlaceholders = audiencePlaceholders != null
? audiencePlaceholders.toArray(Tags.Single[]::new)
: new Tags.Single[0];
this.relationalPlaceholders = relationalPlaceholders != null
? relationalPlaceholders.toArray(Tags.Relational[]::new)
: new Tags.Relational[0];
this.globalPlaceholders = globalPlaceholders == null
? TagResolver.empty()
: globalPlaceholders;
this.filterClass = filterClass;
this.predicateFilter = predicateFilter;
}
@@ -49,49 +56,49 @@ final class ExpansionImpl implements Expansion {
}
@Override
public @NotNull TagResolver audiencePlaceholders(@NotNull Audience audience){
if(audiencePlaceholders == null) return TagResolver.empty();
public @NotNull TagResolver audiencePlaceholders(@NotNull final Audience audience){
if(audiencePlaceholders.length == 0) return TagResolver.empty();
Objects.requireNonNull(audience, () -> "the audience cannot be null");
if(this.singleFilter(audience)) return TagResolver.empty();
TagResolver.Builder placeholders = TagResolver.builder();
for(Tags.Single pl : this.audiencePlaceholders){
final TagResolver.Builder placeholders = TagResolver.builder();
for(final Tags.Single pl : this.audiencePlaceholders){
placeholders.resolver(pl.of(audience));
}
return placeholders.build();
}
private boolean singleFilter(Audience audience){
private boolean singleFilter(final Audience audience){
return filterClass != null && !filterClass.isInstance(audience)
|| predicateFilter != null && predicateFilter.test(audience);
}
@Override
public @NotNull TagResolver relationalPlaceholders(@NotNull Audience audience, @NotNull Audience otherAudience){
if(relationalPlaceholders == null) return TagResolver.empty();
public @NotNull TagResolver relationalPlaceholders(@NotNull final Audience audience, @NotNull final Audience otherAudience){
if(relationalPlaceholders.length == 0) return TagResolver.empty();
Objects.requireNonNull(audience, () -> "the audience cannot be null");
Objects.requireNonNull(otherAudience, () -> "the other audience cannot be null");
if(this.relationalFilter(audience, otherAudience)) return TagResolver.empty();
TagResolver.Builder placeholders = TagResolver.builder();
for(Tags.Relational pl : this.relationalPlaceholders){
final TagResolver.Builder placeholders = TagResolver.builder();
for(final Tags.Relational pl : this.relationalPlaceholders){
placeholders.resolver(pl.of(audience, otherAudience));
}
return placeholders.build();
}
private boolean relationalFilter(Audience audience, Audience otherAudience){
private boolean relationalFilter(final Audience audience, final Audience otherAudience){
return filterClass != null && (!filterClass.isInstance(audience) || !filterClass.isInstance(otherAudience))
|| predicateFilter != null && (!predicateFilter.test(audience) || !predicateFilter.test(otherAudience));
}
@Override
public @NotNull TagResolver globalPlaceholders(){
return this.globalPlaceholders != null ? this.globalPlaceholders : TagResolver.empty();
return this.globalPlaceholders;
}
@Override
@@ -99,7 +106,7 @@ final class ExpansionImpl implements Expansion {
MiniPlaceholders.expansions.add(this);
}
static class Builder implements Expansion.Builder {
static final class Builder implements Expansion.Builder {
private final String expansionName;
private Set<Tags.Single> audiencePlaceholders;
private Set<Tags.Relational> relationalPlaceholders;
@@ -107,13 +114,13 @@ final class ExpansionImpl implements Expansion {
private Class<? extends Audience> filterClass;
private Predicate<Audience> predicateFilter;
Builder(@NotNull String name){
Builder(@NotNull final String name){
this.expansionName = Conditions.nonNullOrEmptyString(name, () -> "expansion name")
.toLowerCase(Locale.ROOT).concat("_");
}
@Override
public Builder audiencePlaceholder(@NotNull String key, @NotNull AudiencePlaceholder audiencePlaceholder){
public Builder audiencePlaceholder(@NotNull final String key, @NotNull final AudiencePlaceholder audiencePlaceholder){
Conditions.nonNullOrEmptyString(key, () -> "placeholder key");
Objects.requireNonNull(audiencePlaceholder, () -> "the audience placeholder cannot be null");
@@ -124,7 +131,7 @@ final class ExpansionImpl implements Expansion {
}
@Override
public Builder relationalPlaceholder(@NotNull String key, @NotNull RelationalPlaceholder relationalPlaceholder){
public Builder relationalPlaceholder(@NotNull final String key, @NotNull final RelationalPlaceholder relationalPlaceholder){
Conditions.nonNullOrEmptyString(key, () -> "placeholder key");
Objects.requireNonNull(relationalPlaceholder, () -> "the relational placeholder cannot be null");
@@ -135,8 +142,7 @@ final class ExpansionImpl implements Expansion {
}
@Override
public Builder globalPlaceholder(@NotNull String key,
BiFunction<ArgumentQueue, Context, Tag> function){
public Builder globalPlaceholder(@NotNull final String key, @NotNull final BiFunction<ArgumentQueue, Context, Tag> function){
Conditions.nonNullOrEmptyString(key, () -> "placeholder key");
Objects.requireNonNull(function, () -> "the global placeholder cannot be null");
@@ -147,13 +153,24 @@ final class ExpansionImpl implements Expansion {
}
@Override
public Builder filter(Class<? extends Audience> clazz) {
public Builder globalPlaceholder(@NotNull final String key, @NotNull final Tag tag){
Conditions.nonNullOrEmptyString(key, () -> "placeholder key");
Objects.requireNonNull(tag, () -> "the tag cannot be null");
if(this.globalPlaceholders == null) this.globalPlaceholders = TagResolver.builder();
this.globalPlaceholders.tag(expansionName+key, tag);
return this;
}
@Override
public Builder filter(@Nullable final Class<? extends Audience> clazz) {
this.filterClass = clazz;
return this;
}
@Override
public Builder filter(Predicate<Audience> predicate){
public Builder filter(@Nullable final Predicate<Audience> predicate){
this.predicateFilter = predicate;
return this;
}
@@ -5,9 +5,12 @@ import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import me.dreamerzero.miniplaceholders.api.enums.Platform;
import me.dreamerzero.miniplaceholders.api.utils.Resolvers;
import me.dreamerzero.miniplaceholders.connect.InternalPlatform;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
@@ -26,15 +29,16 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
public final class MiniPlaceholders {
private MiniPlaceholders(){}
static final Set<Expansion> expansions = Collections.synchronizedSet(new HashSet<>());
private static Platform placeholdersPlatform;
/**
* Get the platform
* @return the platform
* @since 1.0.0
*/
public static Platform getPlatform(){
return placeholdersPlatform;
public static @NotNull Platform getPlatform() {
return InternalPlatform.platform() == InternalPlatform.PAPER
? Platform.PAPER
: Platform.VELOCITY;
}
/**
@@ -48,12 +52,13 @@ public final class MiniPlaceholders {
* @since 1.0.0
*/
public static @NotNull TagResolver getGlobalPlaceholders() {
if(expansions.isEmpty()) return TagResolver.empty();
TagResolver.Builder resolvers = TagResolver.builder();
expansions.forEach(exp -> resolvers.resolver(exp.globalPlaceholders()));
return resolvers.build();
final TagResolver.Builder builder = TagResolver.builder();
for (final Expansion expansion : expansions) {
final TagResolver resolver = expansion.globalPlaceholders();
if (resolver != TagResolver.empty())
builder.resolver(resolver);
}
return builder.build();
}
/**
@@ -66,14 +71,16 @@ public final class MiniPlaceholders {
* @return {@link TagResolver} with placeholders based on an audience
* @since 1.0.0
*/
public static @NotNull TagResolver getAudiencePlaceholders(@NotNull Audience audience) {
if(expansions.isEmpty()) return TagResolver.empty();
@Contract("null -> fail, !null -> !null")
public static @NotNull TagResolver getAudiencePlaceholders(final @NotNull Audience audience) {
Objects.requireNonNull(audience, () -> "audience cannot be null");
TagResolver.Builder resolvers = TagResolver.builder();
expansions.forEach(exp -> resolvers.resolver(exp.audiencePlaceholders(audience)));
final TagResolver.Builder resolvers = TagResolver.builder();
for (Expansion expansion : expansions) {
final TagResolver resolver = expansion.audiencePlaceholders(audience);
if (resolver != TagResolver.empty())
resolvers.resolver(resolver);
}
return resolvers.build();
}
@@ -88,16 +95,87 @@ public final class MiniPlaceholders {
* @return placeholders based on two audiences
* @since 1.0.0
*/
public static @NotNull TagResolver getRelationalPlaceholders(@NotNull Audience audience, @NotNull Audience otherAudience) {
if(expansions.isEmpty()) return TagResolver.empty();
@Contract("_, null -> fail; null, _ -> fail; !null, !null -> !null")
public static @NotNull TagResolver getRelationalPlaceholders(final @NotNull Audience audience, final @NotNull Audience otherAudience) {
Objects.requireNonNull(audience, () -> "audience cannot be null");
Objects.requireNonNull(otherAudience, () -> "otherAudience cannot be null");
TagResolver.Builder resolvers = TagResolver.builder();
expansions.forEach(exp -> resolvers.resolver(exp.relationalPlaceholders(audience, otherAudience)));
final TagResolver.Builder builder = TagResolver.builder();
for (final Expansion expansion : expansions) {
Resolvers.applyIfNotEmpty(
expansion.relationalPlaceholders(audience, otherAudience),
builder
);
}
return resolvers.build();
return builder.build();
}
/**
* Get the TagResolver based on an Audience and the global placeholders
*
* <pre>
* TagResolver resolver = MiniPlaceholders.getAudienceGlobalPlaceholders({@link Audience});
* TagResolver resolver2 = TagResolver.resolver(
* MiniPlaceholders.getAudienceGlobalPlaceholders({@link Audience}),
* MiniPlaceholders.getGlobalPlaceholders()
* );
* // This two resolvers returns the same TagResolver
* assertEquals(resolver, resolver2);
* Component messageParsed = MiniMessage.miniMessage().deserialize({@link String}, resolver);
* </pre>
*
* @param audience the audience
* @return {@link TagResolver} with placeholders based on an audience and the global placeholders
* @since 1.1.0
*/
@Contract("_, null -> fail; null, _ -> fail; !null, !null -> !null")
public static @NotNull TagResolver getAudienceGlobalPlaceholders(final @NotNull Audience audience) {
Objects.requireNonNull(audience, () -> "audience cannot be null");
final TagResolver.Builder builder = TagResolver.builder();
for (final Expansion expansion : expansions) {
Resolvers.applyIfNotEmpty(expansion.audiencePlaceholders(audience), builder);
Resolvers.applyIfNotEmpty(expansion.globalPlaceholders(), builder);
}
return builder.build();
}
/**
* Get the relationals placeholders based on two audiences, based on the first audience,
* and the global placeholders
*
* <pre>
* TagResolver resolver = MiniPlaceholders.getRelationalGlobalPlaceholders({@link Audience}, {@link Audience});
* TagResolver resolver2 = TagResolver.resolver(
* MiniPlaceholders.getRelationalPlaceholders(audience1, audience2),
* MiniPlaceholders.getAudiencePlaceholders(audience1),
* MiniPlaceholders.getGlobalPlaceholders()
* );
* // This methods should return the same TagResolver
* assertEquals(resolver, resolver2);
* Component messageParsed = MiniMessage.miniMessage().deserialize({@link String}, resolver);
* </pre>
*
* @param audience an audience
* @param otherAudience another audience
* @return the placeholders based on two audiences, placeholders based on the first audience and the global placeholders
* @since 1.1.0
*/
@Contract("_, null -> fail; null, _ -> fail; !null, !null -> !null")
public static @NotNull TagResolver getRelationalGlobalPlaceholders(final @NotNull Audience audience, final @NotNull Audience otherAudience) {
Objects.requireNonNull(audience, () -> "audience cannot be null");
Objects.requireNonNull(otherAudience, () -> "otherAudience cannot be null");
final TagResolver.Builder builder = TagResolver.builder();
for (final Expansion expansion : expansions) {
Resolvers.applyIfNotEmpty(expansion.audiencePlaceholders(audience), builder);
Resolvers.applyIfNotEmpty(expansion.relationalPlaceholders(audience, otherAudience), builder);
Resolvers.applyIfNotEmpty(expansion.globalPlaceholders(), builder);
}
return builder.build();
}
/**
@@ -115,10 +193,9 @@ public final class MiniPlaceholders {
* @deprecated dont use this, INTERNAL
* @since 1.0.0
*/
@Deprecated(forRemoval = false)
@Deprecated(forRemoval = true, since = "1.1.0")
@org.jetbrains.annotations.ApiStatus.Internal
public static void setPlatform(Platform platform){
if(placeholdersPlatform != null) throw new RuntimeException("Cannot set platform twice");
placeholdersPlatform = platform;
throw new UnsupportedOperationException("Cannot set platform twice");
}
}
@@ -1,5 +1,7 @@
package me.dreamerzero.miniplaceholders.api;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -15,11 +17,11 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
final class Tags {
private Tags(){}
static Relational relational(String name, RelationalPlaceholder relationalPlaceholder){
static Relational relational(@NotNull final String name, @NotNull final RelationalPlaceholder relationalPlaceholder){
return new Tags.Relational(name, relationalPlaceholder);
}
static Single single(String name, AudiencePlaceholder audiencePlaceholder){
static Single single(@NotNull final String name, @NotNull final AudiencePlaceholder audiencePlaceholder){
return new Single(name, audiencePlaceholder);
}
@@ -27,27 +29,39 @@ final class Tags {
private final RelationalPlaceholder relationalPlaceholder;
private final String key;
Relational(String key, RelationalPlaceholder relationalPlaceholder){
Relational(final String key, final RelationalPlaceholder relationalPlaceholder){
this.relationalPlaceholder = relationalPlaceholder;
this.key = key;
}
TagResolver of(Audience audience, Audience otherAudience){
return TagResolver.resolver(new TagResolver(){
TagResolver of(@NotNull final Audience audience, @NotNull final Audience otherAudience){
return new TagResolver(){
@Override
public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments,
@NotNull Context ctx) throws ParsingException {
if(this.has(name)){
return relationalPlaceholder.tag(audience, otherAudience, arguments, ctx);
}
return null;
return this.has(name)
? relationalPlaceholder.tag(audience, otherAudience, arguments, ctx)
: null;
}
@Override
public boolean has(@NotNull String name) {
return key.equalsIgnoreCase(name);
}
});
};
}
@Override
public boolean equals(Object o){
if(o == this) return true;
if(!(o instanceof Relational)) return false;
return ((Relational)o).key.equals(this.key);
}
@Override
public int hashCode(){
return Objects.hash(key);
}
}
@@ -55,25 +69,39 @@ final class Tags {
private final AudiencePlaceholder audiencePlaceholder;
private final String key;
private Single(String key, AudiencePlaceholder audiencePlaceholder){
private Single(@NotNull final String key, @NotNull final AudiencePlaceholder audiencePlaceholder){
this.key = key;
this.audiencePlaceholder = audiencePlaceholder;
}
public TagResolver of(Audience audience){
return TagResolver.resolver(new TagResolver() {
TagResolver of(@NotNull final Audience audience){
return new TagResolver() {
@Override
public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments,
@NotNull Context ctx) throws ParsingException {
return this.has(name) ? audiencePlaceholder.tag(audience, arguments, ctx) : null;
return this.has(name)
? audiencePlaceholder.tag(audience, arguments, ctx)
: null;
}
@Override
public boolean has(@NotNull String name) {
return key.equalsIgnoreCase(name);
}
});
};
}
@Override
public boolean equals(Object o){
if(o == this) return true;
if(!(o instanceof Single)) return false;
return ((Single)o).key.equals(this.key);
}
@Override
public int hashCode(){
return Objects.hash(key);
}
}
}
@@ -0,0 +1,18 @@
package me.dreamerzero.miniplaceholders.api.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import me.dreamerzero.miniplaceholders.api.enums.Platform;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Extension {
String name();
Platform[] platform();
String version() default "";
}
@@ -0,0 +1,63 @@
package me.dreamerzero.miniplaceholders.api.annotation.processor;
import com.google.gson.Gson;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Name;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import me.dreamerzero.miniplaceholders.api.annotation.Extension;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Set;
@SupportedAnnotationTypes({"me.dreamerzero.miniplaceholders.api.annotation.Extension"})
public class ExtensionAnnotationProcessor extends AbstractProcessor {
private ProcessingEnvironment environment;
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
this.environment = processingEnv;
}
@Override
public synchronized boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
return false;
}
for (Element element : roundEnv.getElementsAnnotatedWith(Extension.class)) {
if (element.getKind() != ElementKind.CLASS) {
return false;
}
Extension extension = element.getAnnotation(Extension.class);
Name name = ((TypeElement) element).getQualifiedName();
try {
FileObject object = environment.getFiler()
.createResource(StandardLocation.CLASS_OUTPUT, "", "miniplaceholders-extension.json");
try (Writer writer = new BufferedWriter(object.openWriter())) {
new Gson().toJson(new ProcessedExtension(
extension.name(),
extension.version(),
name.toString(),
extension.platform()),
writer);
}
} catch (IOException e) {
environment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Cannot generate extension file");
}
}
return false;
}
}
@@ -0,0 +1,30 @@
package me.dreamerzero.miniplaceholders.api.annotation.processor;
import me.dreamerzero.miniplaceholders.api.enums.Platform;
public final class ProcessedExtension {
private final String name;
private final String version;
private final Platform[] platforms;
private final String clazz;
ProcessedExtension(String name, String version, String clazz, Platform... platforms) {
this.name = name;
this.version = version;
this.platforms = platforms;
this.clazz = clazz;
}
public String getName() {
return name;
}
public String getVersion() {
return version;
}
public Platform[] getPlatforms() {
return platforms;
}
public String getClazz() {
return this.clazz;
}
}
@@ -1,5 +1,8 @@
package me.dreamerzero.miniplaceholders.api.placeholder;
import org.jetbrains.annotations.NotNull;
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;
@@ -16,5 +19,9 @@ public interface AudiencePlaceholder {
* @return a Tag
* @since 1.0.0
*/
Tag tag(Audience audience, ArgumentQueue queue, Context ctx);
@Nullable Tag tag(
@NotNull final Audience audience,
@NotNull final ArgumentQueue queue,
@NotNull final Context ctx
);
}
@@ -1,5 +1,8 @@
package me.dreamerzero.miniplaceholders.api.placeholder;
import org.jetbrains.annotations.NotNull;
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;
@@ -17,5 +20,10 @@ public interface RelationalPlaceholder {
* @return a tag
* @since 1.0.0
*/
Tag tag(Audience audience, Audience otherAudience, ArgumentQueue queue, Context ctx);
@Nullable Tag tag(
@NotNull final Audience audience,
@NotNull final Audience otherAudience,
@NotNull final ArgumentQueue queue,
@NotNull final Context ctx
);
}
@@ -0,0 +1,31 @@
package me.dreamerzero.miniplaceholders.api.utils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
/**Common components used in expansions */
public final class Components {
private Components(){}
/**
* "True" Component
* @since 1.1.0
*/
public static final TextComponent TRUE_COMPONENT = Component.text("true", NamedTextColor.GREEN);
/**
* False Component
* @since 1.1.0
*/
public static final TextComponent FALSE_COMPONENT = Component.text("false", NamedTextColor.RED);
/**
* "Yes" Component
* @since 1.1.0
*/
public static final TextComponent YES_COMPONENT = Component.text("yes", NamedTextColor.GREEN);
/**
* "No" Component
* @since 1.1.0
*/
public static final TextComponent NO_COMPONENT = Component.text("no", NamedTextColor.RED);
}
@@ -4,15 +4,27 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
/**
* Legacy utils
*/
public final class LegacyUtils {
private LegacyUtils(){}
/**
* Legacy serializer with hex support
*
* Use this as the last available alternative,
* it is recommended to use MiniMessage instead of this serializer
*/
public static final LegacyComponentSerializer LEGACY_HEX_SERIALIZER = LegacyComponentSerializer.builder()
.character('&')
.hexColors()
.build();
/**
* Parse a string with possible legacy symbols
* @param string the string
@@ -22,18 +34,11 @@ public final class LegacyUtils {
public static @NotNull Component parsePossibleLegacy(@Nullable String string) {
if(string == null || string.isBlank()) return Component.empty();
if(string.indexOf('&') != 0){
return MiniMessage.miniMessage().deserialize(
MiniMessage.miniMessage()
.serialize(LegacyComponentSerializer.builder()
.character('&')
.hexColors()
.build()
.deserialize(string)
)
return miniMessage().deserialize(
miniMessage().serialize(LEGACY_HEX_SERIALIZER.deserialize(string))
);
} else {
return MiniMessage.miniMessage()
.deserialize(string);
return miniMessage().deserialize(string);
}
}
}
@@ -0,0 +1,47 @@
package me.dreamerzero.miniplaceholders.api.utils;
import org.jetbrains.annotations.NotNull;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
/**
* Class of utilities to manage TagResolvers
* @since 1.2.0
*/
public final class Resolvers {
private Resolvers() {}
/**
* Check if the TagResolver is an instance of TagResolver.empty(),
* that is, it will always return null
* @param resolver the resolver to check
* @return true if the TagResolver is the same as TagResolver.empty(), else false
* @since 1.2.0
*/
public static boolean isEmpty(final @NotNull TagResolver resolver) {
return resolver == TagResolver.empty();
}
/**
* Checks if the TagResolver provided is not a TagResolver.empty()
* @param resolver the resolver to check
* @return false if the TagResolver is the same as TagResolver.empty(), else true
* @since 1.2.0
*
*/
public static boolean isNotEmpty(final @NotNull TagResolver resolver) {
return resolver != TagResolver.empty();
}
/**
* Applies a TagResolver to a TagResolver.Builder in case it is not a TagResolver.empty()
* @param resolver the resolver to check
* @param builder the resolver that can be added to the builder
* @since 1.2.0
*/
public static void applyIfNotEmpty(final @NotNull TagResolver resolver, final @NotNull TagResolver.Builder builder) {
if (isNotEmpty(resolver)) {
builder.resolver(resolver);
}
}
}
@@ -1,5 +1,9 @@
package me.dreamerzero.miniplaceholders.api.utils;
import org.jetbrains.annotations.NotNull;
import me.dreamerzero.miniplaceholders.api.placeholder.AudiencePlaceholder;
import me.dreamerzero.miniplaceholders.api.placeholder.RelationalPlaceholder;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
@@ -7,6 +11,48 @@ import net.kyori.adventure.text.minimessage.tag.Tag;
public final class TagsUtils {
private TagsUtils(){}
/**Empty Tag */
/**
* Empty Tag
* @since 1.0.0
*/
public static final Tag EMPTY_TAG = Tag.selfClosingInserting(Component.empty());
/**
* Null Tag
* @since 1.1.0
*/
public static final Tag NULL_TAG = null;
/**
* An Audience placeholder that returns a null Tag
* @since 1.1.0
*/
public static final AudiencePlaceholder NULL_AUDIENCE_PLACEHOLDER = (aud, queue, ctx) -> NULL_TAG;
/**
* A Relational placeholder that returns a null tag
* @since 1.1.0
*/
public static final RelationalPlaceholder NULL_RELATIONAL_PLACEHOLDER = (aud, otheraud, queue, ctx) -> NULL_TAG;
/**
* Creates a new Tag based on a String
* @param string the string
* @return a new basic self closing Tag of a string
* @since 1.1.0
*/
public static @NotNull Tag staticTag(@NotNull String string) {
return Tag.selfClosingInserting(Component.text(string));
}
/**
* Creates a new basic Tag based on a Component
* @param component the component
* @return a new basic self closing Tag of a component
* @since 1.1.0
*/
public static @NotNull Tag staticTag(@NotNull Component component) {
return Tag.selfClosingInserting(component);
}
}
+15
View File
@@ -0,0 +1,15 @@
module me.dreamerzero.miniplaceholders.api {
requires net.kyori.adventure;
requires net.kyori.examination.api;
requires net.kyori.adventure.text.minimessage;
requires static org.jetbrains.annotations;
requires me.dreamerzero.miniplaceholders.connect;
requires java.base;
requires java.compiler;
requires com.google.gson;
exports me.dreamerzero.miniplaceholders.api;
exports me.dreamerzero.miniplaceholders.api.enums;
exports me.dreamerzero.miniplaceholders.api.utils;
exports me.dreamerzero.miniplaceholders.api.placeholder;
}
@@ -0,0 +1 @@
me.dreamerzero.miniplaceholders.api.annotation.processor.ExtensionAnnotationProcessor
@@ -0,0 +1,24 @@
package me.dreamerzero.miniplaceholders;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import me.dreamerzero.miniplaceholders.api.Expansion;
import me.dreamerzero.miniplaceholders.api.utils.TagsUtils;
class ExpansionsTest {
@Test
@DisplayName("Expansion Equality")
void equalsExpansions(){
final Expansion firstExpansion = Expansion.builder("equals")
.audiencePlaceholder("test", TagsUtils.NULL_AUDIENCE_PLACEHOLDER)
.build();
final Expansion secondExpansion = Expansion.builder("equals")
.audiencePlaceholder("test", TagsUtils.NULL_AUDIENCE_PLACEHOLDER)
.build();
assertEquals(firstExpansion, secondExpansion);
}
}
@@ -0,0 +1,33 @@
package me.dreamerzero.miniplaceholders;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import me.dreamerzero.miniplaceholders.api.Expansion;
import me.dreamerzero.miniplaceholders.api.MiniPlaceholders;
import me.dreamerzero.miniplaceholders.api.utils.TagsUtils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
class MiniPlaceholdersTest {
@Test
@Disabled("Cannot correctly calculate the equity of 2 TagResolvers obtained in different ways")
void methodEquality(){
Expansion.builder("equality")
.audiencePlaceholder("audience", TagsUtils.NULL_AUDIENCE_PLACEHOLDER)
.globalPlaceholder("global", TagsUtils.EMPTY_TAG)
.build()
.register();
assertEquals(
MiniPlaceholders.getAudienceGlobalPlaceholders(Audience.empty()),
TagResolver.resolver(
MiniPlaceholders.getAudiencePlaceholders(Audience.empty()),
MiniPlaceholders.getGlobalPlaceholders()
)
);
}
}
@@ -15,7 +15,7 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
public class PlaceholderTest {
class PlaceholderTest {
@Test
@DisplayName("Audience Placeholder Test")
@@ -98,7 +98,7 @@ public class PlaceholderTest {
}
private void assertContentEquals(Component first, Component second){
void assertContentEquals(Component first, Component second){
String firstSerialized = PlainTextComponentSerializer.plainText().serialize(first);
String secondSerialized = PlainTextComponentSerializer.plainText().serialize(second);
@@ -3,14 +3,19 @@ package me.dreamerzero.miniplaceholders;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.function.BiFunction;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import me.dreamerzero.miniplaceholders.api.Expansion;
import me.dreamerzero.miniplaceholders.api.MiniPlaceholders;
import me.dreamerzero.miniplaceholders.api.utils.TagsUtils;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
public class ThrowableTest {
class ThrowableTest {
@Test
@DisplayName("Nullable Exception")
void throwOnNull(){
@@ -19,7 +24,7 @@ public class ThrowableTest {
Expansion.Builder expansionTest = assertDoesNotThrow(() -> Expansion.builder("throwable"));
assertThrows(NullPointerException.class, () -> expansionTest.audiencePlaceholder(null, (aud, queue, ctx) -> TagsUtils.EMPTY_TAG));
assertThrows(NullPointerException.class, () -> expansionTest.globalPlaceholder("test", null));
assertThrows(NullPointerException.class, () -> expansionTest.globalPlaceholder("test", (BiFunction<ArgumentQueue, Context, Tag>)null));
Expansion.builder("testThrows")
.audiencePlaceholder("test", (aud, queue, ctx) -> TagsUtils.EMPTY_TAG)
+6 -2
View File
@@ -8,11 +8,16 @@ plugins {
allprojects {
apply(plugin = "java")
group = "me.dreamerzero.miniplaceholders"
version = "1.0.0"
version = "1.2.0"
description = "MiniPlaceholders"
repositories {
mavenCentral()
}
}
dependencies {
shadow(project(":miniplaceholders-connect"))
shadow(project(":miniplaceholders-api"))
shadow(project(":miniplaceholders-common"))
shadow(project(":miniplaceholders-velocity"))
@@ -21,7 +26,6 @@ dependencies {
subprojects {
repositories {
mavenCentral()
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.maven.apache.org/maven2/")
}
+12 -4
View File
@@ -1,5 +1,5 @@
plugins {
id("net.kyori.blossom") version "1.3.0"
id("net.kyori.blossom") version "1.3.1"
}
repositories {
@@ -8,12 +8,20 @@ repositories {
dependencies {
implementation(project(":miniplaceholders-api"))
compileOnly("net.kyori:adventure-api:4.10.1")
compileOnly("net.kyori:adventure-text-minimessage:4.10.1")
compileOnly("net.kyori:adventure-api:4.11.0")
compileOnly("net.kyori:adventure-text-minimessage:4.11.0")
compileOnly("com.mojang:brigadier:1.0.18")
}
blossom{
blossom {
replaceToken("{version}", version)
replaceTokenIn("src/main/java/me/dreamerzero/miniplaceholders/common/PluginConstants.java")
}
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
}
@@ -0,0 +1,24 @@
package me.dreamerzero.miniplaceholders.extension;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import me.dreamerzero.miniplaceholders.api.annotation.Extension;
public final class Loader {
private Loader() {}
public static Extension[] loadExtensions(Path extensionsPath) {
List<Extension> extensions = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(extensionsPath, (file) -> file.toString().endsWith(".jar"))) {
for (Path ext : stream) {
}
} catch(IOException e) {
}
}
}
+7
View File
@@ -0,0 +1,7 @@
java.toolchain.languageVersion.set(JavaLanguageVersion.of(11))
tasks.compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(11)
}
@@ -0,0 +1,16 @@
package me.dreamerzero.miniplaceholders.connect;
public enum InternalPlatform {
PAPER, VELOCITY;
private static InternalPlatform actualPlatform;
public static void platform(final InternalPlatform platform){
InternalPlatform.actualPlatform = platform;
}
public static InternalPlatform platform(){
return InternalPlatform.actualPlatform;
}
}
+4
View File
@@ -0,0 +1,4 @@
module me.dreamerzero.miniplaceholders.connect {
//TODO: exports to
exports me.dreamerzero.miniplaceholders.connect;
}
Vendored Regular → Executable
View File
File mode changed.
+2
View File
@@ -0,0 +1,2 @@
# run-paper files
/run
+10 -5
View File
@@ -1,23 +1,25 @@
plugins {
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
id("io.papermc.paperweight.userdev") version "1.3.5"
id("net.minecrell.plugin-yml.bukkit") version "0.5.2"
id("io.papermc.paperweight.userdev") version "1.3.8"
id("xyz.jpenilla.run-paper") version "1.0.6"
}
dependencies {
compileOnly(project(":miniplaceholders-common"))
compileOnly(project(":miniplaceholders-api"))
paperDevBundle("1.18.2-R0.1-SNAPSHOT")
compileOnly(project(":miniplaceholders-connect"))
paperDevBundle("1.19.1-R0.1-SNAPSHOT")
}
val pluginVersion = version
val pluginVersion: String = version as String
bukkit {
name = "MiniPlaceholders"
main = "me.dreamerzero.miniplaceholders.paper.PaperPlugin"
apiVersion = "1.18"
website = "https://github.com/4drian3d/MiniPlaceholders"
authors = listOf("4drian3d")
version = pluginVersion as String
version = pluginVersion
}
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
@@ -31,5 +33,8 @@ tasks {
options.release.set(17)
}
runServer {
minecraftVersion("1.19.1")
}
}
@@ -1,41 +1,37 @@
package me.dreamerzero.miniplaceholders.paper;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import io.papermc.paper.datapack.Datapack;
import me.dreamerzero.miniplaceholders.api.Expansion;
import me.dreamerzero.miniplaceholders.api.MiniPlaceholders;
import me.dreamerzero.miniplaceholders.api.enums.Platform;
import me.dreamerzero.miniplaceholders.api.utils.TagsUtils;
import me.dreamerzero.miniplaceholders.common.PlaceholdersCommand;
import me.dreamerzero.miniplaceholders.common.PlaceholdersPlugin;
import me.dreamerzero.miniplaceholders.connect.InternalPlatform;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin, Listener {
private final NumberFormat tpsFormat = NumberFormat.getInstance();
private final NumberFormat msptFormat = NumberFormat.getInstance();
private final DecimalFormat tpsFormat = new DecimalFormat("###.##");
private final DecimalFormat msptFormat = new DecimalFormat("###.###");
@Override
@SuppressWarnings("deprecation")
public void onEnable(){
this.getSLF4JLogger().info("Starting MiniPlaceholders Paper");
MiniPlaceholders.setPlatform(Platform.PAPER);
InternalPlatform.platform(InternalPlatform.PAPER);
this.getServer().getPluginManager().registerEvents(this, this);
tpsFormat.setRoundingMode(RoundingMode.DOWN);
tpsFormat.setMaximumFractionDigits(2);
msptFormat.setRoundingMode(RoundingMode.DOWN);
msptFormat.setMaximumFractionDigits(3);
tpsFormat.setRoundingMode(RoundingMode.HALF_UP);
msptFormat.setRoundingMode(RoundingMode.HALF_UP);
this.loadDefaultExpansions();
this.registerPlatformCommand();
@@ -44,30 +40,30 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin,
@Override
public void loadDefaultExpansions() {
Expansion.builder("server")
.globalPlaceholder("name", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.getServer().getName())))
.globalPlaceholder("online", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.getServer().getOnlinePlayers().size())))
.globalPlaceholder("version", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.getServer().getVersion())))
.globalPlaceholder("max_players", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.getServer().getMaxPlayers())))
.globalPlaceholder("unique_joins", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.getServer().getOfflinePlayers().length)))
.globalPlaceholder("tps_1", (queue, ctx) -> Tag.selfClosingInserting(Component.text(tpsFormat.format(this.getCraftServer().getHandle().getServer().recentTps[0]))))
.globalPlaceholder("tps_5", (queue, ctx) -> Tag.selfClosingInserting(Component.text(tpsFormat.format(this.getCraftServer().getHandle().getServer().recentTps[1]))))
.globalPlaceholder("tps_15", (queue, ctx) -> Tag.selfClosingInserting(Component.text(tpsFormat.format(this.getCraftServer().getHandle().getServer().recentTps[2]))))
.globalPlaceholder("has_whitelist", (queue, ctx) -> Tag.selfClosingInserting(Component.text(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(tpsFormat.format(this.getServer().getTPS()[0])))
.globalPlaceholder("tps_5", (queue, ctx) -> TagsUtils.staticTag(tpsFormat.format(this.getServer().getTPS()[1])))
.globalPlaceholder("tps_15", (queue, ctx) -> TagsUtils.staticTag(tpsFormat.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.selfClosingInserting(Component.text(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.selfClosingInserting(Component.text(entityCount));
return TagsUtils.staticTag(Component.text(entityCount));
})
.globalPlaceholder("mspt", (queue, ctx) -> Tag.selfClosingInserting(Component.text(msptFormat.format(this.getServer().getAverageTickTime()))))
.globalPlaceholder("mspt", (queue, ctx) -> TagsUtils.staticTag(msptFormat.format(this.getServer().getAverageTickTime())))
.globalPlaceholder("datapack_list", (queue, ctx) -> {
TextComponent.Builder builder = Component.text();
for(Datapack datapack : this.getServer().getDatapackManager().getEnabledPacks()){
@@ -81,9 +77,9 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin,
}
@Override
@SuppressWarnings("all")
@SuppressWarnings({"sonarlint(java:s1874)", "deprecation", /*TODO: replace with Java(536871800) */ "all"})
public void registerPlatformCommand() {
this.getCraftServer().getServer()
MinecraftServer.getServer()
.vanillaCommandDispatcher
.getDispatcher()
.register(new PlaceholdersCommand<>(
@@ -93,8 +89,4 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin,
).placeholderTestBuilder("miniplaceholders")
);
}
private CraftServer getCraftServer(){
return (CraftServer)this.getServer();
}
}
+5 -8
View File
@@ -7,13 +7,10 @@ pluginManagement {
rootProject.name = "miniplaceholders-parent"
val modules = listOf("connect", "api", "common", "paper", "velocity")
include("miniplaceholders-api")
include("miniplaceholders-common")
include("miniplaceholders-paper")
include("miniplaceholders-velocity")
modules.forEach {
include("miniplaceholders-$it")
project(":miniplaceholders-$it").projectDir = file(it)
}
project(":miniplaceholders-api").projectDir = file("api")
project(":miniplaceholders-common").projectDir = file("common")
project(":miniplaceholders-velocity").projectDir = file("velocity")
project(":miniplaceholders-paper").projectDir = file("paper")
+8 -1
View File
@@ -3,6 +3,13 @@ dependencies {
annotationProcessor("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
compileOnly(project(":miniplaceholders-common"))
compileOnly(project(":miniplaceholders-api"))
compileOnly(project(":miniplaceholders-connect"))
}
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
tasks.compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
@@ -12,11 +12,12 @@ import com.velocitypowered.api.proxy.ProxyServer;
import org.slf4j.Logger;
import me.dreamerzero.miniplaceholders.api.Expansion;
import me.dreamerzero.miniplaceholders.api.MiniPlaceholders;
import me.dreamerzero.miniplaceholders.api.enums.Platform;
import me.dreamerzero.miniplaceholders.api.utils.Components;
import me.dreamerzero.miniplaceholders.api.utils.TagsUtils;
import me.dreamerzero.miniplaceholders.common.PlaceholdersCommand;
import me.dreamerzero.miniplaceholders.common.PlaceholdersPlugin;
import me.dreamerzero.miniplaceholders.common.PluginConstants;
import me.dreamerzero.miniplaceholders.connect.InternalPlatform;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
@@ -30,17 +31,16 @@ public final class VelocityPlugin implements PlaceholdersPlugin {
private final Logger logger;
private final ProxyServer proxy;
@Inject
public VelocityPlugin(Logger logger, ProxyServer proxy) {
public VelocityPlugin(final Logger logger, final ProxyServer proxy) {
this.logger = logger;
this.proxy = proxy;
}
@Subscribe
@SuppressWarnings("deprecation")
public void onProxyInitialize(ProxyInitializeEvent event) {
public void onProxyInitialize(final ProxyInitializeEvent event) {
logger.info("Starting MiniPlaceholders Velocity");
MiniPlaceholders.setPlatform(Platform.VELOCITY);
InternalPlatform.platform(InternalPlatform.VELOCITY);
this.loadDefaultExpansions();
this.registerPlatformCommand();
@@ -59,16 +59,16 @@ public final class VelocityPlugin implements PlaceholdersPlugin {
.globalPlaceholder("server_count", (queue, ctx) -> Tag.selfClosingInserting(Component.text(proxy.getAllServers().size())))
.globalPlaceholder("is_player_online", (queue, ctx) -> {
String playerName = queue.popOr(() -> "you need to introduce an argument").value();
return Tag.selfClosingInserting(Component.text(proxy.getPlayer(playerName).isPresent()));
return TagsUtils.staticTag(proxy.getPlayer(playerName).isPresent() ? Components.YES_COMPONENT : Components.NO_COMPONENT);
})
.globalPlaceholder("version", (queue, ctx) -> Tag.selfClosingInserting(Component.text(proxy.getVersion().getVersion())))
.globalPlaceholder("version", TagsUtils.staticTag(proxy.getVersion().getVersion()))
.build()
.register();
}
@Override
public void registerPlatformCommand() {
BrigadierCommand brigadierCMD = new BrigadierCommand(
final BrigadierCommand brigadierCMD = new BrigadierCommand(
new PlaceholdersCommand<CommandSource>(
() -> proxy.getAllPlayers().stream().map(Player::getUsername).toList(),
(String st) -> proxy.getPlayer(st).orElse(null))