Fix minimessage in velocity module
This commit is contained in:
parent
6fc198bbc7
commit
2c2711e0e7
|
|
@ -3,8 +3,7 @@ plugins {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT") // Minimessage
|
||||
compileOnly("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT")
|
||||
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
|
||||
compileOnly("net.luckperms:api:5.3") // Luckperms
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package com.alttd.boosterapi.util;
|
||||
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
|
||||
public class ALogger {
|
||||
|
||||
private static org.slf4j.Logger logger = null;
|
||||
|
|
@ -23,6 +21,6 @@ public class ALogger {
|
|||
}
|
||||
|
||||
public static void fatal(String error, Exception exception) {
|
||||
error(error + "\n" + ExceptionUtils.getStackTrace(exception));
|
||||
error(error + "\n" + exception);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,20 +2,16 @@ package com.alttd.boosterapi.util;
|
|||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static Component parseMiniMessage(String message, List<Template> templates) {
|
||||
public static Component parseMiniMessage(String message, TagResolver placeholders) {
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
if (templates == null) {
|
||||
if (placeholders == null) {
|
||||
return miniMessage.deserialize(message);
|
||||
} else {
|
||||
return miniMessage.deserialize(message, TemplateResolver.templates(templates));
|
||||
return miniMessage.deserialize(message, placeholders);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,21 +5,25 @@ plugins {
|
|||
|
||||
dependencies {
|
||||
// API
|
||||
implementation(project(":boosters-api"))
|
||||
implementation(project(":boosters-api")) {
|
||||
exclude("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT")
|
||||
}
|
||||
// Velocity
|
||||
compileOnly("com.velocitypowered:velocity-api:3.0.0")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.0.0")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
|
||||
// DiscordLink
|
||||
compileOnly("com.alttd.proxydiscordlink:ProxyDiscordLink:1.0.0-BETA-SNAPSHOT")
|
||||
compileOnly("com.alttd.proxydiscordlink:ProxyDiscordLink:1.0.0-BETA-SNAPSHOT") {
|
||||
exclude("net.kyori")
|
||||
}
|
||||
|
||||
implementation("mysql:mysql-connector-java:8.0.27") // mysql
|
||||
implementation("org.spongepowered", "configurate-yaml", "4.1.2")
|
||||
implementation("net.kyori", "adventure-text-minimessage", "4.1.0-SNAPSHOT") {
|
||||
exclude("net.kyori")
|
||||
exclude("net.kyori.examination")
|
||||
}
|
||||
// implementation("net.kyori", "adventure-text-minimessage", "4.1.0-SNAPSHOT") {
|
||||
// exclude("net.kyori")
|
||||
// exclude("net.kyori.examination")
|
||||
// }
|
||||
//Luckperms
|
||||
compileOnly("net.luckperms:api:5.3")
|
||||
compileOnly("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT") // Velocity
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
|
@ -27,7 +31,7 @@ tasks {
|
|||
shadowJar {
|
||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
||||
listOf(
|
||||
"net.kyori.adventure.text.minimessage",
|
||||
// "net.kyori.adventure.text.minimessage",
|
||||
"org.spongepowered.configurate"
|
||||
).forEach { relocate(it, "${rootProject.name}.lib.$it") }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.alttd.boosterapi.BoosterType;
|
|||
import com.alttd.boosterapi.config.Config;
|
||||
import com.alttd.boosterapi.util.Utils;
|
||||
import com.alttd.proxydiscordlink.bot.api.DiscordSendMessage;
|
||||
import com.alttd.proxydiscordlink.lib.net.dv8tion.jda.api.entities.templates.Template;
|
||||
import com.alttd.vboosters.VelocityBoosters;
|
||||
import com.alttd.vboosters.data.VelocityBooster;
|
||||
import com.alttd.vboosters.managers.BoosterManager;
|
||||
|
|
@ -24,8 +25,10 @@ import com.velocitypowered.api.proxy.Player;
|
|||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.*;
|
||||
|
|
@ -49,7 +52,7 @@ public class BoosterCommand {
|
|||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
private static MiniMessage miniMessage = MiniMessage.get();
|
||||
private static MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
public BoosterCommand(ProxyServer proxyServer) {
|
||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||
.<CommandSource>literal("booster")
|
||||
|
|
@ -62,25 +65,30 @@ public class BoosterCommand {
|
|||
List<Component> queuedBoosterComponents = new ArrayList<>();
|
||||
for (Booster booster : VelocityBoosterStorage.getVelocityBoosterStorage().getBoosters().values()) {
|
||||
long expiryTime = new Date().getTime() + booster.getDuration();
|
||||
ArrayList<Template> templates = new ArrayList<>(List.of(
|
||||
Template.of("type", booster.getType().getBoosterName()),
|
||||
Template.of("activator", booster.getActivator()),
|
||||
Template.of("start_time", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(booster.getStartingTime())),
|
||||
Template.of("duration", String.valueOf(booster.getDuration())),
|
||||
Template.of("multiplier", String.valueOf(booster.getMultiplier()))));
|
||||
TagResolver.Builder tagResolver = TagResolver.builder();
|
||||
|
||||
List<TagResolver> templates = List.of(
|
||||
Placeholder.unparsed("type", booster.getType().getBoosterName()),
|
||||
Placeholder.unparsed("activator", booster.getActivator()),
|
||||
Placeholder.unparsed("start_time", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(booster.getStartingTime())),
|
||||
Placeholder.unparsed("duration", String.valueOf(booster.getDuration())),
|
||||
Placeholder.unparsed("multiplier", String.valueOf(booster.getMultiplier())));
|
||||
for (TagResolver tagResolver1 : templates)
|
||||
tagResolver.resolver(tagResolver1); // cheaty and lazy way I know
|
||||
|
||||
if (booster.isActive())
|
||||
templates.add(Template.of("end_time", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(expiryTime)));
|
||||
tagResolver.resolver(Placeholder.unparsed("end_time", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(expiryTime)));
|
||||
else
|
||||
templates.add(Template.of("end_time", "unknown"));
|
||||
tagResolver.resolver(Placeholder.unparsed("end_time", "unknown"));
|
||||
if (booster.isActive())
|
||||
activeBoosterComponents.add(miniMessage.parse(activeBooster, templates));
|
||||
activeBoosterComponents.add(miniMessage.deserialize(activeBooster, tagResolver.build()));
|
||||
else if (!booster.finished())
|
||||
queuedBoosterComponents.add(miniMessage.parse(queuedBooster, templates));
|
||||
queuedBoosterComponents.add(miniMessage.deserialize(queuedBooster, tagResolver.build()));
|
||||
}
|
||||
Component separator = miniMessage.parse("\n");
|
||||
context.getSource().sendMessage(miniMessage.parse(message, List.of(
|
||||
Template.of("active_boosters", Component.join(separator, activeBoosterComponents)),
|
||||
Template.of("queued_boosters", Component.join(separator, queuedBoosterComponents))
|
||||
Component separator = miniMessage.deserialize("\n");
|
||||
context.getSource().sendMessage(miniMessage.deserialize(message,TagResolver.resolver(
|
||||
Placeholder.component("active_boosters", Component.join(JoinConfiguration.separator(separator), activeBoosterComponents)),
|
||||
Placeholder.component("queued_boosters", Component.join(JoinConfiguration.separator(separator), queuedBoosterComponents))
|
||||
)));
|
||||
return 1;
|
||||
})
|
||||
|
|
@ -110,7 +118,7 @@ public class BoosterCommand {
|
|||
VelocityBoosters.getPlugin().getBoosterManager().addBooster(new VelocityBooster(boosterType, username, duration, multiplier));
|
||||
String msg = "[" + username + "] purchased booster of type [" + Utils.capitalize(boosterType.getBoosterName()) + "]"; //TODO check if there was a booster active already and change message based on that
|
||||
DiscordSendMessage.sendEmbed(Config.BOOST_ANNOUNCE_CHANNEL, "Booster Purchased", msg);
|
||||
VelocityBoosters.getPlugin().getProxy().sendMessage(MiniMessage.markdown().parse(msg));
|
||||
VelocityBoosters.getPlugin().getProxy().sendMessage(MiniMessage.miniMessage().deserialize(msg));
|
||||
VelocityBoosters.getPlugin().getLogger().info(msg);
|
||||
return 1;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import com.velocitypowered.api.command.CommandSource;
|
|||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.node.Node;
|
||||
|
|
@ -30,7 +30,7 @@ public class DonorRankCommand {
|
|||
private final MiniMessage miniMessage;
|
||||
|
||||
public DonorRankCommand(ProxyServer proxyServer) {
|
||||
miniMessage = MiniMessage.get();
|
||||
miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||
.<CommandSource>literal("donorrank")
|
||||
|
|
@ -83,23 +83,23 @@ public class DonorRankCommand {
|
|||
User user = luckPerms.getUserManager().getUser(username); //TODO test if this works with username
|
||||
|
||||
if (user == null) {
|
||||
commandSource.sendMessage(miniMessage.parse(
|
||||
commandSource.sendMessage(miniMessage.deserialize(
|
||||
Config.INVALID_USER,
|
||||
Template.of("player", username)));
|
||||
Placeholder.unparsed("player", username)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!Config.donorRanks.contains(rank)) {
|
||||
commandSource.sendMessage(miniMessage.parse(
|
||||
commandSource.sendMessage(miniMessage.deserialize(
|
||||
Config.INVALID_DONOR_RANK,
|
||||
Template.of("rank", rank)));
|
||||
Placeholder.unparsed("rank", rank)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case "promote" -> promote(user, rank);
|
||||
case "demote" -> demote(user, rank);
|
||||
default -> commandSource.sendMessage(miniMessage.parse(Config.INVALID_ACTION));
|
||||
default -> commandSource.sendMessage(miniMessage.deserialize(Config.INVALID_ACTION));
|
||||
}
|
||||
return 1;
|
||||
})
|
||||
|
|
@ -129,9 +129,9 @@ public class DonorRankCommand {
|
|||
user.data().add(InheritanceNode.builder(rank).build());
|
||||
VelocityBoosters.getPlugin().getProxy().getPlayer(user.getUniqueId()).ifPresent(player -> {
|
||||
if (player.isActive()) {
|
||||
player.sendMessage(miniMessage.parse(Config.PROMOTE_MESSAGE,
|
||||
Template.of("rank", Utils.capitalize(rank)),
|
||||
Template.of("player", player.getUsername())));
|
||||
player.sendMessage(miniMessage.deserialize(Config.PROMOTE_MESSAGE,
|
||||
Placeholder.unparsed("rank", Utils.capitalize(rank)),
|
||||
Placeholder.unparsed("player", player.getUsername())));
|
||||
}
|
||||
});
|
||||
luckPerms.getUserManager().saveUser(user);
|
||||
|
|
@ -147,9 +147,9 @@ public class DonorRankCommand {
|
|||
});
|
||||
VelocityBoosters.getPlugin().getProxy().getPlayer(user.getUniqueId()).ifPresent(player -> {
|
||||
if (player.isActive()) {
|
||||
player.sendMessage(miniMessage.parse(Config.DEMOTE_MESSAGE,
|
||||
Template.of("rank", Utils.capitalize(rank)),
|
||||
Template.of("player", player.getUsername())));
|
||||
player.sendMessage(miniMessage.deserialize(Config.DEMOTE_MESSAGE,
|
||||
Placeholder.unparsed("rank", Utils.capitalize(rank)),
|
||||
Placeholder.unparsed("player", player.getUsername())));
|
||||
}
|
||||
});
|
||||
luckPerms.getUserManager().saveUser(user);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user