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 |
No files matched your search
@@ -2,7 +2,7 @@
|
||||
MiniMessage Component-based Placeholders for PaperMC and Velocity platforms
|
||||
|
||||
## Compatibility
|
||||
- Paper 1.19.3+
|
||||
- Paper 1.19.4+
|
||||
- Velocity 3.1.2+
|
||||
- Krypton
|
||||
|
||||
@@ -25,12 +25,12 @@ class Main {
|
||||
public static void registerExpansion() {
|
||||
Expansion expansion = Expansion.builder("my-expansion")
|
||||
.filter(Player.class)
|
||||
.audiencePlaceholder("name", (aud, ctx, queue) -> {
|
||||
return Tag.selfClosingInserting(aud.getName());
|
||||
})
|
||||
.globalPlaceholder("tps", (ctx, queue) -> {
|
||||
return Tag.inserting(Component.text(Bukkit.getTps()[0]));
|
||||
}).build;
|
||||
.audiencePlaceholder("name", (aud, ctx, queue) ->
|
||||
Tag.selfClosingInserting(aud.getName())
|
||||
)
|
||||
.globalPlaceholder("tps", (ctx, queue) ->
|
||||
Tag.selfClosingInserting(Component.text(Bukkit.getTps()[0]))
|
||||
).build;
|
||||
|
||||
expansion.register();
|
||||
|
||||
@@ -61,7 +61,7 @@ fun register() {
|
||||
```
|
||||
|
||||
|
||||
Check the available javadocs [here](https://javadoc.jitpack.io/com/github/4drian3d/MiniPlaceholders/latest/javadoc/index.html)
|
||||
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)
|
||||
|
||||
@@ -7,13 +7,13 @@ plugins {
|
||||
dependencies {
|
||||
compileOnly(libs.adventure.api)
|
||||
compileOnly(libs.adventure.minimesssage)
|
||||
compileOnly("net.kyori:adventure-text-serializer-legacy:4.12.0")
|
||||
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(libs.adventure.api)
|
||||
testImplementation(libs.adventure.minimesssage)
|
||||
testImplementation("net.kyori:adventure-text-serializer-plain:4.12.0")
|
||||
testImplementation("net.kyori:adventure-text-serializer-plain:4.13.1")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
java
|
||||
alias(libs.plugins.shadow)
|
||||
kotlin("jvm") version "1.8.10" apply false
|
||||
kotlin("jvm") version "1.8.20" apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
|
||||
@@ -1,88 +1,87 @@
|
||||
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 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 io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.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 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 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 BiPredicate<A, String> hasPermission = null;
|
||||
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(Component.text(MiniPlaceholders.getExpansionCount())))
|
||||
.globalPlaceholder("version", (queue, ctx) -> Tag.selfClosingInserting(Component.text(PluginConstants.VERSION)))
|
||||
.globalPlaceholder("count", (queue, ctx) -> Tag.selfClosingInserting(text(MiniPlaceholders.getExpansionCount())))
|
||||
.globalPlaceholder("version", (queue, ctx) -> Tag.selfClosingInserting(text(PluginConstants.VERSION)))
|
||||
.build();
|
||||
|
||||
public PlaceholdersCommand(
|
||||
@NotNull Supplier<Collection<String>> playersSuggestions,
|
||||
@NotNull Function<@NotNull String,
|
||||
@Nullable Audience> toAudience
|
||||
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;
|
||||
}
|
||||
|
||||
public PlaceholdersCommand(
|
||||
Supplier<Collection<String>> playersSuggestions,
|
||||
Function<@NotNull String, @Nullable Audience> toAudience,
|
||||
Function<A, Audience> fromAToAudience
|
||||
) {
|
||||
this(playersSuggestions, toAudience);
|
||||
this.fromAToAudience = fromAToAudience;
|
||||
}
|
||||
|
||||
public PlaceholdersCommand(
|
||||
Supplier<Collection<String>> playersSuggestions,
|
||||
Function<@NotNull String, @Nullable Audience> toAudience,
|
||||
Function<A, Audience> fromAToAudience,
|
||||
BiPredicate<A, String> hasPermission
|
||||
) {
|
||||
this(playersSuggestions, toAudience, fromAToAudience);
|
||||
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>");
|
||||
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){
|
||||
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(
|
||||
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())
|
||||
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())
|
||||
text()
|
||||
.append(HEADER)
|
||||
.append(Component.newline())
|
||||
.append(miniMessage()
|
||||
.deserialize(
|
||||
"<gradient:#8693AB:#BDD4E7>Version: <placeholders_version>",
|
||||
commandExpansion.globalPlaceholders()
|
||||
)).append(Component.newline())
|
||||
.append(FOOTER)
|
||||
.build()
|
||||
);
|
||||
@@ -93,47 +92,57 @@ public class PlaceholdersCommand<A> {
|
||||
.requires(src -> hasPermission(src, "miniplaceholders.command.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())
|
||||
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 1;
|
||||
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", StringArgumentType.string())
|
||||
.then(RequiredArgumentBuilder.<A, String>argument("string", string())
|
||||
.executes(cmd -> {
|
||||
String stringToParse = cmd.getArgument("string", String.class);
|
||||
Component parsed = this.parseGlobal(stringToParse, getAudience(cmd.getSource()));
|
||||
final String toParse = getString(cmd, "string");
|
||||
final Component parsed = parseGlobal(toParse, getAudience(cmd.getSource()));
|
||||
getAudience(cmd.getSource()).sendMessage(parsed);
|
||||
return 1;
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
)
|
||||
.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("string", StringArgumentType.string())
|
||||
.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 -> {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
String stringToParse = cmd.getArgument("playerStringToParse", String.class);
|
||||
final String toParse = cmd.getArgument("string", String.class);
|
||||
|
||||
Component parsed = this.parseGlobal(stringToParse, objetive);
|
||||
final Component parsed = parseGlobal(toParse, objective);
|
||||
getAudience(cmd.getSource()).sendMessage(parsed);
|
||||
return 1;
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
)
|
||||
@@ -141,11 +150,11 @@ public class PlaceholdersCommand<A> {
|
||||
);
|
||||
}
|
||||
|
||||
public LiteralCommandNode<A> placeholderTestCommand(String command){
|
||||
return this.placeholderTestBuilder(command).build();
|
||||
public LiteralCommandNode<A> asNode(String command) {
|
||||
return asBuilder(command).build();
|
||||
}
|
||||
|
||||
private Component parseGlobal(String string, Audience audience){
|
||||
private Component parseGlobal(final String string, final Audience audience) {
|
||||
return miniMessage().deserialize(
|
||||
string,
|
||||
TagResolver.resolver(
|
||||
@@ -155,15 +164,15 @@ public class PlaceholdersCommand<A> {
|
||||
);
|
||||
}
|
||||
|
||||
private Audience getAudience(A possibleAudience){
|
||||
private Audience getAudience(final A possibleAudience) {
|
||||
if (possibleAudience instanceof Audience audience){
|
||||
return audience;
|
||||
}
|
||||
Audience audience = fromAToAudience.apply(possibleAudience);
|
||||
final Audience audience = sourceToAudience.apply(possibleAudience);
|
||||
return audience != null ? audience : Audience.empty();
|
||||
}
|
||||
|
||||
private boolean hasPermission(A source, String permission) {
|
||||
private boolean hasPermission(final A source, final String permission) {
|
||||
if (hasPermission != null) {
|
||||
return hasPermission.test(source, permission);
|
||||
}
|
||||
@@ -172,4 +181,47 @@ public class PlaceholdersCommand<A> {
|
||||
.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,3 +1,3 @@
|
||||
group = io.github.miniplaceholders
|
||||
version = 2.0.0
|
||||
version = 2.0.2
|
||||
description = MiniMessage Component-based Placeholders for PaperMC, Krypton and Velocity platforms
|
||||
@@ -3,21 +3,21 @@ metadata.format.version = "1.1"
|
||||
[versions]
|
||||
|
||||
velocity = "3.2.0-SNAPSHOT"
|
||||
paper = "1.19.3-R0.1-SNAPSHOT"
|
||||
paper = "1.19.4-R0.1-SNAPSHOT"
|
||||
krypton = "7f7a457cdf"
|
||||
|
||||
runtask = "2.0.1"
|
||||
pluginyml = "0.5.3"
|
||||
userdev = "1.5.1"
|
||||
userdev = "1.5.4"
|
||||
blossom = "1.3.1"
|
||||
indra = "3.0.1"
|
||||
shadow = "8.0.0"
|
||||
shadow = "8.1.1"
|
||||
jmh = "0.7.0"
|
||||
dokka = "1.7.20"
|
||||
dokka = "1.8.10"
|
||||
|
||||
adventure = "4.12.0"
|
||||
brigadier = "1.0.18"
|
||||
kotlin="1.8.10"
|
||||
adventure = "4.13.1"
|
||||
brigadier = "1.0.500"
|
||||
kotlin="1.8.20"
|
||||
|
||||
|
||||
[libraries]
|
||||
@@ -33,11 +33,11 @@ brigadier = { group = "com.mojang", name = "brigadier", version.ref = "brigadier
|
||||
|
||||
krypton-annotation = { group = "org.kryptonmc", name = "krypton-annotation-processor", version.ref = "krypton" }
|
||||
|
||||
plugin-shadow = { group = "gradle.plugin.com.github.johnrengelman", name = "shadow", version.ref = "shadow" }
|
||||
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.7.20"
|
||||
plugin-dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.8.10"
|
||||
|
||||
[plugins]
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
|
||||
networkTimeout=10000
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -73,12 +73,12 @@ class KotlinKryptonPlugin @Inject constructor(
|
||||
}
|
||||
|
||||
override fun registerPlatformCommand() {
|
||||
val command = PlaceholdersCommand<CommandExecutionContext>(
|
||||
{ server.players.map { it.name } },
|
||||
{ server.getPlayer(it) },
|
||||
{ it.sender }
|
||||
)
|
||||
val brigadierCMD = BrigadierCommand.of(command.placeholderTestCommand("miniplaceholders"))
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ tasks {
|
||||
options.release.set(17)
|
||||
}
|
||||
runServer {
|
||||
minecraftVersion("1.19.3")
|
||||
minecraftVersion("1.19.4")
|
||||
}
|
||||
jar {
|
||||
manifest {
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
package io.github.miniplaceholders.paper;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import io.papermc.paper.datapack.Datapack;
|
||||
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 final DecimalFormat tpsFormat = new DecimalFormat("###.##");
|
||||
private final DecimalFormat msptFormat = new DecimalFormat("###.###");
|
||||
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");
|
||||
InternalPlatform.platform(InternalPlatform.PAPER);
|
||||
|
||||
tpsFormat.setRoundingMode(RoundingMode.HALF_UP);
|
||||
msptFormat.setRoundingMode(RoundingMode.HALF_UP);
|
||||
|
||||
this.loadDefaultExpansions();
|
||||
this.registerPlatformCommand();
|
||||
}
|
||||
@@ -44,28 +44,28 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin
|
||||
.globalPlaceholder("version", TagsUtils.staticTag(this.getServer().getVersion()))
|
||||
.globalPlaceholder("max_players", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().getMaxPlayers())))
|
||||
.globalPlaceholder("unique_joins", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().getOfflinePlayers().length)))
|
||||
.globalPlaceholder("tps_1", (queue, ctx) -> TagsUtils.staticTag(tpsFormat.format(this.getServer().getTPS()[0])))
|
||||
.globalPlaceholder("tps_5", (queue, ctx) -> TagsUtils.staticTag(tpsFormat.format(this.getServer().getTPS()[1])))
|
||||
.globalPlaceholder("tps_15", (queue, ctx) -> TagsUtils.staticTag(tpsFormat.format(this.getServer().getTPS()[2])))
|
||||
.globalPlaceholder("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()){
|
||||
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()){
|
||||
for (World world : this.getServer().getWorlds()){
|
||||
entityCount += world.getEntityCount();
|
||||
}
|
||||
return TagsUtils.staticTag(Component.text(entityCount));
|
||||
})
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> TagsUtils.staticTag(msptFormat.format(this.getServer().getAverageTickTime())))
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> TagsUtils.staticTag(MSPT_FORMAT.format(this.getServer().getAverageTickTime())))
|
||||
.globalPlaceholder("datapack_list", (queue, ctx) -> {
|
||||
TextComponent.Builder builder = Component.text();
|
||||
for(Datapack datapack : this.getServer().getDatapackManager().getEnabledPacks()){
|
||||
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());
|
||||
@@ -81,12 +81,16 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin
|
||||
MinecraftServer.getServer()
|
||||
.getCommands()
|
||||
.getDispatcher()
|
||||
.register(new PlaceholdersCommand<>(
|
||||
() -> this.getServer().getOnlinePlayers().stream().map(Player::getName).toList(),
|
||||
(String st) -> this.getServer().getPlayer(st),
|
||||
CommandSourceStack::getBukkitSender,
|
||||
(source, permission) -> source.getBukkitSender().hasPermission(permission)
|
||||
).placeholderTestBuilder("miniplaceholders")
|
||||
.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")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,5 @@ 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'
|
||||
api-version: '1.19'
|
||||
folia-supported: true
|
||||
+2
-1
@@ -2,5 +2,6 @@
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:base"
|
||||
]
|
||||
],
|
||||
"ignoreDeps": ["krypton", "krypton-api", "krypton-annotation-processor", "krypton-server"]
|
||||
}
|
||||
@@ -11,6 +11,10 @@ pluginManagement {
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0"
|
||||
}
|
||||
|
||||
arrayOf(
|
||||
"connect",
|
||||
"api",
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
#run velocity files
|
||||
/run
|
||||
@@ -8,9 +8,6 @@ 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 io.github.miniplaceholders.api.Expansion;
|
||||
import io.github.miniplaceholders.api.utils.Components;
|
||||
import io.github.miniplaceholders.api.utils.TagsUtils;
|
||||
@@ -20,16 +17,18 @@ 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"}
|
||||
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;
|
||||
@@ -49,30 +48,35 @@ public final class VelocityPlugin implements PlaceholdersPlugin {
|
||||
@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();
|
||||
.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(
|
||||
new PlaceholdersCommand<CommandSource>(
|
||||
() -> proxy.getAllPlayers().stream().map(Player::getUsername).toList(),
|
||||
(String st) -> proxy.getPlayer(st).orElse(null))
|
||||
.placeholderTestCommand("vminiplaceholders"));
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user