diff --git a/module/hologram-integration/src/main/java/org/battleplugins/arena/module/hologram/decentholograms/DecentHologram.java b/module/hologram-integration/src/main/java/org/battleplugins/arena/module/hologram/decentholograms/DecentHologram.java index 4a115888..94a3df81 100644 --- a/module/hologram-integration/src/main/java/org/battleplugins/arena/module/hologram/decentholograms/DecentHologram.java +++ b/module/hologram-integration/src/main/java/org/battleplugins/arena/module/hologram/decentholograms/DecentHologram.java @@ -4,20 +4,15 @@ import eu.decentsoftware.holograms.api.holograms.HologramPage; import eu.decentsoftware.holograms.api.holograms.enums.HologramLineType; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.battleplugins.arena.competition.LiveCompetition; import org.battleplugins.arena.feature.hologram.Hologram; +import org.battleplugins.arena.util.Util; import org.bukkit.Location; import java.util.ArrayList; import java.util.List; public class DecentHologram implements Hologram { - private static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder() - .hexColors() - .useUnusualXRepeatedCharacterHexFormat() - .build(); - private final LiveCompetition competition; private final eu.decentsoftware.holograms.api.holograms.Hologram impl; @@ -47,7 +42,7 @@ public List getLines() { List lines = new ArrayList<>(); for (HologramLine line : page.getLines()) { if (line.getType() == HologramLineType.TEXT) { - lines.add(SERIALIZER.deserialize(line.getText())); + lines.add(Util.deserializeFromLegacy(line.getText())); } } @@ -66,7 +61,7 @@ public void setLines(Component... lines) { } for (Component line : lines) { - page.addLine(new HologramLine(page, this.getLocation(), SERIALIZER.serialize(line))); + page.addLine(new HologramLine(page, this.getLocation(), Util.serializeToLegacy(line))); } } @@ -77,7 +72,7 @@ public void addLine(Component line) { } HologramPage page = this.impl.getPage(0); - page.addLine(new HologramLine(page, this.getLocation(), SERIALIZER.serialize(line))); + page.addLine(new HologramLine(page, this.getLocation(), Util.serializeToLegacy(line))); } @Override diff --git a/module/placeholderapi-integration/src/main/java/org/battleplugins/arena/module/placeholderapi/BattleArenaExpansion.java b/module/placeholderapi-integration/src/main/java/org/battleplugins/arena/module/placeholderapi/BattleArenaExpansion.java index 9695fa1d..063730bb 100644 --- a/module/placeholderapi-integration/src/main/java/org/battleplugins/arena/module/placeholderapi/BattleArenaExpansion.java +++ b/module/placeholderapi-integration/src/main/java/org/battleplugins/arena/module/placeholderapi/BattleArenaExpansion.java @@ -1,17 +1,19 @@ package org.battleplugins.arena.module.placeholderapi; import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import net.kyori.adventure.text.Component; import org.battleplugins.arena.Arena; import org.battleplugins.arena.ArenaPlayer; import org.battleplugins.arena.BattleArena; import org.battleplugins.arena.competition.Competition; import org.battleplugins.arena.competition.LiveCompetition; -import org.battleplugins.arena.competition.map.CompetitionMap; -import org.battleplugins.arena.competition.map.LiveCompetitionMap; import org.battleplugins.arena.competition.phase.CompetitionPhaseType; +import org.battleplugins.arena.messages.Messages; import org.battleplugins.arena.resolver.Resolver; import org.battleplugins.arena.resolver.ResolverKey; import org.battleplugins.arena.resolver.ResolverKeys; +import org.battleplugins.arena.team.ArenaTeam; +import org.battleplugins.arena.util.Util; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -58,6 +60,37 @@ public BattleArenaExpansion(BattleArena plugin) { if (resolverKey != null && resolver.has(resolverKey)) { return resolver.resolveToString(resolverKey); } + + // Additional placeholders for competition + switch (placeholder) { + case "team_color": { + ArenaTeam team = arenaPlayer.getTeam(); + if (team != null) { + return team.getTextColor().asHexString(); + } + } + case "team_color_legacy": { + ArenaTeam team = arenaPlayer.getTeam(); + if (team != null) { + Component teamColor = Component.empty().color(team.getTextColor()); + return Util.serializeToLegacy(teamColor); + } + } + case "formatted_team_name": { + ArenaTeam team = arenaPlayer.getTeam(); + if (team != null) { + Component teamName = team.getFormattedName(); + return Messages.wrap(teamName).asPlainText(); + } + } + case "formatted_team_name_legacy": { + ArenaTeam team = arenaPlayer.getTeam(); + if (team != null) { + Component teamName = team.getFormattedName(); + return Util.serializeToLegacy(teamName); + } + } + } } // If player is null or no other placeholder resolvers have made it to this point, diff --git a/plugin/src/main/java/org/battleplugins/arena/messages/Message.java b/plugin/src/main/java/org/battleplugins/arena/messages/Message.java index 72ab6074..7ad09a45 100644 --- a/plugin/src/main/java/org/battleplugins/arena/messages/Message.java +++ b/plugin/src/main/java/org/battleplugins/arena/messages/Message.java @@ -86,6 +86,10 @@ public String asPlainText() { return PlainTextComponentSerializer.plainText().serialize(this.toComponent()); } + public String asMiniMessage() { + return Messages.MINI_MESSAGE.serialize(this.toComponent()); + } + public Component toComponent() { return this.text; } diff --git a/plugin/src/main/java/org/battleplugins/arena/messages/Messages.java b/plugin/src/main/java/org/battleplugins/arena/messages/Messages.java index 1e53ee73..694f1ba3 100644 --- a/plugin/src/main/java/org/battleplugins/arena/messages/Messages.java +++ b/plugin/src/main/java/org/battleplugins/arena/messages/Messages.java @@ -168,6 +168,10 @@ public static Message wrap(String defaultText) { return new Message("unregistered", MINI_MESSAGE.deserialize(defaultText, RESOLVER)); } + public static Message wrap(Component defaultComponent) { + return new Message("unregistered", defaultComponent); + } + public static Message info(String translationKey, String defaultText) { return message(translationKey, MINI_MESSAGE.deserialize(defaultText, RESOLVER).color(PRIMARY_COLOR)); } diff --git a/plugin/src/main/java/org/battleplugins/arena/util/Util.java b/plugin/src/main/java/org/battleplugins/arena/util/Util.java index c79f4b7f..681c011d 100644 --- a/plugin/src/main/java/org/battleplugins/arena/util/Util.java +++ b/plugin/src/main/java/org/battleplugins/arena/util/Util.java @@ -1,8 +1,11 @@ package org.battleplugins.arena.util; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.battleplugins.arena.BattleArena; import org.battleplugins.arena.config.ArenaOption; import org.battleplugins.arena.messages.Messages; +import org.jetbrains.annotations.ApiStatus; import java.io.File; import java.io.IOException; @@ -21,6 +24,36 @@ import java.util.stream.Stream; public class Util { + private static final LegacyComponentSerializer LEGACY_SERIALIZER = LegacyComponentSerializer.builder() + .hexColors() + .useUnusualXRepeatedCharacterHexFormat() + .build(); + + /** + * Serializes a component to a legacy string. + *

+ * This method is internal and should not be used by other plugins. + * + * @param component the component to serialize + * @return the serialized component + */ + @ApiStatus.Internal + public static String serializeToLegacy(Component component) { + return LEGACY_SERIALIZER.serialize(component); + } + + /** + * Deserializes a legacy string to a component. + *

+ * This method is internal and should not be used by other plugins. + * + * @param legacy the legacy string to deserialize + * @return the deserialized component + */ + @ApiStatus.Internal + public static Component deserializeFromLegacy(String legacy) { + return LEGACY_SERIALIZER.deserialize(legacy); + } public static String toTimeStringShort(Duration duration) { long seconds = duration.getSeconds();