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