Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5adadcbbcb | ||
|
|
4c1739f3b0 | ||
|
|
dcfd2a6fe1 | ||
|
|
b7a56198f4 | ||
|
|
2d9fdaccc2 | ||
|
|
4f63f55d11 | ||
|
|
5495f5f57a | ||
|
|
d33e98714a | ||
|
|
e6e98c9852 | ||
|
|
6f9abbefc9 | ||
|
|
7ee6dcb1b7 | ||
|
|
db37d4ae66 | ||
|
|
38b707d091 | ||
|
|
6737e63232 | ||
|
|
5f9c42c5d7 | ||
|
|
f97665fe47 | ||
|
|
202782e053 | ||
|
|
20da844129 | ||
|
|
e98b222250 | ||
|
|
430c483f39 | ||
|
|
92798a38c7 | ||
|
|
5f491e9553 | ||
|
|
1a862fce44 | ||
|
|
da965a7b4a | ||
|
|
d3cd42c076 | ||
|
|
4a3572d39c | ||
|
|
8f5baf7757 | ||
|
|
5a98d82c49 | ||
|
|
984ef05ffb | ||
|
|
db2a723c57 | ||
|
|
5187a74a06 | ||
|
|
4b7a003c27 | ||
|
|
1a673997e0 | ||
|
|
2364f306a8 | ||
|
|
23b21eb921 | ||
|
|
6e71e33bf8 | ||
|
|
1164d4551f | ||
|
|
de562d1bae | ||
|
|
9c117b156b | ||
|
|
4a9b90ed95 | ||
|
|
de095dd900 | ||
|
|
05af305d50 | ||
|
|
c9a9783e8a | ||
|
|
5835fb3d45 | ||
|
|
914275b16d | ||
|
|
a98aa93fb4 | ||
|
|
f0fd8148ad | ||
|
|
045cb01911 | ||
|
|
40ba7593a6 | ||
|
|
978e63c8dc | ||
|
|
9b04b58f50 | ||
|
|
9f7eaf1614 | ||
|
|
9286751bd0 | ||
|
|
16783494ad | ||
|
|
9050aed7a3 | ||
|
|
9ef9b1b3c6 | ||
|
|
8290c946df | ||
|
|
5057fe4817 | ||
|
|
c43debe9bb | ||
|
|
15d9f527eb | ||
|
|
68dd632c69 | ||
|
|
b0da895025 | ||
|
|
29dcd5bcdf | ||
|
|
f156f48c54 | ||
|
|
a1b1118aa2 | ||
|
|
5e716cb6d9 | ||
|
|
ebe04a3ede | ||
|
|
5e97666be7 | ||
|
|
aa8a36c92b | ||
|
|
c3fac7a11a | ||
|
|
a12c37bc97 | ||
|
|
e83bc3d8f6 | ||
|
|
e0767d9bff | ||
|
|
70e8d8925d | ||
|
|
ea9213bf2d | ||
|
|
fc6bc5c728 | ||
|
|
007fe3279d | ||
|
|
9976b9bf89 | ||
|
|
b9035fe504 | ||
|
|
cff2aee3d6 | ||
|
|
b45d8be1e5 | ||
|
|
b4fcf85b07 | ||
|
|
7363571d91 | ||
|
|
d6c883edf4 | ||
|
|
6a011c0699 | ||
|
|
4779fb9f69 | ||
|
|
f97650ef1f | ||
|
|
98e280e01b | ||
|
|
d35892d964 | ||
|
|
9263698139 | ||
|
|
194801df6b | ||
|
|
06e927045e | ||
|
|
5e8a881b51 | ||
|
|
8bb9bafb8b | ||
|
|
74f14f139c | ||
|
|
45b2fbe977 | ||
|
|
df04f51d60 | ||
|
|
5b35094d27 | ||
|
|
e8635bc6c8 | ||
|
|
a1e95295cc | ||
|
|
927563f749 | ||
|
|
225bafeaaa | ||
|
|
dac6354071 | ||
|
|
01bb19213c | ||
|
|
6ff764bf4c | ||
|
|
4a509e63a2 | ||
|
|
f9d3f01a34 | ||
|
|
e5cf5001eb | ||
|
|
a762a68901 | ||
|
|
20b7d92710 | ||
|
|
d0edacfafd | ||
|
|
43c034fc0b | ||
|
|
2337525e25 | ||
|
|
0bb6f6264a | ||
|
|
24a7591a0f | ||
|
|
6a73aa3f46 | ||
|
|
7832d96d50 | ||
|
|
900214dfad | ||
|
|
9de6aceac3 | ||
|
|
4e2599abd3 | ||
|
|
dc5d4c5cc9 | ||
|
|
782bd02a33 | ||
|
|
25a3ce024d | ||
|
|
ece1252a6e | ||
|
|
4df9c296c9 | ||
|
|
68e2034dd3 |
No files matched your search
@@ -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']
|
||||
@@ -8,10 +8,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v2
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: 17
|
||||
distribution: 'temurin'
|
||||
@@ -25,7 +25,7 @@ jobs:
|
||||
command: gradle build
|
||||
|
||||
- name: Upload Artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: MiniPlaceholders
|
||||
path: build/libs/MiniPlaceholders.jar
|
||||
path: build/libs/MiniPlaceholders-*.jar
|
||||
@@ -1,13 +1,67 @@
|
||||
# MiniPlaceholders
|
||||
# MiniPlaceholders  [](https://discord.gg/5NMMzK5mAn)
|
||||
MiniMessage Component-based Placeholders for PaperMC and Velocity platforms
|
||||
|
||||
## Compatibility
|
||||
- Paper 1.19.4+
|
||||
- Velocity 3.1.2+
|
||||
- Krypton
|
||||
|
||||
## Commands:
|
||||
### Velocity
|
||||
`/vminiplaceholders <parse|help> <me|player> <player-to-parse>`
|
||||
### Paper
|
||||
`/miniplaceholders <parse|help> <me|player> <player-to-parse>`
|
||||
|
||||
## API
|
||||
Check the available javadocs [here](https://javadoc.jitpack.io/com/github/4drian3d/MiniPlaceholders/latest/javadoc/index.html)
|
||||
## Usage
|
||||
|
||||
Check our usage wiki [here](https://github.com/MiniPlaceholders/MiniPlaceholders/wiki/User-Getting-Started)
|
||||
|
||||
## API
|
||||
|
||||
### Java
|
||||
```java
|
||||
|
||||
class Main {
|
||||
public static void registerExpansion() {
|
||||
Expansion expansion = Expansion.builder("my-expansion")
|
||||
.filter(Player.class)
|
||||
.audiencePlaceholder("name", (aud, ctx, queue) ->
|
||||
Tag.selfClosingInserting(aud.getName())
|
||||
)
|
||||
.globalPlaceholder("tps", (ctx, queue) ->
|
||||
Tag.selfClosingInserting(Component.text(Bukkit.getTps()[0]))
|
||||
).build;
|
||||
|
||||
expansion.register();
|
||||
|
||||
Player player;
|
||||
player.sendMessage(miniMessage().deserialize("Player Name: <my-expansion_name>", MiniPlaceholders.getAudiencePlaceholders(player)));
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Kotlin
|
||||
```kotlin
|
||||
fun register() {
|
||||
val expansion = expansion("my-expansion") {
|
||||
audiencePlaceholder("name") { aud, _, _ ->
|
||||
aud.getName().asClosingTag()
|
||||
}
|
||||
globalPlaceholder("tps") { _, _ ->
|
||||
Component.text(Bukkit.getTps()[0]).asInsertingTag()
|
||||
}
|
||||
}
|
||||
|
||||
expansion.register()
|
||||
|
||||
val player: Player
|
||||
player.sendMessage(miniMessage().deserialize("Player Name: <my-expansion_name>", MiniPlaceholders.getAudiencePlaceholders(player)))
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Check the available javadocs [here](https://javadoc.io/doc/io.github.miniplaceholders/miniplaceholders-api)
|
||||
|
||||
Or check the developer wiki [here](https://github.com/MiniPlaceholders/MiniPlaceholders/wiki/Developer-Getting-Started)
|
||||
|
||||
Or check the wiki [here](https://github.com/4drian3d/MiniPlaceholders/wiki)
|
||||
+23
-35
@@ -1,17 +1,19 @@
|
||||
plugins {
|
||||
id("me.champeau.jmh") version "0.6.6"
|
||||
`maven-publish`
|
||||
alias(libs.plugins.jmh)
|
||||
id("miniplaceholders.publish")
|
||||
|
||||
}
|
||||
|
||||
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")
|
||||
testImplementation(platform("org.junit:junit-bom:5.8.1"))
|
||||
compileOnly(libs.adventure.api)
|
||||
compileOnly(libs.adventure.minimesssage)
|
||||
compileOnly("net.kyori:adventure-text-serializer-legacy:4.13.1")
|
||||
compileOnly(projects.miniplaceholdersConnect)
|
||||
testImplementation(platform("org.junit:junit-bom:5.9.2"))
|
||||
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(libs.adventure.api)
|
||||
testImplementation(libs.adventure.minimesssage)
|
||||
testImplementation("net.kyori:adventure-text-serializer-plain:4.13.1")
|
||||
}
|
||||
|
||||
tasks {
|
||||
@@ -28,44 +30,30 @@ jmh {
|
||||
iterations.set(2)
|
||||
fork.set(2)
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
|
||||
val projectGroup: String = project.group as String
|
||||
val projectVersion: String = project.version as String
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
groupId = projectGroup
|
||||
artifactId = project.name
|
||||
version = projectVersion
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
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/"
|
||||
)
|
||||
}
|
||||
|
||||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
javadoc {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
(options as StandardJavadocDocletOptions).links(
|
||||
"https://jd.advntr.dev/api/${libs.versions.adventure.get()}/",
|
||||
"https://jd.advntr.dev/text-minimessage/${libs.versions.adventure.get()}/"
|
||||
)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.dreamerzero.miniplaceholders;
|
||||
package io.github.miniplaceholders.jmh;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package me.dreamerzero.miniplaceholders;
|
||||
package io.github.miniplaceholders.jmh;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -9,8 +9,8 @@ import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.Expansion;
|
||||
import me.dreamerzero.miniplaceholders.api.MiniPlaceholders;
|
||||
import io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.miniplaceholders.api.MiniPlaceholders;
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
public class PlaceholderBenchmark {
|
||||
+26
-12
@@ -1,13 +1,14 @@
|
||||
package me.dreamerzero.miniplaceholders.api;
|
||||
package io.github.miniplaceholders.api;
|
||||
|
||||
import io.github.miniplaceholders.api.placeholder.AudiencePlaceholder;
|
||||
import io.github.miniplaceholders.api.placeholder.RelationalPlaceholder;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
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;
|
||||
@@ -48,7 +49,7 @@ public interface Expansion {
|
||||
* @return A TagResolver with variable placeholders of an Audience
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull TagResolver audiencePlaceholders(@NotNull final Audience audience);
|
||||
@NotNull TagResolver audiencePlaceholders(final @NotNull Audience audience);
|
||||
|
||||
/**
|
||||
* Get the relational placeholders based on two audiences
|
||||
@@ -61,7 +62,7 @@ public interface Expansion {
|
||||
* @return A TagResolver with variable placeholders between 2 {@link Audience}s
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull TagResolver relationalPlaceholders(@NotNull final Audience audience, @NotNull final Audience otherAudience);
|
||||
@NotNull TagResolver relationalPlaceholders(final @NotNull Audience audience, final @NotNull Audience otherAudience);
|
||||
|
||||
/**
|
||||
* Get global placeholders
|
||||
@@ -82,7 +83,7 @@ public interface Expansion {
|
||||
* @return a new expansion builder
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull Expansion.Builder builder(@NotNull final String name){
|
||||
static @NotNull Expansion.Builder builder(final @NotNull String name){
|
||||
return new ExpansionImpl.Builder(name);
|
||||
}
|
||||
|
||||
@@ -108,7 +109,7 @@ public interface Expansion {
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static interface Builder extends AbstractBuilder<Expansion> {
|
||||
interface Builder extends AbstractBuilder<Expansion> {
|
||||
/**
|
||||
* Adds an audience placeholder
|
||||
*
|
||||
@@ -121,7 +122,7 @@ public interface Expansion {
|
||||
* @return the {@link Builder} itself
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull Builder audiencePlaceholder(@NotNull final String key, @NotNull final AudiencePlaceholder audiencePlaceholder);
|
||||
@NotNull Builder audiencePlaceholder(final @NotNull String key, final @NotNull AudiencePlaceholder audiencePlaceholder);
|
||||
|
||||
/**
|
||||
* Adds an Relational Placeholder based on two audiences
|
||||
@@ -139,7 +140,7 @@ public interface Expansion {
|
||||
* @return the {@link Builder} itself
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull Builder relationalPlaceholder(@NotNull final String key, @NotNull final RelationalPlaceholder relationalPlaceholder);
|
||||
@NotNull Builder relationalPlaceholder(final @NotNull String key, final @NotNull RelationalPlaceholder relationalPlaceholder);
|
||||
|
||||
/**
|
||||
* Adds a global placeholder
|
||||
@@ -151,7 +152,18 @@ public interface Expansion {
|
||||
* @return the {@link Builder} itself
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull Builder globalPlaceholder(@NotNull final String key, final BiFunction<ArgumentQueue, Context, Tag> function);
|
||||
@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
|
||||
*/
|
||||
@NotNull Builder globalPlaceholder(final @NotNull String key, final @NotNull Tag tag);
|
||||
|
||||
/**
|
||||
* Filter the type of Audiences that this expansion can receive
|
||||
@@ -166,7 +178,8 @@ public interface Expansion {
|
||||
* @return the {@link Builder} itself
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull Builder filter(@Nullable final 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
|
||||
@@ -180,6 +193,7 @@ public interface Expansion {
|
||||
* @return the {@link Builder} itself
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull Builder filter(@NotNull final Predicate<Audience> predicate);
|
||||
@Contract("_ -> this")
|
||||
@NotNull Builder filter(final @Nullable Predicate<Audience> predicate);
|
||||
}
|
||||
}
|
||||
+33
-22
@@ -1,4 +1,4 @@
|
||||
package me.dreamerzero.miniplaceholders.api;
|
||||
package io.github.miniplaceholders.api;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -6,15 +6,15 @@ import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import io.github.miniplaceholders.api.placeholder.AudiencePlaceholder;
|
||||
import io.github.miniplaceholders.api.placeholder.RelationalPlaceholder;
|
||||
import io.github.miniplaceholders.api.utils.Conditions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.placeholder.AudiencePlaceholder;
|
||||
import me.dreamerzero.miniplaceholders.api.placeholder.RelationalPlaceholder;
|
||||
import me.dreamerzero.miniplaceholders.api.utils.Conditions;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.minimessage.Context;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
@@ -51,7 +51,7 @@ final class ExpansionImpl implements Expansion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name(){
|
||||
public @NotNull String name(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ final class ExpansionImpl implements Expansion {
|
||||
public @NotNull TagResolver audiencePlaceholders(@NotNull final Audience audience){
|
||||
if(audiencePlaceholders.length == 0) return TagResolver.empty();
|
||||
|
||||
Objects.requireNonNull(audience, () -> "the audience cannot be null");
|
||||
Objects.requireNonNull(audience, "the audience cannot be null");
|
||||
|
||||
if(this.singleFilter(audience)) return TagResolver.empty();
|
||||
|
||||
@@ -79,13 +79,13 @@ final class ExpansionImpl implements Expansion {
|
||||
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");
|
||||
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();
|
||||
if (this.relationalFilter(audience, otherAudience)) return TagResolver.empty();
|
||||
|
||||
final TagResolver.Builder placeholders = TagResolver.builder();
|
||||
for(final Tags.Relational pl : this.relationalPlaceholders){
|
||||
for (final Tags.Relational pl : this.relationalPlaceholders){
|
||||
placeholders.resolver(pl.of(audience, otherAudience));
|
||||
}
|
||||
return placeholders.build();
|
||||
@@ -120,31 +120,31 @@ final class ExpansionImpl implements Expansion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder audiencePlaceholder(@NotNull final String key, @NotNull final AudiencePlaceholder audiencePlaceholder){
|
||||
public @NotNull Builder audiencePlaceholder(@NotNull final String key, @NotNull final AudiencePlaceholder audiencePlaceholder){
|
||||
Conditions.nonNullOrEmptyString(key, () -> "placeholder key");
|
||||
Objects.requireNonNull(audiencePlaceholder, () -> "the audience placeholder cannot be null");
|
||||
Objects.requireNonNull(audiencePlaceholder, "the audience placeholder cannot be null");
|
||||
|
||||
if(this.audiencePlaceholders == null) this.audiencePlaceholders = new HashSet<>(5);
|
||||
if (this.audiencePlaceholders == null) this.audiencePlaceholders = new HashSet<>(5);
|
||||
|
||||
this.audiencePlaceholders.add(Tags.single(expansionName+key, audiencePlaceholder));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder relationalPlaceholder(@NotNull final String key, @NotNull final RelationalPlaceholder relationalPlaceholder){
|
||||
public @NotNull Builder relationalPlaceholder(@NotNull final String key, @NotNull final RelationalPlaceholder relationalPlaceholder){
|
||||
Conditions.nonNullOrEmptyString(key, () -> "placeholder key");
|
||||
Objects.requireNonNull(relationalPlaceholder, () -> "the relational placeholder cannot be null");
|
||||
Objects.requireNonNull(relationalPlaceholder, "the relational placeholder cannot be null");
|
||||
|
||||
if(this.relationalPlaceholders == null) this.relationalPlaceholders = new HashSet<>(4);
|
||||
if (this.relationalPlaceholders == null) this.relationalPlaceholders = new HashSet<>(4);
|
||||
|
||||
this.relationalPlaceholders.add(Tags.relational(expansionName+"rel_"+key, relationalPlaceholder));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder globalPlaceholder(@NotNull final String key, @NotNull final BiFunction<ArgumentQueue, Context, Tag> function){
|
||||
public @NotNull 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");
|
||||
Objects.requireNonNull(function, "the global placeholder cannot be null");
|
||||
|
||||
if(this.globalPlaceholders == null) this.globalPlaceholders = TagResolver.builder();
|
||||
|
||||
@@ -153,13 +153,24 @@ final class ExpansionImpl implements Expansion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder filter(@Nullable final Class<? extends Audience> clazz) {
|
||||
public @NotNull 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 @NotNull Builder filter(@Nullable final Class<? extends Audience> clazz) {
|
||||
this.filterClass = clazz;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder filter(@NotNull final Predicate<Audience> predicate){
|
||||
public @NotNull Builder filter(@Nullable final Predicate<Audience> predicate){
|
||||
this.predicateFilter = predicate;
|
||||
return this;
|
||||
}
|
||||
@@ -179,8 +190,8 @@ final class ExpansionImpl implements Expansion {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o){
|
||||
if(this==o) return true;
|
||||
if(o == null || o.getClass() != ExpansionImpl.class) return false;
|
||||
if (this==o) return true;
|
||||
if (o == null || o.getClass() != ExpansionImpl.class) return false;
|
||||
return ((ExpansionImpl)o).name.equals(this.name);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
package io.github.miniplaceholders.api;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import io.github.miniplaceholders.api.enums.Platform;
|
||||
import io.github.miniplaceholders.api.utils.Resolvers;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import io.github.miniplaceholders.connect.InternalPlatform;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* MiniPlaceholders
|
||||
*
|
||||
* <p>This class allows you to obtain the {@link TagResolver}
|
||||
* that other plugins provide based on single {@link Audience},
|
||||
* 2-audience or global placeholders</p>
|
||||
*
|
||||
* @author 4drian3d
|
||||
* @see TagResolver
|
||||
* @see Expansion
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public final class MiniPlaceholders {
|
||||
private MiniPlaceholders(){}
|
||||
static final Set<Expansion> expansions = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
/**
|
||||
* Get the platform
|
||||
* @return the platform
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull Platform getPlatform() {
|
||||
switch (InternalPlatform.platform()) {
|
||||
case PAPER: return Platform.PAPER;
|
||||
case VELOCITY: return Platform.VELOCITY;
|
||||
default: return Platform.KRYPTON;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the global placeholders
|
||||
*
|
||||
* <pre>TagResolver resolver = MiniPlaceholders.getGlobalPlaceholders();
|
||||
* Component messageParsed = MiniMessage.miniMessage().deserialize({@link String}, resolver);</pre>
|
||||
*
|
||||
* @return global placeholders independient of any audience
|
||||
* @see TagResolver
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull TagResolver getGlobalPlaceholders() {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the TagResolver based on an Audience
|
||||
*
|
||||
* <pre>TagResolver resolver = MiniPlaceholders.getAudiencePlaceholders({@link Audience});
|
||||
* Component messageParsed = MiniMessage.miniMessage().deserialize({@link String}, resolver);</pre>
|
||||
*
|
||||
* @param audience the audience
|
||||
* @return {@link TagResolver} with placeholders based on an audience
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull TagResolver getAudiencePlaceholders(final @NotNull Audience audience) {
|
||||
requireNonNull(audience, "audience cannot be null");
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relational placeholders based on two audiences
|
||||
*
|
||||
* <pre>TagResolver resolver = MiniPlaceholders.getRelationalPlaceholders({@link Audience}, {@link Audience});
|
||||
* Component messageParsed = MiniMessage.miniMessage().deserialize({@link String}, resolver);</pre>
|
||||
*
|
||||
* @param audience an audience
|
||||
* @param otherAudience another audience
|
||||
* @return placeholders based on two audiences
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull TagResolver getRelationalPlaceholders(final @NotNull Audience audience, final @NotNull Audience otherAudience) {
|
||||
requireNonNull(audience, "audience cannot be null");
|
||||
requireNonNull(otherAudience, "otherAudience cannot be null");
|
||||
|
||||
final TagResolver.Builder builder = TagResolver.builder();
|
||||
for (final Expansion expansion : expansions) {
|
||||
Resolvers.applyIfNotEmpty(
|
||||
expansion.relationalPlaceholders(audience, otherAudience),
|
||||
builder
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
public static @NotNull TagResolver getAudienceGlobalPlaceholders(final @NotNull Audience audience) {
|
||||
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 relational 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
|
||||
*/
|
||||
public static @NotNull TagResolver getRelationalGlobalPlaceholders(final @NotNull Audience audience, final @NotNull Audience otherAudience) {
|
||||
requireNonNull(audience, "audience cannot be null");
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of expansion registered
|
||||
* @return the amount of expansions registered
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static int getExpansionCount(){
|
||||
return expansions.size();
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
package me.dreamerzero.miniplaceholders.api;
|
||||
package io.github.miniplaceholders.api;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import io.github.miniplaceholders.api.placeholder.AudiencePlaceholder;
|
||||
import io.github.miniplaceholders.api.placeholder.RelationalPlaceholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.placeholder.AudiencePlaceholder;
|
||||
import me.dreamerzero.miniplaceholders.api.placeholder.RelationalPlaceholder;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.minimessage.Context;
|
||||
import net.kyori.adventure.text.minimessage.ParsingException;
|
||||
+4
-2
@@ -1,9 +1,11 @@
|
||||
package me.dreamerzero.miniplaceholders.api.enums;
|
||||
package io.github.miniplaceholders.api.enums;
|
||||
|
||||
/**Platforms on which MiniPlaceholders can be used */
|
||||
public enum Platform {
|
||||
/**Paper Platform */
|
||||
PAPER,
|
||||
/**Velocity Platform */
|
||||
VELOCITY
|
||||
VELOCITY,
|
||||
/**Krypton Platform */
|
||||
KRYPTON
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
/**Plugin enums */
|
||||
package io.github.miniplaceholders.api.enums;
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* MiniPlaceholders core package
|
||||
*/
|
||||
package io.github.miniplaceholders.api;
|
||||
+9
-2
@@ -1,4 +1,7 @@
|
||||
package me.dreamerzero.miniplaceholders.api.placeholder;
|
||||
package io.github.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;
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
+10
-2
@@ -1,4 +1,7 @@
|
||||
package me.dreamerzero.miniplaceholders.api.placeholder;
|
||||
package io.github.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;
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
* Placeholders available based on information obtained from Audiences
|
||||
*/
|
||||
package me.dreamerzero.miniplaceholders.api.placeholder;
|
||||
package io.github.miniplaceholders.api.placeholder;
|
||||
@@ -0,0 +1,31 @@
|
||||
package io.github.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
-4
@@ -1,4 +1,4 @@
|
||||
package me.dreamerzero.miniplaceholders.api.utils;
|
||||
package io.github.miniplaceholders.api.utils;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -14,9 +14,9 @@ public final class Conditions {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static String nonNullOrEmptyString(String string, Supplier<String> name){
|
||||
if(string == null)
|
||||
if (string == null)
|
||||
throw new NullPointerException("the " + name.get() + " cannot be null");
|
||||
if(string.isBlank())
|
||||
if (string.isBlank())
|
||||
throw new IllegalStateException("the " + name.get() + "cannot be an empty string");
|
||||
return string;
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public final class Conditions {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static String nonEmptyString(String string, Supplier<String> reason){
|
||||
if(string.isBlank())
|
||||
if (string.isBlank())
|
||||
throw new IllegalStateException(reason.get());
|
||||
return string;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package io.github.miniplaceholders.api.utils;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
|
||||
|
||||
/**
|
||||
* Legacy utils
|
||||
*/
|
||||
public final class LegacyUtils {
|
||||
private LegacyUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy serializer with hex support
|
||||
* <p>Use this as the last available alternative,
|
||||
* it is recommended to use MiniMessage instead of this serializer</p>
|
||||
*/
|
||||
public static final LegacyComponentSerializer LEGACY_HEX_SERIALIZER = LegacyComponentSerializer.builder()
|
||||
.character('&')
|
||||
.hexColors()
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Parse a string with possible legacy symbols
|
||||
*
|
||||
* @param string the string
|
||||
* @return a parsed string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull Component parsePossibleLegacy(@Nullable String string) {
|
||||
if (string == null || string.isBlank()) return Component.empty();
|
||||
if (string.indexOf('&') != 0) {
|
||||
return miniMessage().deserialize(
|
||||
miniMessage().serialize(LEGACY_HEX_SERIALIZER.deserialize(string))
|
||||
);
|
||||
} else {
|
||||
return miniMessage().deserialize(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package io.github.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package io.github.miniplaceholders.api.utils;
|
||||
|
||||
import io.github.miniplaceholders.api.placeholder.AudiencePlaceholder;
|
||||
import io.github.miniplaceholders.api.placeholder.RelationalPlaceholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
|
||||
/**Tags utils */
|
||||
public final class TagsUtils {
|
||||
private TagsUtils(){}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
* General Utilities
|
||||
* Here you will find utilities that will help you in the development of expansions
|
||||
*/
|
||||
package me.dreamerzero.miniplaceholders.api.utils;
|
||||
package io.github.miniplaceholders.api.utils;
|
||||
@@ -1,124 +0,0 @@
|
||||
package me.dreamerzero.miniplaceholders.api;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.enums.Platform;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
/**
|
||||
* MiniPlaceholders
|
||||
*
|
||||
* <p>This class allows you to obtain the {@link TagResolver}
|
||||
* that other plugins provide based on single {@link Audience},
|
||||
* 2-audience or global placeholders</p>
|
||||
*
|
||||
* @author 4drian3d
|
||||
* @see TagResolver
|
||||
* @see Expansion
|
||||
* @since 1.0.0
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the global placeholders
|
||||
*
|
||||
* <pre>TagResolver resolver = MiniPlaceholders.getGlobalPlaceholders();
|
||||
* Component messageParsed = MiniMessage.miniMessage().deserialize({@link String}, resolver);</pre>
|
||||
*
|
||||
* @return global placeholders independient of any audience
|
||||
* @see TagResolver
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the TagResolver based on an Audience
|
||||
*
|
||||
* <pre>TagResolver resolver = MiniPlaceholders.getAudiencePlaceholders({@link Audience});
|
||||
* Component messageParsed = MiniMessage.miniMessage().deserialize({@link String}, resolver);</pre>
|
||||
*
|
||||
* @param audience the audience
|
||||
* @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();
|
||||
|
||||
Objects.requireNonNull(audience, () -> "audience cannot be null");
|
||||
|
||||
TagResolver.Builder resolvers = TagResolver.builder();
|
||||
expansions.forEach(exp -> resolvers.resolver(exp.audiencePlaceholders(audience)));
|
||||
|
||||
return resolvers.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relationals placeholders based on two audiences
|
||||
*
|
||||
* <pre>TagResolver resolver = MiniPlaceholders.getRelationalPlaceholders({@link Audience}, {@link Audience});
|
||||
* Component messageParsed = MiniMessage.miniMessage().deserialize({@link String}, resolver);</pre>
|
||||
*
|
||||
* @param audience an audience
|
||||
* @param otherAudience another audience
|
||||
* @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();
|
||||
|
||||
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)));
|
||||
|
||||
return resolvers.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ammount of expansion registered
|
||||
* @return the ammount of expansions registered
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static int getExpansionCount(){
|
||||
return expansions.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the platform
|
||||
* @param platform the platform
|
||||
* @deprecated dont use this, INTERNAL
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Deprecated(forRemoval = false)
|
||||
@org.jetbrains.annotations.ApiStatus.Internal
|
||||
public static void setPlatform(Platform platform){
|
||||
if(placeholdersPlatform != null) throw new RuntimeException("Cannot set platform twice");
|
||||
placeholdersPlatform = platform;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
/**Plugin enums */
|
||||
package me.dreamerzero.miniplaceholders.api.enums;
|
||||
@@ -1,4 +0,0 @@
|
||||
/**
|
||||
* MiniPlaceholders core package
|
||||
*/
|
||||
package me.dreamerzero.miniplaceholders.api;
|
||||
@@ -1,39 +0,0 @@
|
||||
package me.dreamerzero.miniplaceholders.api.utils;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Legacy utils
|
||||
*/
|
||||
public final class LegacyUtils {
|
||||
private LegacyUtils(){}
|
||||
|
||||
/**
|
||||
* Parse a string with possible legacy symbols
|
||||
* @param string the string
|
||||
* @return a parsed string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
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)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
return MiniMessage.miniMessage()
|
||||
.deserialize(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package me.dreamerzero.miniplaceholders.api.utils;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
|
||||
/**Tags utils */
|
||||
public final class TagsUtils {
|
||||
private TagsUtils(){}
|
||||
|
||||
/**Empty Tag */
|
||||
public static final Tag EMPTY_TAG = Tag.selfClosingInserting(Component.empty());
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/** MiniPlaceholders API Module */
|
||||
open module io.github.miniplaceholders.api {
|
||||
requires net.kyori.adventure;
|
||||
requires net.kyori.adventure.text.minimessage;
|
||||
requires net.kyori.examination.api;
|
||||
requires static org.jetbrains.annotations;
|
||||
requires io.github.miniplaceholders.connect;
|
||||
requires net.kyori.adventure.text.serializer.legacy;
|
||||
|
||||
exports io.github.miniplaceholders.api;
|
||||
exports io.github.miniplaceholders.api.enums;
|
||||
exports io.github.miniplaceholders.api.utils;
|
||||
exports io.github.miniplaceholders.api.placeholder;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.github.miniplaceholders.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.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 io.github.miniplaceholders.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.miniplaceholders.api.MiniPlaceholders;
|
||||
import io.github.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()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -1,13 +1,13 @@
|
||||
package me.dreamerzero.miniplaceholders;
|
||||
package io.github.miniplaceholders.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.github.miniplaceholders.test.testobjects.TestAudience;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.Expansion;
|
||||
import me.dreamerzero.miniplaceholders.api.MiniPlaceholders;
|
||||
import me.dreamerzero.miniplaceholders.testobjects.TestAudience;
|
||||
import io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.miniplaceholders.api.MiniPlaceholders;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
@@ -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")
|
||||
@@ -23,7 +23,7 @@ public class PlaceholderTest {
|
||||
TestAudience player = new TestAudience("4drian3d");
|
||||
|
||||
Expansion expansion = Expansion.builder("example")
|
||||
.audiencePlaceholder("name", (aud, queue, ctx) -> Tag.selfClosingInserting(Component.text(((TestAudience)aud).getName()))).build();
|
||||
.audiencePlaceholder("name", (aud, queue, ctx) -> Tag.selfClosingInserting(Component.text(((TestAudience)aud).name()))).build();
|
||||
|
||||
final Component expected = Component.text("Player Name: 4drian3d");
|
||||
final Component result = MiniMessage.miniMessage().deserialize("Player Name: <example_name>", expansion.audiencePlaceholders(player));
|
||||
@@ -80,7 +80,7 @@ public class PlaceholderTest {
|
||||
@DisplayName("Filtered Expansion")
|
||||
void filteredExpansion(){
|
||||
Expansion expansion = Expansion.builder("filter")
|
||||
.audiencePlaceholder("name", (aud, queue, ctx) -> Tag.selfClosingInserting(Component.text(((TestAudience)aud).getName())))
|
||||
.audiencePlaceholder("name", (aud, queue, ctx) -> Tag.selfClosingInserting(Component.text(((TestAudience)aud).name())))
|
||||
.filter(TestAudience.class)
|
||||
.build();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -106,7 +106,7 @@ public class PlaceholderTest {
|
||||
}
|
||||
|
||||
private boolean isEnemy(TestAudience a1, TestAudience a2){
|
||||
return a1.getName().equals("PlayerOne") && a2.getName().equals("PlayerTwo");
|
||||
return a1.name().equals("PlayerOne") && a2.name().equals("PlayerTwo");
|
||||
}
|
||||
|
||||
}
|
||||
+13
-6
@@ -1,16 +1,23 @@
|
||||
package me.dreamerzero.miniplaceholders;
|
||||
package io.github.miniplaceholders.test;
|
||||
|
||||
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 io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.miniplaceholders.api.MiniPlaceholders;
|
||||
import io.github.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 {
|
||||
//yea... it is intended xd
|
||||
@SuppressWarnings("DataFlowIssue")
|
||||
class ThrowableTest {
|
||||
@Test
|
||||
@DisplayName("Nullable Exception")
|
||||
void throwOnNull(){
|
||||
@@ -19,7 +26,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)
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.github.miniplaceholders.test.testobjects;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
|
||||
public record TestAudience(@NotNull String name) implements Audience {}
|
||||
@@ -1,16 +0,0 @@
|
||||
package me.dreamerzero.miniplaceholders.testobjects;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
|
||||
public final class TestAudience implements Audience {
|
||||
private final String name;
|
||||
public TestAudience(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public @NotNull String getName(){
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.plugin.shadow)
|
||||
implementation(libs.plugin.kotlin)
|
||||
implementation(libs.plugin.dokka)
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
rootProject.name = "build-logic"
|
||||
|
||||
dependencyResolutionManagement {
|
||||
@Suppress("UnstableApiUsage")
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
versionCatalogs {
|
||||
register("libs") {
|
||||
from(files("../gradle/libs.versions.toml"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
signing
|
||||
id("org.jetbrains.dokka")
|
||||
}
|
||||
/*
|
||||
val dokkaHtmlJar = tasks.register<Jar>("dokkaHtmlJar") {
|
||||
dependsOn(tasks.dokkaHtml)
|
||||
from(tasks.dokkaHtml.flatMap { it.outputDirectory })
|
||||
archiveClassifier.set("javadoc")
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
artifact(tasks["dokkaHtmlJar"])
|
||||
repositories {
|
||||
maven {
|
||||
credentials(PasswordCredentials::class)
|
||||
val central = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
val snapshots = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
|
||||
|
||||
if (project.version.toString().endsWith("SNAPSHOT")) {
|
||||
name = "SonatypeSnapshots"
|
||||
setUrl(snapshots)
|
||||
} else {
|
||||
name = "OSSRH"
|
||||
setUrl(central)
|
||||
}
|
||||
}
|
||||
}
|
||||
from(components["java"])
|
||||
pom {
|
||||
url.set("https://github.com/MiniPlaceholders/MiniPlaceholders")
|
||||
licenses {
|
||||
license {
|
||||
name.set("GNU General Public License version 3 or later")
|
||||
url.set("https://opensource.org/licenses/GPL-3.0")
|
||||
}
|
||||
}
|
||||
scm {
|
||||
connection.set("scm:git:https://github.com/MiniPlaceholders/MiniPlaceholders.git")
|
||||
developerConnection.set("scm:git:ssh://git@github.com/MiniPlaceholders/MiniPlaceholders.git")
|
||||
url.set("https://github.com/MiniPlaceholders/MiniPlaceholders")
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id.set("4drian3d")
|
||||
name.set("Adrian Gonzales")
|
||||
email.set("adriangonzalesval@gmail.com")
|
||||
}
|
||||
}
|
||||
issueManagement {
|
||||
name.set("GitHub")
|
||||
url.set("https://github.com/MiniPlaceholders/MiniPlaceholders/issues")
|
||||
}
|
||||
ciManagement {
|
||||
name.set("GitHub Actions")
|
||||
url.set("https://github.com/MiniPlaceholders/MiniPlaceholders/actions")
|
||||
}
|
||||
name.set(project.name)
|
||||
description.set(project.description)
|
||||
url.set("https://github.com/MiniPlaceholders/MiniPlaceholders")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
useGpgCmd()
|
||||
sign(configurations.archives.get())
|
||||
sign(publishing.publications["maven"])
|
||||
sign(tasks["dokkaHtmlJar"])
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}*/
|
||||
@@ -0,0 +1,71 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
signing
|
||||
}
|
||||
/*
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
repositories {
|
||||
maven {
|
||||
credentials(PasswordCredentials::class)
|
||||
val central = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
val snapshots = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
|
||||
|
||||
if (project.version.toString().endsWith("SNAPSHOT")) {
|
||||
name = "SonatypeSnapshots"
|
||||
setUrl(snapshots)
|
||||
} else {
|
||||
name = "OSSRH"
|
||||
setUrl(central)
|
||||
}
|
||||
}
|
||||
}
|
||||
from(components["java"])
|
||||
pom {
|
||||
url.set("https://github.com/MiniPlaceholders/MiniPlaceholders")
|
||||
licenses {
|
||||
license {
|
||||
name.set("GNU General Public License version 3 or later")
|
||||
url.set("https://opensource.org/licenses/GPL-3.0")
|
||||
}
|
||||
}
|
||||
scm {
|
||||
connection.set("scm:git:https://github.com/MiniPlaceholders/MiniPlaceholders.git")
|
||||
developerConnection.set("scm:git:ssh://git@github.com/MiniPlaceholders/MiniPlaceholders.git")
|
||||
url.set("https://github.com/MiniPlaceholders/MiniPlaceholders")
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id.set("4drian3d")
|
||||
name.set("Adrian Gonzales")
|
||||
email.set("adriangonzalesval@gmail.com")
|
||||
}
|
||||
}
|
||||
issueManagement {
|
||||
name.set("GitHub")
|
||||
url.set("https://github.com/MiniPlaceholders/MiniPlaceholders/issues")
|
||||
}
|
||||
ciManagement {
|
||||
name.set("GitHub Actions")
|
||||
url.set("https://github.com/MiniPlaceholders/MiniPlaceholders/actions")
|
||||
}
|
||||
name.set(project.name)
|
||||
description.set(project.description)
|
||||
url.set("https://github.com/MiniPlaceholders/MiniPlaceholders")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
useGpgCmd()
|
||||
sign(configurations.archives.get())
|
||||
sign(publishing.publications["maven"])
|
||||
|
||||
}*/
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
+7
-13
@@ -1,22 +1,17 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
plugins {
|
||||
java
|
||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||
alias(libs.plugins.shadow)
|
||||
kotlin("jvm") version "1.8.20" apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "java")
|
||||
group = "me.dreamerzero.miniplaceholders"
|
||||
version = "1.0.1"
|
||||
description = "MiniPlaceholders"
|
||||
apply<JavaPlugin>()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
shadow(project(":miniplaceholders-api"))
|
||||
shadow(project(":miniplaceholders-common"))
|
||||
shadow(project(":miniplaceholders-velocity"))
|
||||
shadow(project(":miniplaceholders-paper", "reobf"))
|
||||
implementation(projects.miniplaceholdersVelocity)
|
||||
implementation(project(":miniplaceholders-paper", "reobf"))
|
||||
implementation(projects.miniplaceholdersKrypton)
|
||||
}
|
||||
|
||||
subprojects {
|
||||
@@ -29,9 +24,8 @@ subprojects {
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
archiveFileName.set("MiniPlaceholders.jar")
|
||||
archiveFileName.set("MiniPlaceholders-${project.version}.jar")
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
configurations = listOf(project.configurations.shadow.get())
|
||||
}
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
|
||||
+20
-10
@@ -1,27 +1,37 @@
|
||||
plugins {
|
||||
id("net.kyori.blossom") version "1.3.0"
|
||||
alias(libs.plugins.blossom)
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://libraries.minecraft.net");
|
||||
maven("https://libraries.minecraft.net") {
|
||||
mavenContent {
|
||||
includeGroup("com.mojang")
|
||||
}
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":miniplaceholders-api"))
|
||||
compileOnly("net.kyori:adventure-api:4.10.1")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.10.1")
|
||||
compileOnly("com.mojang:brigadier:1.0.18")
|
||||
implementation(projects.miniplaceholdersApi)
|
||||
compileOnly(libs.adventure.api)
|
||||
compileOnly(libs.adventure.minimesssage)
|
||||
compileOnly(libs.brigadier)
|
||||
}
|
||||
|
||||
blossom{
|
||||
replaceToken("{version}", version)
|
||||
replaceTokenIn("src/main/java/me/dreamerzero/miniplaceholders/common/PluginConstants.java")
|
||||
replaceToken("{version}", project.version)
|
||||
replaceTokenIn("src/main/java/io/github/miniplaceholders/common/PluginConstants.java")
|
||||
}
|
||||
|
||||
tasks {
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
|
||||
options.release.set(17)
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes("Automatic-Module-Name" to "io.github.miniplaceholders.common")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
package io.github.miniplaceholders.common;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.miniplaceholders.api.MiniPlaceholders;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.builder.AbstractBuilder;
|
||||
import net.kyori.adventure.permission.PermissionChecker;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.*;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static java.util.concurrent.CompletableFuture.supplyAsync;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.RED;
|
||||
import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
|
||||
|
||||
public final class PlaceholdersCommand<A> {
|
||||
private final Supplier<Collection<String>> playersSuggestions;
|
||||
private final Function<String, Audience> toAudience;
|
||||
private final Function<A, Audience> sourceToAudience;
|
||||
private final BiPredicate<A, String> hasPermission;
|
||||
private final Expansion commandExpansion = Expansion.builder("placeholders")
|
||||
.globalPlaceholder("count", (queue, ctx) -> Tag.selfClosingInserting(text(MiniPlaceholders.getExpansionCount())))
|
||||
.globalPlaceholder("version", (queue, ctx) -> Tag.selfClosingInserting(text(PluginConstants.VERSION)))
|
||||
.build();
|
||||
|
||||
private PlaceholdersCommand(
|
||||
final Supplier<Collection<String>> playersSuggestions,
|
||||
final Function<String, Audience> toAudience,
|
||||
final Function<A, Audience> sourceToAudience,
|
||||
final BiPredicate<A, String> hasPermission
|
||||
) {
|
||||
this.playersSuggestions = playersSuggestions;
|
||||
this.toAudience = toAudience;
|
||||
this.sourceToAudience = sourceToAudience;
|
||||
this.hasPermission = hasPermission;
|
||||
}
|
||||
|
||||
private static final Component HEADER = miniMessage()
|
||||
.deserialize("<gradient:aqua:white:aqua>---------- <gradient:#4d8bff:#a4ff96>MiniPlaceholders</gradient> -----------</gradient>");
|
||||
private static final Component FOOTER = miniMessage()
|
||||
.deserialize("<gradient:aqua:white:aqua> --------------- ---------------</gradient>");
|
||||
|
||||
public LiteralArgumentBuilder<A> asBuilder(String commandName){
|
||||
return LiteralArgumentBuilder.<A>literal(commandName)
|
||||
.requires(a -> getAudience(a).pointers().supports(PermissionChecker.POINTER))
|
||||
.executes(cmd -> {
|
||||
Audience source = getAudience(cmd.getSource());
|
||||
if (hasPermission(cmd.getSource(), "miniplaceholders.command")) {
|
||||
source.sendMessage(
|
||||
text()
|
||||
.append(HEADER)
|
||||
.append(Component.newline())
|
||||
.append(miniMessage()
|
||||
.deserialize(
|
||||
"<gradient:aqua:#918fff>Placeholders Available:</gradient> <aqua><placeholders_count></aqua>",
|
||||
commandExpansion.globalPlaceholders()
|
||||
)).append(Component.newline())
|
||||
.append(FOOTER)
|
||||
.build()
|
||||
);
|
||||
} else {
|
||||
source.sendMessage(
|
||||
text()
|
||||
.append(HEADER)
|
||||
.append(Component.newline())
|
||||
.append(miniMessage()
|
||||
.deserialize(
|
||||
"<gradient:#8693AB:#BDD4E7>Version: <placeholders_version>",
|
||||
commandExpansion.globalPlaceholders()
|
||||
)).append(Component.newline())
|
||||
.append(FOOTER)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
return 1;
|
||||
})
|
||||
.then(LiteralArgumentBuilder.<A>literal("help")
|
||||
.requires(src -> hasPermission(src, "miniplaceholders.command.help"))
|
||||
.executes(cmd -> {
|
||||
getAudience(cmd.getSource()).sendMessage(
|
||||
text()
|
||||
.append(HEADER)
|
||||
.append(Component.newline())
|
||||
.append(miniMessage()
|
||||
.deserialize(
|
||||
"<gradient:#9694ff:#5269ff>Commands:</gradient>"))
|
||||
.append(Component.newline())
|
||||
.append(miniMessage()
|
||||
.deserialize(
|
||||
"<gradient:aqua:#94d1ff>/miniplaceholders</gradient> <aqua>help</aqua>"))
|
||||
.append(Component.newline())
|
||||
.append(miniMessage()
|
||||
.deserialize(
|
||||
"<gradient:aqua:#94d1ff>/miniplaceholders</gradient> <aqua>parse</aqua> <#8fadff><player|me></#8fadff> <#99ffb6><player></#99ffb6>"))
|
||||
.append(Component.newline())
|
||||
.append(FOOTER)
|
||||
.build()
|
||||
);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
.then(LiteralArgumentBuilder.<A>literal("parse")
|
||||
.requires(cmd -> hasPermission(cmd, "miniplaceholders.command.parse"))
|
||||
.then(LiteralArgumentBuilder.<A>literal("me")
|
||||
.then(RequiredArgumentBuilder.<A, String>argument("string", string())
|
||||
.executes(cmd -> {
|
||||
final String toParse = getString(cmd, "string");
|
||||
final Component parsed = parseGlobal(toParse, getAudience(cmd.getSource()));
|
||||
getAudience(cmd.getSource()).sendMessage(parsed);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
)
|
||||
.then(LiteralArgumentBuilder.<A>literal("player")
|
||||
.then(RequiredArgumentBuilder.<A, String>argument("source", word())
|
||||
.suggests((argument, builder) -> supplyAsync(() -> {
|
||||
playersSuggestions.get().forEach(builder::suggest);
|
||||
return builder.build();
|
||||
}))
|
||||
.then(RequiredArgumentBuilder.<A, String>argument("string", string())
|
||||
.executes(cmd -> {
|
||||
final Audience objective = toAudience.apply(getString(cmd, "source"));
|
||||
if (objective == null){
|
||||
getAudience(cmd.getSource()).sendMessage(text("You must specify a valid player", RED));
|
||||
return -1;
|
||||
}
|
||||
final String toParse = cmd.getArgument("string", String.class);
|
||||
|
||||
final Component parsed = parseGlobal(toParse, objective);
|
||||
getAudience(cmd.getSource()).sendMessage(parsed);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public LiteralCommandNode<A> asNode(String command) {
|
||||
return asBuilder(command).build();
|
||||
}
|
||||
|
||||
private Component parseGlobal(final String string, final Audience audience) {
|
||||
return miniMessage().deserialize(
|
||||
string,
|
||||
TagResolver.resolver(
|
||||
MiniPlaceholders.getGlobalPlaceholders(),
|
||||
MiniPlaceholders.getAudiencePlaceholders(audience)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private Audience getAudience(final A possibleAudience) {
|
||||
if (possibleAudience instanceof Audience audience){
|
||||
return audience;
|
||||
}
|
||||
final Audience audience = sourceToAudience.apply(possibleAudience);
|
||||
return audience != null ? audience : Audience.empty();
|
||||
}
|
||||
|
||||
private boolean hasPermission(final A source, final String permission) {
|
||||
if (hasPermission != null) {
|
||||
return hasPermission.test(source, permission);
|
||||
}
|
||||
return getAudience(source)
|
||||
.get(PermissionChecker.POINTER)
|
||||
.map(checker -> checker.test(permission))
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
public static <A> Builder<A> builder() {
|
||||
return new Builder<>();
|
||||
}
|
||||
|
||||
public final static class Builder<A> implements AbstractBuilder<PlaceholdersCommand<A>> {
|
||||
private Supplier<Collection<String>> playersSuggestions;
|
||||
private Function<String, Audience> toAudience;
|
||||
private Function<A, Audience> fromAToAudience = a -> Audience.empty();
|
||||
private BiPredicate<A, String> hasPermission;
|
||||
|
||||
private Builder() {}
|
||||
|
||||
public Builder<A> playerSuggestions(final Supplier<@NotNull Collection<@NotNull String>> playersSuggestions) {
|
||||
this.playersSuggestions = playersSuggestions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<A> toAudience(final @NotNull Function<@NotNull String, @Nullable Audience> argumentToAudience) {
|
||||
this.toAudience = argumentToAudience;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<A> fromSourceToAudience(final @NotNull Function<@NotNull A, @Nullable Audience> sourceToAudience) {
|
||||
this.fromAToAudience = sourceToAudience;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<A> hasPermissionCheck(final @NotNull BiPredicate<@NotNull A, @NotNull String> hasPermission) {
|
||||
this.hasPermission = hasPermission;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PlaceholdersCommand<A> build() {
|
||||
return new PlaceholdersCommand<>(
|
||||
requireNonNull(playersSuggestions),
|
||||
requireNonNull(toAudience),
|
||||
requireNonNull(fromAToAudience),
|
||||
hasPermission
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.dreamerzero.miniplaceholders.common;
|
||||
package io.github.miniplaceholders.common;
|
||||
|
||||
public interface PlaceholdersPlugin {
|
||||
void loadDefaultExpansions();
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.dreamerzero.miniplaceholders.common;
|
||||
package io.github.miniplaceholders.common;
|
||||
|
||||
public final class PluginConstants {
|
||||
public static final String VERSION = "{version}";
|
||||
@@ -1,143 +0,0 @@
|
||||
package me.dreamerzero.miniplaceholders.common;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.Expansion;
|
||||
import me.dreamerzero.miniplaceholders.api.MiniPlaceholders;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.permission.PermissionChecker;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
|
||||
|
||||
public class PlaceholdersCommand<A> {
|
||||
private final @NotNull Supplier<@NotNull Collection<@NotNull String>> playersSuggestions;
|
||||
private final @NotNull Function<@NotNull String, @Nullable Audience> toAudience;
|
||||
private Function<A, Audience> fromAToAudience = a -> Audience.empty();
|
||||
private final Expansion commandExpansion = Expansion.builder("placeholders")
|
||||
.globalPlaceholder("count", (queue, ctx) -> Tag.selfClosingInserting(Component.text(MiniPlaceholders.getExpansionCount())))
|
||||
.globalPlaceholder("version", (queue, ctx) -> Tag.selfClosingInserting(Component.text(PluginConstants.VERSION)))
|
||||
.build();
|
||||
|
||||
public PlaceholdersCommand(Supplier<Collection<String>> playersSuggestions, Function<@NotNull String, @Nullable Audience> toAudience){
|
||||
this.playersSuggestions = playersSuggestions;
|
||||
this.toAudience = toAudience;
|
||||
}
|
||||
|
||||
public PlaceholdersCommand(Supplier<Collection<String>> playersSuggestions, Function<@NotNull String, @Nullable Audience> toAudience, Function<A, Audience> fromAToAudience){
|
||||
this(playersSuggestions, toAudience);
|
||||
this.fromAToAudience = fromAToAudience;
|
||||
}
|
||||
|
||||
private static final Component HEADER = miniMessage().deserialize("<gradient:aqua:white:aqua>---------- <gradient:#4d8bff:#a4ff96>MiniPlaceholders</gradient> -----------</gradient>");
|
||||
private static final Component FOOTER = miniMessage().deserialize("<gradient:aqua:white:aqua> --------------- ---------------</gradient>");
|
||||
|
||||
public LiteralArgumentBuilder<A> placeholderTestBuilder(String commandName){
|
||||
return LiteralArgumentBuilder.<A>literal(commandName)
|
||||
.requires(a -> getAudience(a).pointers().supports(PermissionChecker.POINTER))
|
||||
.executes(cmd -> {
|
||||
Audience source = getAudience(cmd.getSource());
|
||||
if(source.pointers().get(PermissionChecker.POINTER).orElse(null).test("miniplaceholders.command")){
|
||||
source.sendMessage(
|
||||
Component.text()
|
||||
.append(HEADER).append(Component.newline())
|
||||
.append(miniMessage().deserialize("<gradient:aqua:#918fff>Placeholders Available:</gradient> <aqua><placeholders_count></aqua>", commandExpansion.globalPlaceholders())).append(Component.newline())
|
||||
.append(FOOTER)
|
||||
.build()
|
||||
);
|
||||
} else {
|
||||
source.sendMessage(
|
||||
Component.text()
|
||||
.append(HEADER).append(Component.newline())
|
||||
.append(miniMessage().deserialize("<gradient:red:dark_red>Version: <placeholders_version>", commandExpansion.globalPlaceholders())).append(Component.newline())
|
||||
.append(FOOTER)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
return 1;
|
||||
})
|
||||
.then(LiteralArgumentBuilder.<A>literal("help")
|
||||
.executes(cmd -> {
|
||||
getAudience(cmd.getSource()).sendMessage(
|
||||
Component.text()
|
||||
.append(HEADER).append(Component.newline())
|
||||
.append(miniMessage().deserialize("<gradient:#9694ff:#5269ff>Commands:</gradient>")).append(Component.newline())
|
||||
.append(miniMessage().deserialize("<gradient:aqua:#94d1ff>/miniplaceholders</gradient> <aqua>help</aqua>")).append(Component.newline())
|
||||
.append(miniMessage().deserialize("<gradient:aqua:#94d1ff>/miniplaceholders</gradient> <aqua>parse</aqua> <color:#8fadff><player:me></color> <color:#99ffb6><player></color>")).append(Component.newline())
|
||||
.append(FOOTER)
|
||||
.build()
|
||||
);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
.then(LiteralArgumentBuilder.<A>literal("parse")
|
||||
.then(LiteralArgumentBuilder.<A>literal("me")
|
||||
.then(RequiredArgumentBuilder.<A, String>argument("selfStringToParse", StringArgumentType.string())
|
||||
.executes(cmd -> {
|
||||
String stringToParse = cmd.getArgument("selfStringToParse", String.class);
|
||||
Component parsed = this.parseGlobal(stringToParse, getAudience(cmd.getSource()));
|
||||
getAudience(cmd.getSource()).sendMessage(parsed);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
)
|
||||
.then(LiteralArgumentBuilder.<A>literal("player")
|
||||
.then(RequiredArgumentBuilder.<A, String>argument("source", StringArgumentType.word())
|
||||
.suggests((argument, builder) -> {
|
||||
playersSuggestions.get().forEach(builder::suggest);
|
||||
return builder.buildFuture();
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<A, String>argument("playerStringToParse", StringArgumentType.string())
|
||||
.executes(cmd -> {
|
||||
Audience objetive = toAudience.apply(cmd.getArgument("source", String.class));
|
||||
if(objetive == null){
|
||||
getAudience(cmd.getSource()).sendMessage(Component.text("You must specify a valid player", NamedTextColor.RED));
|
||||
return 1;
|
||||
}
|
||||
String stringToParse = cmd.getArgument("playerStringToParse", String.class);
|
||||
|
||||
Component parsed = this.parseGlobal(stringToParse, objetive);
|
||||
getAudience(cmd.getSource()).sendMessage(parsed);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public LiteralCommandNode<A> placeholderTestCommand(String command){
|
||||
return this.placeholderTestBuilder(command).build();
|
||||
}
|
||||
|
||||
private Component parseGlobal(String string, Audience audience){
|
||||
return miniMessage().deserialize(
|
||||
string,
|
||||
TagResolver.resolver(
|
||||
MiniPlaceholders.getGlobalPlaceholders(),
|
||||
MiniPlaceholders.getAudiencePlaceholders(audience)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private Audience getAudience(A possibleAudience){
|
||||
if(possibleAudience instanceof Audience audience){
|
||||
return audience;
|
||||
}
|
||||
Audience audience = fromAToAudience.apply(possibleAudience);
|
||||
return audience != null ? audience : Audience.empty();
|
||||
}
|
||||
}
|
||||
@@ -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 io.github.miniplaceholders.connect;
|
||||
|
||||
public enum InternalPlatform {
|
||||
|
||||
PAPER, VELOCITY, KRYPTON;
|
||||
|
||||
private static InternalPlatform actualPlatform;
|
||||
|
||||
public static void platform(final InternalPlatform platform){
|
||||
InternalPlatform.actualPlatform = platform;
|
||||
}
|
||||
|
||||
public static InternalPlatform platform(){
|
||||
return InternalPlatform.actualPlatform;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module io.github.miniplaceholders.connect {
|
||||
exports io.github.miniplaceholders.connect;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
group = io.github.miniplaceholders
|
||||
version = 2.0.2
|
||||
description = MiniMessage Component-based Placeholders for PaperMC, Krypton and Velocity platforms
|
||||
@@ -0,0 +1,51 @@
|
||||
metadata.format.version = "1.1"
|
||||
|
||||
[versions]
|
||||
|
||||
velocity = "3.2.0-SNAPSHOT"
|
||||
paper = "1.19.4-R0.1-SNAPSHOT"
|
||||
krypton = "7f7a457cdf"
|
||||
|
||||
runtask = "2.0.1"
|
||||
pluginyml = "0.5.3"
|
||||
userdev = "1.5.4"
|
||||
blossom = "1.3.1"
|
||||
indra = "3.0.1"
|
||||
shadow = "8.1.1"
|
||||
jmh = "0.7.0"
|
||||
dokka = "1.8.10"
|
||||
|
||||
adventure = "4.13.1"
|
||||
brigadier = "1.0.500"
|
||||
kotlin="1.8.20"
|
||||
|
||||
|
||||
[libraries]
|
||||
|
||||
velocity = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" }
|
||||
paper = { group = "io.papermc.paper", name = "paper-api", version.ref = "paper" }
|
||||
krypton-server = { group = "org.kryptonmc", name = "krypton-server", version.ref = "krypton" }
|
||||
|
||||
adventure-api = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" }
|
||||
adventure-minimesssage = { group = "net.kyori", name = "adventure-text-minimessage", version.ref = "adventure" }
|
||||
|
||||
brigadier = { group = "com.mojang", name = "brigadier", version.ref = "brigadier" }
|
||||
|
||||
krypton-annotation = { group = "org.kryptonmc", name = "krypton-annotation-processor", version.ref = "krypton" }
|
||||
|
||||
plugin-shadow = { group = "com.github.johnrengelman", name = "shadow", version.ref = "shadow" }
|
||||
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
||||
plugin-indra-common = { module = "net.kyori:indra-common", version.ref = "indra" }
|
||||
plugin-indra-spotless = { module = "net.kyori:indra-licenser-spotless", version.ref = "indra" }
|
||||
plugin-dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.8.10"
|
||||
|
||||
[plugins]
|
||||
|
||||
pluginyml = { id = "net.minecrell.plugin-yml.bukkit", version.ref = "pluginyml" }
|
||||
userdev = { id = "io.papermc.paperweight.userdev", version.ref = "userdev" }
|
||||
runpaper = { id = "xyz.jpenilla.run-paper", version.ref = "runtask" }
|
||||
runvelocity = { id = "xyz.jpenilla.run-velocity", version.ref = "runtask" }
|
||||
blossom = { id = "net.kyori.blossom", version.ref = "blossom" }
|
||||
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
|
||||
jmh = { id = "me.champeau.jmh", version.ref = "jmh" }
|
||||
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
|
||||
Vendored
BIN
Binary file not shown.
+2
-1
@@ -1,5 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
|
||||
networkTimeout=10000
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -32,10 +32,10 @@
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
@@ -55,7 +55,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -80,10 +80,10 @@ do
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
@@ -143,12 +143,16 @@ fi
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@@ -205,6 +209,12 @@ set -- \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
|
||||
Vendored
+92
-89
@@ -1,89 +1,92 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("miniplaceholders.kotlin.publish")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(kotlin("stdlib"))
|
||||
compileOnly(libs.adventure.api)
|
||||
compileOnly(libs.adventure.minimesssage)
|
||||
compileOnlyApi(projects.miniplaceholdersApi)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
explicitApi()
|
||||
jvmToolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package io.github.miniplaceholders.kotlin
|
||||
|
||||
import io.github.miniplaceholders.api.Expansion
|
||||
|
||||
/**
|
||||
* Create a new Expansion
|
||||
*
|
||||
* @param name the expansion name
|
||||
* @param builder a builder-like function to create an Expansion from a builder
|
||||
* @return a new expansion
|
||||
* @since 1.4.0
|
||||
* @see Expansion.builder
|
||||
* @see Expansion.Builder.build
|
||||
* */
|
||||
public fun expansion(name: String, builder: Expansion.Builder.() -> Expansion.Builder): Expansion
|
||||
= builder(Expansion.builder(name)).build()
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.github.miniplaceholders.kotlin
|
||||
|
||||
import net.kyori.adventure.text.ComponentLike
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag
|
||||
|
||||
/**
|
||||
* Converts a [ComponentLike] to a [Tag] of type selfClosingInserting
|
||||
*
|
||||
* @see Tag.selfClosingInserting
|
||||
*/
|
||||
public fun ComponentLike.asClosingTag(): Tag = Tag.selfClosingInserting(this)
|
||||
|
||||
/**
|
||||
* Converts a [ComponentLike] to a [Tag] of type inserting
|
||||
*
|
||||
* @see Tag.inserting
|
||||
*/
|
||||
public fun ComponentLike.asInsertingTag(): Tag = Tag.inserting(this)
|
||||
|
||||
/**
|
||||
* Converts a [ComponentLike] to a [Tag] of type preProcessParsed
|
||||
*
|
||||
* @see Tag.preProcessParsed
|
||||
*/
|
||||
public fun String.asPreProcessTag(): Tag = Tag.preProcessParsed(this)
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.github.miniplaceholders.kotlin
|
||||
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
|
||||
|
||||
/**
|
||||
* Check if this TagResolver is an instance of TagResolver.empty(),
|
||||
* that is, it will always return null
|
||||
* @return true if the TagResolver is the same as TagResolver.empty(), else false
|
||||
* @since 1.4.0
|
||||
* @see TagResolver.empty
|
||||
*/
|
||||
public fun TagResolver.isEmpty(): Boolean = this == TagResolver.empty()
|
||||
|
||||
/**
|
||||
* Checks if this TagResolver is not a TagResolver.empty()
|
||||
* @return false if the TagResolver is the same as TagResolver.empty(), else true
|
||||
* @since 1.4.0
|
||||
* @see TagResolver.empty
|
||||
*/
|
||||
public fun TagResolver.isNotEmpty(): Boolean = this != TagResolver.empty()
|
||||
|
||||
/**
|
||||
* Applies a TagResolver to a TagResolver.Builder in case it is not a TagResolver.empty()
|
||||
* @param resolver the resolver to check
|
||||
* @since 1.4.0
|
||||
* @see TagResolver.isNotEmpty
|
||||
*/
|
||||
public fun TagResolver.Builder.applyIfNotEmpty(resolver: TagResolver) {
|
||||
if (resolver.isNotEmpty()) {
|
||||
resolver(resolver)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
kotlin("kapt")
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://repo.kryptonmc.org/releases")
|
||||
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
|
||||
maven("https://repo.kryptonmc.org/snapshots")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.krypton.server)
|
||||
compileOnly(kotlin("stdlib"))
|
||||
kapt(libs.krypton.annotation)
|
||||
implementation(projects.miniplaceholdersCommon)
|
||||
implementation(projects.miniplaceholdersApi)
|
||||
implementation(projects.miniplaceholdersConnect)
|
||||
implementation(projects.miniplaceholdersKotlinExt)
|
||||
}
|
||||
|
||||
tasks {
|
||||
compileKotlin {
|
||||
kotlinOptions.jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package io.github.miniplaceholders.krypton
|
||||
|
||||
import com.google.inject.Inject
|
||||
import io.github.miniplaceholders.api.utils.TagsUtils
|
||||
import io.github.miniplaceholders.common.PlaceholdersCommand
|
||||
import io.github.miniplaceholders.common.PlaceholdersPlugin
|
||||
import io.github.miniplaceholders.common.PluginConstants
|
||||
import io.github.miniplaceholders.connect.InternalPlatform
|
||||
import io.github.miniplaceholders.kotlin.asClosingTag
|
||||
import io.github.miniplaceholders.kotlin.expansion
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.apache.logging.log4j.Logger
|
||||
import org.kryptonmc.api.command.BrigadierCommand
|
||||
import org.kryptonmc.api.command.CommandExecutionContext
|
||||
import org.kryptonmc.api.event.Listener
|
||||
import org.kryptonmc.api.event.server.ServerStartEvent
|
||||
import org.kryptonmc.api.plugin.annotation.Plugin
|
||||
import org.kryptonmc.krypton.KryptonServer
|
||||
import org.kryptonmc.krypton.command.KryptonCommandMeta
|
||||
|
||||
@Plugin(
|
||||
name = "MiniPlaceholders",
|
||||
id = "miniplaceholders",
|
||||
version = PluginConstants.VERSION,
|
||||
authors = ["4drian3d"]
|
||||
)
|
||||
class KotlinKryptonPlugin @Inject constructor(
|
||||
private val server: KryptonServer,
|
||||
private val logger: Logger
|
||||
) : PlaceholdersPlugin {
|
||||
|
||||
init {
|
||||
InternalPlatform.platform(InternalPlatform.KRYPTON)
|
||||
}
|
||||
|
||||
@Listener
|
||||
@Suppress("UNUSED")
|
||||
fun onServerStart(event: ServerStartEvent) {
|
||||
logger.info("Starting MiniPlaceholders Krypton")
|
||||
this.loadDefaultExpansions()
|
||||
this.registerPlatformCommand()
|
||||
}
|
||||
|
||||
override fun loadDefaultExpansions() {
|
||||
expansion("server") {
|
||||
globalPlaceholder("total_entities") { _, _ ->
|
||||
var entityCount = 0
|
||||
for ((_, value) in server.worldManager.worlds) {
|
||||
entityCount += value.entities.size
|
||||
}
|
||||
Component.text(entityCount).asClosingTag()
|
||||
}
|
||||
globalPlaceholder("total_chunks") { _, _ ->
|
||||
var chunkCount = 0
|
||||
for ((_, value) in server.worldManager.worlds) {
|
||||
chunkCount += value.chunks.size
|
||||
}
|
||||
Component.text(chunkCount).asClosingTag()
|
||||
}
|
||||
globalPlaceholder("name", TagsUtils.staticTag(server.platform.name))
|
||||
globalPlaceholder("online") { queue, _ ->
|
||||
if (queue.hasNext()) {
|
||||
val worldName = queue.pop().value()
|
||||
val players = server.players.filter { it.world.name == worldName }
|
||||
|
||||
return@globalPlaceholder Component.text(players.joinToString(", ")).asClosingTag()
|
||||
}
|
||||
Component.text(server.players.size).asClosingTag()
|
||||
}
|
||||
globalPlaceholder("version", TagsUtils.staticTag(server.platform.version))
|
||||
globalPlaceholder("max_players", Component.text(server.config.maxPlayers).asClosingTag())
|
||||
}.register()
|
||||
}
|
||||
|
||||
override fun registerPlatformCommand() {
|
||||
val command = PlaceholdersCommand.builder<CommandExecutionContext>()
|
||||
.fromSourceToAudience { it.sender }
|
||||
.playerSuggestions { server.players.map { it.name } }
|
||||
.toAudience { server.getPlayer(it) }
|
||||
.build()
|
||||
val brigadierCMD = BrigadierCommand.of(command.asNode("miniplaceholders"))
|
||||
val meta = KryptonCommandMeta.Builder("miniplaceholders").build()
|
||||
server.commandManager.register(brigadierCMD, meta)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# run-paper files
|
||||
/run
|
||||
+20
-17
@@ -1,24 +1,14 @@
|
||||
plugins {
|
||||
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
|
||||
id("io.papermc.paperweight.userdev") version "1.3.5"
|
||||
id("xyz.jpenilla.run-paper") version "1.0.6"
|
||||
alias(libs.plugins.userdev)
|
||||
alias(libs.plugins.runpaper)
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":miniplaceholders-common"))
|
||||
compileOnly(project(":miniplaceholders-api"))
|
||||
paperDevBundle("1.18.2-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
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
|
||||
paperweight.paperDevBundle(libs.versions.paper.get())
|
||||
implementation(projects.miniplaceholdersCommon)
|
||||
implementation(projects.miniplaceholdersApi)
|
||||
implementation(projects.miniplaceholdersConnect)
|
||||
}
|
||||
|
||||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
@@ -32,5 +22,18 @@ tasks {
|
||||
|
||||
options.release.set(17)
|
||||
}
|
||||
runServer {
|
||||
minecraftVersion("1.19.4")
|
||||
}
|
||||
jar {
|
||||
manifest {
|
||||
attributes("Automatic-Module-Name" to "io.github.miniplaceholders.paper")
|
||||
}
|
||||
}
|
||||
processResources {
|
||||
filesMatching("paper-plugin.yml") {
|
||||
expand("version" to project.version)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package io.github.miniplaceholders.paper;
|
||||
|
||||
import io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.miniplaceholders.api.utils.TagsUtils;
|
||||
import io.github.miniplaceholders.common.PlaceholdersCommand;
|
||||
import io.github.miniplaceholders.common.PlaceholdersPlugin;
|
||||
import io.github.miniplaceholders.connect.InternalPlatform;
|
||||
import io.papermc.paper.datapack.Datapack;
|
||||
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;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin {
|
||||
private static final DecimalFormat TPS_FORMAT = new DecimalFormat("###.##");
|
||||
private static final DecimalFormat MSPT_FORMAT = new DecimalFormat("###.###");
|
||||
|
||||
static {
|
||||
InternalPlatform.platform(InternalPlatform.PAPER);
|
||||
TPS_FORMAT.setRoundingMode(RoundingMode.HALF_UP);
|
||||
MSPT_FORMAT.setRoundingMode(RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable(){
|
||||
this.getSLF4JLogger().info("Starting MiniPlaceholders Paper");
|
||||
this.loadDefaultExpansions();
|
||||
this.registerPlatformCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDefaultExpansions() {
|
||||
Expansion.builder("server")
|
||||
.globalPlaceholder("name", TagsUtils.staticTag(Component.text(this.getServer().getName())))
|
||||
.globalPlaceholder("online", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().getOnlinePlayers().size())))
|
||||
.globalPlaceholder("version", TagsUtils.staticTag(this.getServer().getVersion()))
|
||||
.globalPlaceholder("max_players", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().getMaxPlayers())))
|
||||
.globalPlaceholder("unique_joins", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().getOfflinePlayers().length)))
|
||||
.globalPlaceholder("tps_1", (queue, ctx) -> TagsUtils.staticTag(TPS_FORMAT.format(this.getServer().getTPS()[0])))
|
||||
.globalPlaceholder("tps_5", (queue, ctx) -> TagsUtils.staticTag(TPS_FORMAT.format(this.getServer().getTPS()[1])))
|
||||
.globalPlaceholder("tps_15", (queue, ctx) -> TagsUtils.staticTag(TPS_FORMAT.format(this.getServer().getTPS()[2])))
|
||||
.globalPlaceholder("has_whitelist", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().hasWhitelist())))
|
||||
.globalPlaceholder("total_chunks", (queue, ctx) -> {
|
||||
int chunkCount = 0;
|
||||
for (World world : this.getServer().getWorlds()){
|
||||
chunkCount += world.getLoadedChunks().length;
|
||||
}
|
||||
return TagsUtils.staticTag(Component.text(chunkCount));
|
||||
})
|
||||
.globalPlaceholder("total_entities", (queue, ctx) -> {
|
||||
int entityCount = 0;
|
||||
for (World world : this.getServer().getWorlds()){
|
||||
entityCount += world.getEntityCount();
|
||||
}
|
||||
return TagsUtils.staticTag(Component.text(entityCount));
|
||||
})
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> TagsUtils.staticTag(MSPT_FORMAT.format(this.getServer().getAverageTickTime())))
|
||||
.globalPlaceholder("datapack_list", (queue, ctx) -> {
|
||||
final TextComponent.Builder builder = Component.text();
|
||||
for (Datapack datapack : this.getServer().getDatapackManager().getEnabledPacks()){
|
||||
builder.append(Component.text("[").append(Component.text(datapack.getName()).append(Component.text("] "))));
|
||||
}
|
||||
return Tag.selfClosingInserting(builder.build());
|
||||
})
|
||||
.globalPlaceholder("datapack_count", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.getServer().getDatapackManager().getEnabledPacks().size())))
|
||||
.build()
|
||||
.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"sonarlint(java:s1874)"})
|
||||
public void registerPlatformCommand() {
|
||||
MinecraftServer.getServer()
|
||||
.getCommands()
|
||||
.getDispatcher()
|
||||
.register(PlaceholdersCommand.<CommandSourceStack>builder()
|
||||
.playerSuggestions(() -> getServer().getOnlinePlayers()
|
||||
.stream()
|
||||
.map(Player::getName)
|
||||
.toList())
|
||||
.toAudience(st -> getServer().getPlayer(st))
|
||||
.hasPermissionCheck((source, permission) -> source.getBukkitSender().hasPermission(permission))
|
||||
.fromSourceToAudience(CommandSourceStack::getBukkitSender)
|
||||
.build()
|
||||
.asBuilder("miniplaceholders")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package me.dreamerzero.miniplaceholders.paper;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
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.common.PlaceholdersCommand;
|
||||
import me.dreamerzero.miniplaceholders.common.PlaceholdersPlugin;
|
||||
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;
|
||||
|
||||
public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin, Listener {
|
||||
private final NumberFormat tpsFormat = NumberFormat.getInstance();
|
||||
private final NumberFormat msptFormat = NumberFormat.getInstance();
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void onEnable(){
|
||||
this.getSLF4JLogger().info("Starting MiniPlaceholders Paper");
|
||||
MiniPlaceholders.setPlatform(Platform.PAPER);
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
|
||||
tpsFormat.setRoundingMode(RoundingMode.DOWN);
|
||||
tpsFormat.setMaximumFractionDigits(2);
|
||||
|
||||
msptFormat.setRoundingMode(RoundingMode.DOWN);
|
||||
msptFormat.setMaximumFractionDigits(3);
|
||||
|
||||
this.loadDefaultExpansions();
|
||||
this.registerPlatformCommand();
|
||||
}
|
||||
|
||||
@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("total_chunks", (queue, ctx) -> {
|
||||
int chunkCount = 0;
|
||||
for(World world : this.getServer().getWorlds()){
|
||||
chunkCount += world.getLoadedChunks().length;
|
||||
}
|
||||
return Tag.selfClosingInserting(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));
|
||||
})
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> Tag.selfClosingInserting(Component.text(msptFormat.format(this.getServer().getAverageTickTime()))))
|
||||
.globalPlaceholder("datapack_list", (queue, ctx) -> {
|
||||
TextComponent.Builder builder = Component.text();
|
||||
for(Datapack datapack : this.getServer().getDatapackManager().getEnabledPacks()){
|
||||
builder.append(Component.text("[").append(Component.text(datapack.getName()).append(Component.text("] "))));
|
||||
}
|
||||
return Tag.selfClosingInserting(builder.build());
|
||||
})
|
||||
.globalPlaceholder("datapack_count", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.getServer().getDatapackManager().getEnabledPacks().size())))
|
||||
.build()
|
||||
.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("all")
|
||||
public void registerPlatformCommand() {
|
||||
this.getCraftServer().getServer()
|
||||
.vanillaCommandDispatcher
|
||||
.getDispatcher()
|
||||
.register(new PlaceholdersCommand<>(
|
||||
() -> this.getServer().getOnlinePlayers().stream().map(Player::getName).toList(),
|
||||
(String st) -> this.getServer().getPlayer(st),
|
||||
CommandSourceStack::getBukkitSender
|
||||
).placeholderTestBuilder("miniplaceholders")
|
||||
);
|
||||
}
|
||||
|
||||
private CraftServer getCraftServer(){
|
||||
return (CraftServer)this.getServer();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
name: MiniPlaceholders
|
||||
version: '${version}'
|
||||
main: io.github.miniplaceholders.paper.PaperPlugin
|
||||
description: MiniMessage Component-based Placeholders for PaperMC, Krypton and Velocity platforms
|
||||
api-version: '1.19'
|
||||
folia-supported: true
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:base"
|
||||
],
|
||||
"ignoreDeps": ["krypton", "krypton-api", "krypton-annotation-processor", "krypton-server"]
|
||||
}
|
||||
+25
-14
@@ -1,18 +1,29 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://papermc.io/repo/repository/maven-public/")
|
||||
}
|
||||
}
|
||||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||
|
||||
rootProject.name = "miniplaceholders-parent"
|
||||
|
||||
include("miniplaceholders-api")
|
||||
include("miniplaceholders-common")
|
||||
include("miniplaceholders-paper")
|
||||
include("miniplaceholders-velocity")
|
||||
pluginManagement {
|
||||
@Suppress("UnstableApiUsage")
|
||||
includeBuild("build-logic")
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
project(":miniplaceholders-api").projectDir = file("api")
|
||||
project(":miniplaceholders-common").projectDir = file("common")
|
||||
project(":miniplaceholders-velocity").projectDir = file("velocity")
|
||||
project(":miniplaceholders-paper").projectDir = file("paper")
|
||||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0"
|
||||
}
|
||||
|
||||
arrayOf(
|
||||
"connect",
|
||||
"api",
|
||||
"kotlin-ext",
|
||||
"common",
|
||||
"paper",
|
||||
"velocity",
|
||||
"krypton"
|
||||
).forEach {
|
||||
include("miniplaceholders-$it")
|
||||
project(":miniplaceholders-$it").projectDir = file(it)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#run velocity files
|
||||
/run
|
||||
@@ -1,14 +1,32 @@
|
||||
plugins {
|
||||
alias(libs.plugins.runvelocity)
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
|
||||
compileOnly(project(":miniplaceholders-common"))
|
||||
compileOnly(project(":miniplaceholders-api"))
|
||||
compileOnly(libs.velocity)
|
||||
annotationProcessor(libs.velocity)
|
||||
implementation(projects.miniplaceholdersCommon)
|
||||
implementation(projects.miniplaceholdersApi)
|
||||
implementation(projects.miniplaceholdersConnect)
|
||||
}
|
||||
|
||||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
|
||||
tasks.compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
tasks {
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
|
||||
options.release.set(17)
|
||||
}
|
||||
options.release.set(17)
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes("Automatic-Module-Name" to "io.github.miniplaceholders.velocity")
|
||||
}
|
||||
}
|
||||
|
||||
runVelocity {
|
||||
velocityVersion(libs.versions.velocity.get())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package io.github.miniplaceholders.velocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.command.BrigadierCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.miniplaceholders.api.utils.Components;
|
||||
import io.github.miniplaceholders.api.utils.TagsUtils;
|
||||
import io.github.miniplaceholders.common.PlaceholdersCommand;
|
||||
import io.github.miniplaceholders.common.PlaceholdersPlugin;
|
||||
import io.github.miniplaceholders.common.PluginConstants;
|
||||
import io.github.miniplaceholders.connect.InternalPlatform;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@Plugin(
|
||||
name = "MiniPlaceholders",
|
||||
id = "miniplaceholders",
|
||||
version = PluginConstants.VERSION,
|
||||
authors = {"4drian3d"}
|
||||
)
|
||||
public final class VelocityPlugin implements PlaceholdersPlugin {
|
||||
private final Logger logger;
|
||||
private final ProxyServer proxy;
|
||||
|
||||
@Inject
|
||||
public VelocityPlugin(final Logger logger, final ProxyServer proxy) {
|
||||
this.logger = logger;
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialize(final ProxyInitializeEvent event) {
|
||||
logger.info("Starting MiniPlaceholders Velocity");
|
||||
|
||||
InternalPlatform.platform(InternalPlatform.VELOCITY);
|
||||
|
||||
this.loadDefaultExpansions();
|
||||
this.registerPlatformCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDefaultExpansions() {
|
||||
Expansion.builder("proxy")
|
||||
.globalPlaceholder("online_players", (queue, ctx) -> {
|
||||
if (queue.hasNext()) {
|
||||
String server = queue.pop().value();
|
||||
return Tag.selfClosingInserting(Component.text(proxy.getServer(server).map(sv -> sv.getPlayersConnected().size()).orElse(0)));
|
||||
}
|
||||
return Tag.selfClosingInserting(Component.text(proxy.getPlayerCount()));
|
||||
})
|
||||
.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 TagsUtils.staticTag(proxy.getPlayer(playerName).isPresent() ? Components.YES_COMPONENT : Components.NO_COMPONENT);
|
||||
})
|
||||
.globalPlaceholder("version", TagsUtils.staticTag(proxy.getVersion().getVersion()))
|
||||
.build()
|
||||
.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlatformCommand() {
|
||||
final BrigadierCommand brigadierCMD = new BrigadierCommand(
|
||||
PlaceholdersCommand.<CommandSource>builder()
|
||||
.playerSuggestions(() -> proxy.getAllPlayers()
|
||||
.stream()
|
||||
.map(Player::getUsername)
|
||||
.toList())
|
||||
.toAudience(st -> proxy.getPlayer(st).orElse(null))
|
||||
.build()
|
||||
.asNode("vminiplaceholders")
|
||||
);
|
||||
|
||||
proxy.getCommandManager().register(brigadierCMD);
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package me.dreamerzero.miniplaceholders.velocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.command.BrigadierCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
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.common.PlaceholdersCommand;
|
||||
import me.dreamerzero.miniplaceholders.common.PlaceholdersPlugin;
|
||||
import me.dreamerzero.miniplaceholders.common.PluginConstants;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
|
||||
@Plugin(
|
||||
name = "MiniPlaceholders",
|
||||
id = "miniplaceholders",
|
||||
version = PluginConstants.VERSION,
|
||||
authors = {"4drian3d"}
|
||||
)
|
||||
public final class VelocityPlugin implements PlaceholdersPlugin {
|
||||
private final Logger logger;
|
||||
private final ProxyServer proxy;
|
||||
@Inject
|
||||
public VelocityPlugin(Logger logger, ProxyServer proxy) {
|
||||
this.logger = logger;
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@SuppressWarnings("deprecation")
|
||||
public void onProxyInitialize(ProxyInitializeEvent event) {
|
||||
logger.info("Starting MiniPlaceholders Velocity");
|
||||
|
||||
MiniPlaceholders.setPlatform(Platform.VELOCITY);
|
||||
|
||||
this.loadDefaultExpansions();
|
||||
this.registerPlatformCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDefaultExpansions() {
|
||||
Expansion.builder("proxy")
|
||||
.globalPlaceholder("online_players", (queue, ctx) -> {
|
||||
if(queue.hasNext()){
|
||||
String server = queue.pop().value();
|
||||
return Tag.selfClosingInserting(Component.text(proxy.getServer(server).map(sv -> sv.getPlayersConnected().size()).orElse(0)));
|
||||
}
|
||||
return Tag.selfClosingInserting(Component.text(proxy.getPlayerCount()));
|
||||
})
|
||||
.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()));
|
||||
})
|
||||
.globalPlaceholder("version", (queue, ctx) -> Tag.selfClosingInserting(Component.text(proxy.getVersion().getVersion())))
|
||||
.build()
|
||||
.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlatformCommand() {
|
||||
BrigadierCommand brigadierCMD = new BrigadierCommand(
|
||||
new PlaceholdersCommand<CommandSource>(
|
||||
() -> proxy.getAllPlayers().stream().map(Player::getUsername).toList(),
|
||||
(String st) -> proxy.getPlayer(st).orElse(null))
|
||||
.placeholderTestCommand("vminiplaceholders"));
|
||||
|
||||
proxy.getCommandManager().register(brigadierCMD);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user