Skip to content

Commit

Permalink
fix: Fixed MiniMessage format in legacy strings
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed May 28, 2023
1 parent b537bd1 commit b636018
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ subprojects {

tasks {
shadowJar {
archiveFileName.set("LuckPerms-Expansion-${project.version}.jar")
archiveFileName.set("MiniPlaceholders-LuckPerms-Expansion-${project.version}.jar")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
build {
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ dependencies {
compileOnly(libs.miniplaceholders)
compileOnly(libs.adventure.api)
compileOnly(libs.adventure.minimessage)
compileOnly(libs.adventure.legacy)
compileOnly(libs.luckperms)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.miniplaceholders.expansion.luckperms.common;

import io.github.miniplaceholders.api.Expansion;
import io.github.miniplaceholders.api.utils.LegacyUtils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
Expand All @@ -11,10 +10,14 @@
import net.luckperms.api.model.group.Group;
import net.luckperms.api.model.user.User;
import net.luckperms.api.util.Tristate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

import static io.github.miniplaceholders.api.utils.Components.*;
import static io.github.miniplaceholders.api.utils.LegacyUtils.LEGACY_HEX_SERIALIZER;
import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;

public record CommonExpansion(LuckPerms luckPerms) {
private static final Component UNDEFINED_COMPONENT = Component.text("undefined", NamedTextColor.GRAY);
Expand All @@ -26,14 +29,14 @@ public Expansion.Builder commonBuilder() {
if (user == null) {
return null;
}
return Tag.inserting(LegacyUtils.parsePossibleLegacy(user.getCachedData().getMetaData().getPrefix()));
return Tag.inserting(parsePossibleLegacy(user.getCachedData().getMetaData().getPrefix()));
})
.audiencePlaceholder("suffix", (aud, queue, ctx) -> {
final User user = user(aud);
if (user == null) {
return null;
}
return Tag.inserting(LegacyUtils.parsePossibleLegacy(user.getCachedData().getMetaData().getSuffix()));
return Tag.inserting(parsePossibleLegacy(user.getCachedData().getMetaData().getSuffix()));
})
.audiencePlaceholder("has_permission", (aud, queue, ctx) -> {
final User user = user(aud);
Expand Down Expand Up @@ -67,7 +70,7 @@ public Expansion.Builder commonBuilder() {
return null;
}
final Component groups = user.getInheritedGroups(user.getQueryOptions()).stream()
.map(group -> LegacyUtils.parsePossibleLegacy(group.getDisplayName()))
.map(group -> parsePossibleLegacy(group.getDisplayName()))
.collect(Component.toComponent(Component.text(", ")));
return Tag.selfClosingInserting(groups);
})
Expand Down Expand Up @@ -102,4 +105,17 @@ private User user(final Audience audience) {
}
return luckPerms.getUserManager().getUser(uuid);
}

public static @NotNull Component parsePossibleLegacy(final @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))
.replace("\\<", "<")
.replace("\\>", ">")
);
} else {
return miniMessage().deserialize(string);
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group = io.github.miniplaceholders
version = 1.1.1
version = 1.2.0
description = LuckPerms-Expansion
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ luckperms = { module = "net.luckperms:api", version.ref = "luckperms" }

adventure-api = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" }
adventure-minimessage = { group = "net.kyori", name = "adventure-text-minimessage", version.ref = "adventure" }
adventure-legacy = { group = "net.kyori", name = "adventure-text-serializer-legacy", version.ref = "adventure" }

[plugins]

Expand Down
2 changes: 1 addition & 1 deletion paper/src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: LuckPerms-Expansion
name: MiniPlaceholders-LuckPerms-Expansion
version: '${version}'
author: 4drian3d
main: io.github.miniplaceholders.expansion.luckperms.paper.PaperPlugin
Expand Down
9 changes: 9 additions & 0 deletions velocity/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
plugins {
alias(libs.plugins.blossom)
}

dependencies {
compileOnly(libs.velocity.api)
annotationProcessor(libs.velocity.api)
compileOnly(libs.miniplaceholders)
compileOnly(libs.luckperms)
implementation(projects.luckpermsExpansionCommon)
}

blossom {
replaceTokenIn("src/main/java/io/github/miniplaceholders/expansion/luckperms/velocity/Constants.java")
replaceToken("{version}", project.version)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.miniplaceholders.expansion.luckperms.velocity;

public class Constants {
static final String VERSION = "{version}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import org.slf4j.Logger;

@Plugin(
name = "LuckPerms-Expansion",
id = "luckperms-expansion",
version = "1.0.0",
name = "MiniPlaceholders-LuckPerms-Expansion",
id = "miniplaceholders-luckperms-expansion",
version = Constants.VERSION,
authors = {"4drian3d"},
dependencies = {
@Dependency(id = "miniplaceholders"),
Expand Down

0 comments on commit b636018

Please sign in to comment.