Compare commits

..
40 Commits
Author SHA1 Message Date
Adrian 373d15a115 release: Version 2.1.0 2023-04-25 12:09:36 -05:00
Adrian 67e1de9334 ci: Adjusted upload action to also upload Fabric version 2023-04-25 11:39:45 -05:00
Adrian 07c780411f Merge remote-tracking branch 'origin/main' 2023-04-25 11:04:03 -05:00
Adrian c678931a31 misc: Improved command feedback design 2023-04-25 11:03:37 -05:00
Adrian 2511a0f2df Merge pull request #65 from MiniPlaceholders/renovate/kotlin-monorepo
fix(deps): update kotlin monorepo to v1.8.21
2023-04-25 07:50:33 -05:00
renovate[bot] 27ff27caf6 fix(deps): update kotlin monorepo to v1.8.21 2023-04-25 05:12:17 +00:00
Adrian 547f9a1788 Merge pull request #62 from MiniPlaceholders/renovate/runtask
chore(deps): update runtask to v2.1.0
2023-04-24 14:11:57 -05:00
Adrian 12a407585b Merge pull request #64 from MiniPlaceholders/renovate/org.gradle.toolchains.foojay-resolver-convention-0.x
chore(deps): update plugin org.gradle.toolchains.foojay-resolver-convention to v0.5.0
2023-04-24 14:11:49 -05:00
renovate[bot] 60796df402 chore(deps): update plugin org.gradle.toolchains.foojay-resolver-convention to v0.5.0 2023-04-24 17:32:44 +00:00
Adrian 56fd8557c6 Merge pull request #63 from MiniPlaceholders/renovate/fabric-api
fix(deps): update dependency net.fabricmc.fabric-api:fabric-api to v0.79.0+1.20
2023-04-24 08:34:04 -05:00
renovate[bot] fa4305682a fix(deps): update dependency net.fabricmc.fabric-api:fabric-api to v0.79.0+1.20 2023-04-24 09:25:05 +00:00
renovate[bot] 08f0c8871b chore(deps): update runtask to v2.1.0 2023-04-24 04:23:07 +00:00
Adrian 8dfaa35b16 [ci skip] chore: Improved README documentation 2023-04-23 12:05:39 -05:00
Adrian 3137a87095 Merge pull request #60 from MiniPlaceholders/renovate/fabric-loom-1.x
chore(deps): update plugin fabric-loom to v1.2.5
2023-04-23 09:36:11 -05:00
renovate[bot] 423275e11d chore(deps): update plugin fabric-loom to v1.2.5 2023-04-23 13:50:41 +00:00
Adrian 21b876c13a Merge pull request #59 from MiniPlaceholders/renovate/fabric-loom-1.x
chore(deps): update plugin fabric-loom to v1.2.4
2023-04-23 08:49:50 -05:00
renovate[bot] 3fedc67356 chore(deps): update plugin fabric-loom to v1.2.4 2023-04-23 12:53:50 +00:00
Adrian 63a8ef9e02 Merge pull request #57 from MiniPlaceholders/renovate/fabric-api
fix(deps): update dependency net.fabricmc.fabric-api:fabric-api to v0.78.1+1.20
2023-04-22 12:35:57 -05:00
Adrian 4666531bb8 Merge pull request #58 from MiniPlaceholders/renovate/fabric-loom-1.x
chore(deps): update plugin fabric-loom to v1.2.2
2023-04-22 12:35:16 -05:00
renovate[bot] abf476c368 chore(deps): update plugin fabric-loom to v1.2.2 2023-04-22 17:18:52 +00:00
renovate[bot] d213a20df6 fix(deps): update dependency net.fabricmc.fabric-api:fabric-api to v0.78.1+1.20 2023-04-22 17:18:47 +00:00
Adrian 8f5a81c17e feat(platform): Added Fabric Implementation (#53) 2023-04-22 12:16:20 -05:00
Adrian dd0e895513 Merge branch 'main' into feat/platform/fabric 2023-04-21 23:14:30 -05:00
Adrian 8f42950ef3 ci: Increased compile timeout in GitHub Actions 2023-04-21 21:54:14 -05:00
Adrian 4043a578e1 feat(fabric): Finished server placeholders implementation 2023-04-21 19:48:44 -05:00
Adrian 1c06b1bee4 Merge pull request #56 from MiniPlaceholders/renovate/gradle-8.x
chore(deps): update dependency gradle to v8.1.1
2023-04-21 08:38:33 -05:00
renovate[bot] 5c6b3f4e43 chore(deps): update dependency gradle to v8.1.1 2023-04-21 13:20:37 +00:00
Adrian 8df4e70032 Merge pull request #55 from MiniPlaceholders/renovate/jmh
chore(deps): update dependency me.champeau.jmh to v0.7.1
2023-04-17 15:41:39 -05:00
renovate[bot] 432267b567 chore(deps): update dependency me.champeau.jmh to v0.7.1 2023-04-17 20:10:21 +00:00
Adrian 28090463b8 fix(fabric): Fixed meta file name 2023-04-16 22:29:31 -05:00
Adrian fff437a60b fix: Fixed project compilation 2023-04-16 21:10:40 -05:00
Adrian 00e0bdcaf3 feat(platform): Added Fabric support 2023-04-16 16:23:48 -05:00
Adrian 1c9ff78b4c feat(api): Added some utils methods to Expansions and MiniPlaceholders
- `Expansion#registered`
- `Expansion#unregister`
- `MiniPlaceholders#getExpansionByName`
2023-04-16 12:08:36 -05:00
Adrian 0aa037d1af feat(api): Added some utils methods to Expansions and MiniPlaceholders class
- Expansion#registered
- Expansion#unregister
- MiniPlaceholders#getExpansionByName

closes #51
2023-04-16 10:20:42 -05:00
Adrian 1440d19663 [ci skip] chore: Removed unused jitpack file 2023-04-15 23:54:08 -05:00
Adrian 20daf60534 fix(deps): Manually updated Krypton version
closes #42
closes #38
2023-04-15 23:52:03 -05:00
Adrian dd36c10a0f perf(api): Changed internal Set implementation from a synchronizedSet to a ConcurrentHashMap based Set 2023-04-15 23:42:40 -05:00
Adrian 0caddf5b44 [ci skip] chore: Update FUNDING.yml 2023-04-14 16:12:43 -05:00
Adrian 7ca4536dc5 Merge pull request #50 from MiniPlaceholders/renovate/gradle-8.x
chore(deps): update dependency gradle to v8.1
2023-04-14 09:32:21 -05:00
renovate[bot] e9ecd3aebf chore(deps): update dependency gradle to v8.1 2023-04-12 15:22:19 +00:00
26 changed files with 543 additions and 169 deletions

No files matched your search

+2 -13
View File
@@ -1,13 +1,2 @@
# 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']
github: 4drian3d
custom: https://paypal.me/4drian3d
+4 -2
View File
@@ -20,7 +20,7 @@ jobs:
- name: Build with Gradle
uses: nick-invision/retry@v2
with:
timeout_minutes: 4
timeout_minutes: 10
max_attempts: 2
command: gradle build
@@ -28,4 +28,6 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: MiniPlaceholders
path: build/libs/MiniPlaceholders-*.jar
path: |-
build/libs/MiniPlaceholders-*.jar
fabric/build/libs/MiniPlaceholders-Fabric-mc*.jar
+47 -27
View File
@@ -1,33 +1,57 @@
# MiniPlaceholders ![WorkFlow](https://img.shields.io/github/actions/workflow/status/MiniPlaceholders/MiniPlaceholders/build.yml?style=flat-square) [![Discord](https://img.shields.io/discord/899740810956910683?color=7289da&label=Discord)](https://discord.gg/5NMMzK5mAn)
MiniMessage Component-based Placeholders for PaperMC and Velocity platforms
# MiniPlaceholders
[![WorkFlow](https://img.shields.io/github/actions/workflow/status/MiniPlaceholders/MiniPlaceholders/build.yml?style=flat-square)](https://github.com/MiniPlaceholders/MiniPlaceholders/actions)
![Latest Version](https://img.shields.io/github/v/release/MiniPlaceholders/MiniPlaceholders?style=flat-square)
[![Discord](https://img.shields.io/discord/899740810956910683?color=7289da&logo=Discord&label=Discord&style=flat-square)](https://discord.gg/5NMMzK5mAn)
![Modrinth Downloads](https://img.shields.io/modrinth/dt/HQyibRsN?logo=Modrinth&style=flat-square)
![GitHub Downloads](https://img.shields.io/github/downloads/MiniPlaceholders/MiniPlaceholders/total?logo=GitHub&style=flat-square)
MiniMessage Component-based Placeholders for PaperMC, Folia, Fabric, Krypton and Velocity platforms
## Compatibility
- Paper 1.19.4+
- Folia 1.19.4
- Velocity 3.1.2+
- Fabric
- Krypton
## Commands:
## Commands
### Velocity
`/vminiplaceholders <parse|help> <me|player> <player-to-parse>`
### Paper
`/miniplaceholders <parse|help> <me|player> <player-to-parse>`
## Usage
- `/vminiplaceholders parse me "[message with placeholders]"`
- `/vminiplaceholders parse player [some-player] "[message with placeholders]"`
Check our usage wiki [here](https://github.com/MiniPlaceholders/MiniPlaceholders/wiki/User-Getting-Started)
### Paper | Folia | Fabric | Krypton
- `/miniplaceholders <parse|help> player [some-player] "[message with placeholders]`
- `/miniplaceholders parse player [some-player] "[message with placeholders]"`
#### Example:
- `/miniplaceholders parse me "<player_xp>"`
- `/vminiplaceholders parse player 4drian3d "<player_name>"`
## User Usage
Check our user usage wiki [here](https://github.com/MiniPlaceholders/MiniPlaceholders/wiki/User-Getting-Started)
## API
Check the available [Javadocs](https://javadoc.io/doc/io.github.miniplaceholders/miniplaceholders-api)
Or check the [Developer Wiki](https://github.com/MiniPlaceholders/MiniPlaceholders/wiki/Developer-Getting-Started)
### Java
```java
class Main {
public static void registerExpansion() {
Expansion expansion = Expansion.builder("my-expansion")
final Expansion expansion = Expansion.builder("my-expansion")
.filter(Player.class)
.audiencePlaceholder("name", (aud, ctx, queue) ->
Tag.selfClosingInserting(aud.getName())
)
.audiencePlaceholder("name", (audience, ctx, queue) -> {
final Player player = (player) audience;
return Tag.selfClosingInserting(player.getName());
})
.globalPlaceholder("tps", (ctx, queue) ->
Tag.selfClosingInserting(Component.text(Bukkit.getTps()[0]))
).build;
@@ -35,7 +59,8 @@ class Main {
expansion.register();
Player player;
player.sendMessage(miniMessage().deserialize("Player Name: <my-expansion_name>", MiniPlaceholders.getAudiencePlaceholders(player)));
final TagResolver playerResolver = MiniPlaceholders.getAudiencePlaceholders(player);
player.sendMessage(miniMessage().deserialize("Player Name: <my-expansion_name>", playerResolver));
}
}
@@ -44,24 +69,19 @@ class Main {
### Kotlin
```kotlin
fun register() {
val expansion = expansion("my-expansion") {
audiencePlaceholder("name") { aud, _, _ ->
aud.getName().asClosingTag()
val expansion = expansion("my-expansion") {
audiencePlaceholder("name") { aud, _, _ ->
aud.getName().asClosingTag()
}
globalPlaceholder("tps") { _, _ ->
Component.text(Bukkit.getTps()[0]).asInsertingTag()
}
}
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)))
val playerResolver = MiniPlaceholders.getAudiencePlaceholders(player)
player.sendMessage(miniMessage().deserialize("Player Name: <my-expansion_name>", playerResolver))
}
```
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)
+1 -6
View File
@@ -36,15 +36,10 @@ java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
repositories {
mavenCentral()
}
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(11)
options.release.set(17)
}
processResources {
filteringCharset = Charsets.UTF_8.name()
@@ -74,9 +74,26 @@ public interface Expansion {
/**
* Register this expansion
* @since 1.0.0
* @throws IllegalStateException if the expansion you are trying to register is already registered
* @see Expansion#registered()
*/
void register();
/**
* Unregisters this expansion
* @since 2.1.0
* @throws IllegalStateException if the expansion you are trying to unregister is not registered
* @see Expansion#registered()
*/
void unregister();
/**
* Get the registration status of this expansion
* @return true if the expansion is registered, otherwise false
* @since 2.1.0
*/
boolean registered();
/**
* Creates a new Expansion Builder
* @param name the expansion name
@@ -125,7 +142,7 @@ public interface Expansion {
@NotNull Builder audiencePlaceholder(final @NotNull String key, final @NotNull AudiencePlaceholder audiencePlaceholder);
/**
* Adds an Relational Placeholder based on two audiences
* Adds a Relational Placeholder based on two audiences
*
* <p>This type of placeholder allows you to create
* components based on a 2-audiences relationship,
@@ -157,7 +174,7 @@ public interface Expansion {
/**
* Adds a global placeholder
*
* <p>This placeholder is not cached and is inmutable</p>
* <p>This placeholder is not cached and is immutable</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
@@ -102,10 +102,26 @@ final class ExpansionImpl implements Expansion {
}
@Override
public void register(){
public void register() {
if (this.registered()) {
throw new IllegalStateException("Expansion" + this.name + "is already registered");
}
MiniPlaceholders.expansions.add(this);
}
@Override
public void unregister() {
if (!this.registered()) {
throw new IllegalStateException("Expansion " + this.name + " is not registered");
}
MiniPlaceholders.expansions.remove(this);
}
@Override
public boolean registered() {
return MiniPlaceholders.expansions.contains(this);
}
static final class Builder implements Expansion.Builder {
private final String expansionName;
private Set<Tags.Single> audiencePlaceholders;
@@ -1,17 +1,18 @@
package io.github.miniplaceholders.api;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
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 org.jetbrains.annotations.Nullable;
import static io.github.miniplaceholders.api.utils.Resolvers.applyIfNotEmpty;
import static java.util.Objects.requireNonNull;
/**
@@ -27,8 +28,8 @@ import static java.util.Objects.requireNonNull;
* @since 1.0.0
*/
public final class MiniPlaceholders {
private MiniPlaceholders(){}
static final Set<Expansion> expansions = Collections.synchronizedSet(new HashSet<>());
private MiniPlaceholders() {}
static final Set<Expansion> expansions = ConcurrentHashMap.newKeySet();
/**
* Get the platform
@@ -36,11 +37,12 @@ public final class MiniPlaceholders {
* @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;
}
return switch (InternalPlatform.platform()) {
case PAPER -> Platform.PAPER;
case VELOCITY -> Platform.VELOCITY;
case KRYPTON -> Platform.KRYPTON;
case FABRIC -> Platform.FABRIC;
};
}
/**
@@ -49,7 +51,7 @@ public final class MiniPlaceholders {
* <pre>TagResolver resolver = MiniPlaceholders.getGlobalPlaceholders();
* Component messageParsed = MiniMessage.miniMessage().deserialize({@link String}, resolver);</pre>
*
* @return global placeholders independient of any audience
* @return global placeholders independent of any audience
* @see TagResolver
* @since 1.0.0
*/
@@ -79,8 +81,7 @@ public final class MiniPlaceholders {
final TagResolver.Builder resolvers = TagResolver.builder();
for (Expansion expansion : expansions) {
final TagResolver resolver = expansion.audiencePlaceholders(audience);
if (resolver != TagResolver.empty())
resolvers.resolver(resolver);
applyIfNotEmpty(resolver, resolvers);
}
return resolvers.build();
}
@@ -102,7 +103,7 @@ public final class MiniPlaceholders {
final TagResolver.Builder builder = TagResolver.builder();
for (final Expansion expansion : expansions) {
Resolvers.applyIfNotEmpty(
applyIfNotEmpty(
expansion.relationalPlaceholders(audience, otherAudience),
builder
);
@@ -134,8 +135,8 @@ public final class MiniPlaceholders {
final TagResolver.Builder builder = TagResolver.builder();
for (final Expansion expansion : expansions) {
Resolvers.applyIfNotEmpty(expansion.audiencePlaceholders(audience), builder);
Resolvers.applyIfNotEmpty(expansion.globalPlaceholders(), builder);
applyIfNotEmpty(expansion.audiencePlaceholders(audience), builder);
applyIfNotEmpty(expansion.globalPlaceholders(), builder);
}
return builder.build();
@@ -168,9 +169,9 @@ public final class MiniPlaceholders {
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);
applyIfNotEmpty(expansion.audiencePlaceholders(audience), builder);
applyIfNotEmpty(expansion.relationalPlaceholders(audience, otherAudience), builder);
applyIfNotEmpty(expansion.globalPlaceholders(), builder);
}
return builder.build();
@@ -184,4 +185,27 @@ public final class MiniPlaceholders {
public static int getExpansionCount(){
return expansions.size();
}
/**
* Get a specific expansion by name
* <p>The name of each expansion is set when the expansion is created</p>
* <pre>
* Expansion expansion = Expansion.builder("example").build();
* expansion.register();
*
* assertThat(MiniPlaceholders.getExpansionByName("example")).isNotNull();
* </pre>
* @param name the name of the required expansion
* @return the required expansion, if not present, will return null
* @see Expansion#builder(String)
* @since 2.1.0
*/
public @Nullable Expansion getExpansionByName(final @NotNull String name) {
for (final Expansion expansion : expansions) {
if (Objects.equals(expansion.name(), name)) {
return expansion;
}
}
return null;
}
}
@@ -7,5 +7,7 @@ public enum Platform {
/**Velocity Platform */
VELOCITY,
/**Krypton Platform */
KRYPTON
KRYPTON,
/**Fabric Platform */
FABRIC
}
@@ -1,7 +1,5 @@
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;
@@ -11,6 +9,8 @@ import io.github.miniplaceholders.api.utils.TagsUtils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import static org.junit.jupiter.api.Assertions.*;
class MiniPlaceholdersTest {
@Test
@Disabled("Cannot correctly calculate the equity of 2 TagResolvers obtained in different ways")
@@ -30,4 +30,16 @@ class MiniPlaceholdersTest {
)
);
}
@Test
void registrationTest() {
Expansion expansion = Expansion.builder("testregistration")
.build();
expansion.register();
assertTrue(expansion.registered());
assertThrows(IllegalStateException.class, expansion::register);
assertDoesNotThrow(expansion::unregister);
}
}
+11 -9
View File
@@ -1,11 +1,20 @@
plugins {
java
alias(libs.plugins.shadow)
kotlin("jvm") version "1.8.20" apply false
kotlin("jvm") version "1.8.21" apply false
}
allprojects {
apply<JavaPlugin>()
repositories {
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.maven.apache.org/maven2/")
maven("https://jitpack.io") {
mavenContent {
includeGroup("net.william278")
}
}
}
}
dependencies {
@@ -14,18 +23,11 @@ dependencies {
implementation(projects.miniplaceholdersKrypton)
}
subprojects {
repositories {
mavenCentral()
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.maven.apache.org/maven2/")
}
}
tasks {
shadowJar {
archiveFileName.set("MiniPlaceholders-${project.version}.jar")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
relocate("net.william278.desertwell", "io.github.miniplaceholders.libs.desertwell")
}
build {
dependsOn(shadowJar)
+3 -2
View File
@@ -8,11 +8,13 @@ repositories {
includeGroup("com.mojang")
}
}
mavenCentral()
}
dependencies {
implementation(projects.miniplaceholdersApi)
implementation(libs.desertwell) {
exclude("org.json")
}
compileOnly(libs.adventure.api)
compileOnly(libs.adventure.minimesssage)
compileOnly(libs.brigadier)
@@ -28,7 +30,6 @@ tasks {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
jar {
manifest {
attributes("Automatic-Module-Name" to "io.github.miniplaceholders.common")
@@ -4,14 +4,16 @@ 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.format.TextColor;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.util.TriState;
import net.william278.desertwell.about.AboutMenu;
import net.william278.desertwell.util.Version;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -23,7 +25,7 @@ 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.Component.*;
import static net.kyori.adventure.text.format.NamedTextColor.RED;
import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
@@ -32,10 +34,6 @@ public final class PlaceholdersCommand<A> {
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,
@@ -49,73 +47,59 @@ public final class PlaceholdersCommand<A> {
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 HELP = text()
.append(newline())
.append(miniMessage()
.deserialize("<gradient:aqua:white:aqua><st><b> </st> <gradient:#4d8bff:#a4ff96>MiniPlaceholders</gradient> <st><b> </st>"))
.append(newline())
.append(miniMessage()
.deserialize(
"<gradient:#9694ff:#5269ff>Commands:</gradient>"))
.append(newline())
.append(miniMessage()
.deserialize(
"<gradient:aqua:#94d1ff>/miniplaceholders</gradient> <aqua>help</aqua>"))
.append(newline())
.append(miniMessage()
.deserialize(
"<gradient:aqua:#94d1ff>/miniplaceholders</gradient> <aqua>parse</aqua> <#8fadff><player | me></#8fadff> <#99ffb6><player></#99ffb6>"))
.append(newline())
.append(miniMessage()
.deserialize("<gradient:aqua:white:aqua><st><b> "))
.build();
private static final Component INFO = AboutMenu.builder()
.title(miniMessage().deserialize("<gradient:#4d8bff:#a4ff96>MiniPlaceholders</gradient>"))
.description(text("MiniMessage Component-based Placeholders for PaperMC, Folia, Fabric, Velocity and Krypton platforms"))
.credits("Author", AboutMenu.Credit.of("4drian3d").url("https://github.com/4drian3d"))
.credits("Contributors", AboutMenu.Credit.of("Sliman4"))
.buttons(
AboutMenu.Link.of("https://github.com/MiniPlaceholders/MiniPlaceholders/wiki/User-Getting-Started").text("Documentation").icon("⛏"),
AboutMenu.Link.of("https://discord.gg/5NMMzK5mAn").text("Discord").color(TextColor.color(0x7289da)).icon("⭐"),
AboutMenu.Link.of("https://modrinth.com/plugin/miniplaceholders").text("Downloads").color(TextColor.color(0xff496e)).icon("↓")
).version(Version.fromString(PluginConstants.VERSION))
.build()
.toComponent();
public LiteralArgumentBuilder<A> asBuilder(String commandName){
return LiteralArgumentBuilder.<A>literal(commandName)
.requires(a -> getAudience(a).pointers().supports(PermissionChecker.POINTER))
.requires(a -> permissionValue(a, "miniplaceholders.command") != TriState.FALSE)
.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;
source.sendMessage(INFO);
return Command.SINGLE_SUCCESS;
})
.then(LiteralArgumentBuilder.<A>literal("help")
.requires(src -> hasPermission(src, "miniplaceholders.command.help"))
.requires(src -> permissionValue(src, "miniplaceholders.command.help").toBooleanOrElse(false))
.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()
);
getAudience(cmd.getSource()).sendMessage(HELP);
return Command.SINGLE_SUCCESS;
})
)
.then(LiteralArgumentBuilder.<A>literal("parse")
.requires(cmd -> hasPermission(cmd, "miniplaceholders.command.parse"))
.requires(cmd -> permissionValue(cmd, "miniplaceholders.command.parse").toBooleanOrElse(false))
.then(LiteralArgumentBuilder.<A>literal("me")
.requires(cmd -> permissionValue(cmd, "miniplaceholders.command.parse.me").toBooleanOrElse(false))
.then(RequiredArgumentBuilder.<A, String>argument("string", string())
.executes(cmd -> {
final String toParse = getString(cmd, "string");
@@ -126,6 +110,7 @@ public final class PlaceholdersCommand<A> {
)
)
.then(LiteralArgumentBuilder.<A>literal("player")
.requires(cmd -> permissionValue(cmd, "miniplaceholders.command.parse.player").toBooleanOrElse(false))
.then(RequiredArgumentBuilder.<A, String>argument("source", word())
.suggests((argument, builder) -> supplyAsync(() -> {
playersSuggestions.get().forEach(builder::suggest);
@@ -165,21 +150,21 @@ public final class PlaceholdersCommand<A> {
}
private Audience getAudience(final A possibleAudience) {
if (possibleAudience instanceof Audience audience){
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) {
private TriState permissionValue(final A source, final String permission) {
if (hasPermission != null) {
return hasPermission.test(source, permission);
return TriState.byBoolean(hasPermission.test(source, permission));
}
return getAudience(source)
.get(PermissionChecker.POINTER)
.map(checker -> checker.test(permission))
.orElse(false);
.map(checker -> checker.value(permission))
.orElse(TriState.FALSE);
}
public static <A> Builder<A> builder() {
@@ -2,7 +2,7 @@ package io.github.miniplaceholders.connect;
public enum InternalPlatform {
PAPER, VELOCITY, KRYPTON;
PAPER, VELOCITY, KRYPTON, FABRIC;
private static InternalPlatform actualPlatform;
+54
View File
@@ -0,0 +1,54 @@
plugins {
id("fabric-loom") version "1.2.5"
alias(libs.plugins.shadow)
}
repositories {
maven("https://oss.sonatype.org/content/repositories/snapshots")
}
val shade: Configuration by configurations.creating
dependencies {
minecraft(libs.minecraft)
mappings(loom.officialMojangMappings())
modImplementation(libs.fabric.loader)
modImplementation(libs.fabric.api)
modImplementation(libs.adventure.platform.fabric)
include(libs.adventure.platform.fabric)
modImplementation(libs.luckopermissionsapi)
include(libs.luckopermissionsapi)
shadeModule(projects.miniplaceholdersCommon)
shadeModule(projects.miniplaceholdersApi)
shadeModule(projects.miniplaceholdersConnect)
}
fun DependencyHandlerScope.shadeModule(module: ProjectDependency) {
shade(module)
implementation(module)
}
tasks {
processResources {
filteringCharset = Charsets.UTF_8.name()
filesMatching("fabric.mod.json") {
expand("version" to project.version)
}
}
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
remapJar {
inputFile.set(shadowJar.get().archiveFile)
archiveFileName.set("MiniPlaceholders-Fabric-mc${libs.versions.minecraft.get()}-v${project.version}.jar")
}
shadowJar {
configurations = listOf(shade)
}
}
java {
withSourcesJar()
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
@@ -0,0 +1,105 @@
package io.github.miniplaceholders.fabric;
import io.github.miniplaceholders.api.Expansion;
import io.github.miniplaceholders.common.PlaceholdersCommand;
import io.github.miniplaceholders.common.PlaceholdersPlugin;
import io.github.miniplaceholders.connect.InternalPlatform;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.packs.PackResources;
import net.minecraft.world.entity.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import java.util.Arrays;
public class FabricMod implements ModInitializer, PlaceholdersPlugin {
private final Logger logger = LoggerFactory.getLogger("miniplaceholders");
private static final DecimalFormat MSPT_FORMAT = new DecimalFormat("###.###");
private final TickManager tickManager = new TickManager();
private MinecraftServer minecraftServer;
@Override
public void onInitialize() {
logger.info("Starting MiniPlaceholders Fabric");
InternalPlatform.platform(InternalPlatform.FABRIC);
ServerLifecycleEvents.SERVER_STARTING.register(minecraftServer -> {
this.minecraftServer = minecraftServer;
this.loadDefaultExpansions();
});
this.registerPlatformCommand();
}
@Override
public void loadDefaultExpansions() {
Expansion.builder("server")
.globalPlaceholder("name", Tag.selfClosingInserting(Component.text(this.minecraftServer.getServerModName())))
.globalPlaceholder("online", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.minecraftServer.getPlayerCount())))
.globalPlaceholder("version", (ctx, queue) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getServerVersion())))
.globalPlaceholder("max_players", (ctx, queue) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getMaxPlayers())))
.globalPlaceholder("unique_joins", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.minecraftServer.getProfileCache().load().size())))
.globalPlaceholder("tps_1m", (ctx, queue) -> Tag.preProcessParsed(tickManager.getTps1m().formattedAverage()))
.globalPlaceholder("tps_5m", (ctx, queue) -> Tag.preProcessParsed(tickManager.getTps5m().formattedAverage()))
//.globalPlaceholder("tps_15m", (ctx, queue) -> Tag.preProcessParsed(tickManager.getTps15m().formattedAverage()))
.globalPlaceholder("tick_count", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getTickCount())))
.globalPlaceholder("has_whitelist", (queue, ctx) -> Tag.preProcessParsed(Boolean.toString(this.minecraftServer.getPlayerList().isUsingWhitelist())))
.globalPlaceholder("total_chunks", (queue, ctx) -> {
int chunks = 0;
for (final ServerLevel level : this.minecraftServer.getAllLevels()) {
chunks += level.getChunkSource().getLoadedChunksCount();
}
return Tag.preProcessParsed(Integer.toString(chunks));
})
.globalPlaceholder("total_entities", (queue, ctx) -> {
int entities = 0;
for (final ServerLevel level : this.minecraftServer.getAllLevels()) {
for (final Entity ignored : level.getAllEntities()) {
entities++;
}
}
return Tag.preProcessParsed(Integer.toString(entities));
})
.globalPlaceholder("mspt", (queue, ctx) -> Tag.preProcessParsed(MSPT_FORMAT.format(this.minecraftServer.getAverageTickTime())))
.globalPlaceholder("datapack_list", (queue, ctx) ->
Tag.selfClosingInserting(this.minecraftServer.getResourceManager()
.listPacks()
.map(PackResources::packId)
.map(id -> Component.text()
.content("[")
.append(Component.text(id))
.append(Component.text("]"))
.build())
.collect(Component.toComponent(Component.space())))
)
.globalPlaceholder("datapack_count", (queue, ctx) ->
Tag.preProcessParsed(Long.toString(this.minecraftServer.getResourceManager()
.listPacks()
.count()))
)
.build()
.register();
}
@Override
public void registerPlatformCommand() {
CommandRegistrationCallback.EVENT.register((dispatcher, commandBuildContext, commandSelection) ->
dispatcher.register(PlaceholdersCommand.<CommandSourceStack>builder()
.hasPermissionCheck((source, permission) -> Permissions.check(source, permission, 4))
.toAudience(string -> this.minecraftServer.getPlayerList().getPlayerByName(string))
.playerSuggestions(() -> Arrays.asList(this.minecraftServer.getPlayerNames()))
.build()
.asBuilder("miniplaceholders"))
);
}
}
@@ -0,0 +1,59 @@
package io.github.miniplaceholders.fabric;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
/**
* Based on the MIT licensed Paper-Server patch "Further improve server tick loop".
*
* @author Daniel Ennis/Aikar
*/
final class RollingAverage {
private static final DecimalFormat TPS_FORMAT = new DecimalFormat("###.##");
static { TPS_FORMAT.setRoundingMode(RoundingMode.HALF_UP); }
private static final int TPS = 20;
private static final long SEC_IN_NANO = 1000000000;
private final int size;
private final BigDecimal[] samples;
private final long[] times;
private long time;
private BigDecimal total;
private int index = 0;
RollingAverage(final int size) {
this.size = size;
this.samples = new BigDecimal[size];
this.times = new long[size];
this.time = size * SEC_IN_NANO;
this.total = dec(TPS).multiply(dec(SEC_IN_NANO)).multiply(dec(size));
for (int i = 0; i < size; i++) {
this.samples[i] = dec(TPS);
this.times[i] = SEC_IN_NANO;
}
}
private static BigDecimal dec(final long t) {
return new BigDecimal(t);
}
void add(final BigDecimal x, final long t) {
this.time -= this.times[this.index];
this.total = this.total.subtract(this.samples[this.index].multiply(dec(this.times[this.index])));
this.samples[this.index] = x;
this.times[this.index] = t;
this.time += t;
this.total = this.total.add(x.multiply(dec(t)));
if (++this.index == this.size) {
this.index = 0;
}
}
double average() {
return this.total.divide(dec(this.time), 30, RoundingMode.HALF_UP).doubleValue();
}
String formattedAverage() {
return TPS_FORMAT.format(average());
}
}
@@ -0,0 +1,45 @@
package io.github.miniplaceholders.fabric;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import java.math.BigDecimal;
import java.math.RoundingMode;
final class TickManager {
private static final int TICK_DURATION = 20;
private static final BigDecimal TPS_BASE = new BigDecimal(1E9).multiply(new BigDecimal(TICK_DURATION));
private final RollingAverage tps1m = new RollingAverage(60);
private final RollingAverage tps5m = new RollingAverage(60 * 5);
private final RollingAverage tps15m = new RollingAverage(60 * 15);
private long lastStartTick = 0;
private long lastEndTick = 0;
TickManager() {
ServerTickEvents.START_SERVER_TICK.register(server -> this.lastStartTick = System.nanoTime());
ServerTickEvents.END_SERVER_TICK.register(server -> {
if (server.getTickCount() % TICK_DURATION == 0) {
final long diff = lastStartTick - lastEndTick;
final BigDecimal currentTps = TPS_BASE.divide(new BigDecimal(diff), 30, RoundingMode.HALF_UP);
this.tps1m.add(currentTps, diff);
this.tps5m.add(currentTps, diff);
this.tps15m.add(currentTps, diff);
this.lastEndTick = System.nanoTime();
}
});
}
public RollingAverage getTps1m() {
return tps1m;
}
public RollingAverage getTps5m() {
return tps5m;
}
public RollingAverage getTps15m() {
return tps15m;
}
}
+29
View File
@@ -0,0 +1,29 @@
{
"schemaVersion": 1,
"id": "miniplaceholders",
"version": "${version}",
"name": "MiniPlaceholders",
"description": "MiniMessage Component-based Placeholders for PaperMC, Fabric, Krypton and Velocity platforms",
"authors": [
"4drian3d"
],
"contact": {
"homepage": "https://github.com/MiniPlaceholders/MiniPlaceholders",
"sources": "https://github.com/MiniPlaceholders/MiniPlaceholders",
"issues": "https://github.com/MiniPlaceholders/MiniPlaceholders/issues"
},
"license": "GPL",
"environment": "server",
"entrypoints": {
"main": [
"io.github.miniplaceholders.fabric.FabricMod"
]
},
"depends": {
"fabricloader": ">=0.14.19",
"fabric": "*",
"java": ">=17",
"minecraft": "~1.19.4",
"fabric-permissions-api-v0": "*"
}
}
+3 -1
View File
@@ -1,3 +1,5 @@
group = io.github.miniplaceholders
version = 2.0.2
version = 2.1.0
description = MiniMessage Component-based Placeholders for PaperMC, Krypton and Velocity platforms
org.gradle.jvmargs=-Xmx2G
+19 -5
View File
@@ -4,30 +4,42 @@ metadata.format.version = "1.1"
velocity = "3.2.0-SNAPSHOT"
paper = "1.19.4-R0.1-SNAPSHOT"
krypton = "7f7a457cdf"
krypton = "cbfaff4aa4"
minecraft = "1.19.4"
runtask = "2.0.1"
runtask = "2.1.0"
pluginyml = "0.5.3"
userdev = "1.5.4"
blossom = "1.3.1"
indra = "3.0.1"
shadow = "8.1.1"
jmh = "0.7.0"
jmh = "0.7.1"
dokka = "1.8.10"
adventure = "4.13.1"
adventurefabric = "5.8.0"
brigadier = "1.0.500"
kotlin="1.8.20"
kotlin="1.8.21"
fabric-api = "0.79.0+1.20"
fabric-loader = "0.14.19"
desertwell = "2.0.2"
[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" }
minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft" }
fabric-api = { group = "net.fabricmc.fabric-api", name = "fabric-api", version.ref = "fabric-api" }
fabric-loader = { group = "net.fabricmc", name = "fabric-loader", version.ref = "fabric-loader" }
luckopermissionsapi = { group = "me.lucko", name = "fabric-permissions-api", version = "0.2-SNAPSHOT" }
adventure-api = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" }
adventure-minimesssage = { group = "net.kyori", name = "adventure-text-minimessage", version.ref = "adventure" }
adventure-platform-fabric = { group = "net.kyori", name = "adventure-platform-fabric", version.ref = "adventurefabric" }
brigadier = { group = "com.mojang", name = "brigadier", version.ref = "brigadier" }
@@ -39,6 +51,8 @@ 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"
desertwell = { group = "net.william278", name = "DesertWell", version.ref = "desertwell" }
[plugins]
pluginyml = { id = "net.minecrell.plugin-yml.bukkit", version.ref = "pluginyml" }
@@ -48,4 +62,4 @@ 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" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored
+4 -3
View File
@@ -85,9 +85,6 @@ done
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"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi
# 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"'
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
-2
View File
@@ -1,2 +0,0 @@
jdk:
- openjdk17
+3 -3
View File
@@ -20,8 +20,8 @@ dependencies {
implementation(projects.miniplaceholdersKotlinExt)
}
tasks {
compileKotlin {
kotlinOptions.jvmTarget = "17"
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
+5 -3
View File
@@ -3,16 +3,17 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
rootProject.name = "miniplaceholders-parent"
pluginManagement {
@Suppress("UnstableApiUsage")
includeBuild("build-logic")
repositories {
gradlePluginPortal()
mavenCentral()
maven("https://maven.fabricmc.net/")
maven("https://maven.quiltmc.org/repository/release/")
}
}
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
}
arrayOf(
@@ -22,7 +23,8 @@ arrayOf(
"common",
"paper",
"velocity",
"krypton"
"krypton",
"fabric"
).forEach {
include("miniplaceholders-$it")
project(":miniplaceholders-$it").projectDir = file(it)