forked from Upstream/Velocitab
first test
This commit is contained in:
parent
c8af05d9be
commit
1be3c47d9c
@ -43,7 +43,7 @@ public enum Formatter {
|
||||
MINIMESSAGE(
|
||||
(text, player, plugin) -> plugin.getMiniPlaceholdersHook()
|
||||
.map(hook -> hook.format(text, player.getPlayer()))
|
||||
.orElse(MiniMessage.miniMessage().deserialize(text)),
|
||||
.orElse(MiniMessage.miniMessage().deserialize(parseSections(text))),
|
||||
(text) -> MiniMessage.miniMessage().escapeTags(text),
|
||||
"MiniMessage"
|
||||
),
|
||||
@ -94,4 +94,26 @@ public enum Formatter {
|
||||
return name;
|
||||
}
|
||||
|
||||
private static String replaceAmpersandCodesWithSection(String text) {
|
||||
char[] b = text.toCharArray();
|
||||
for (int i = 0; i < b.length - 1; i++) {
|
||||
if (b[i] == '&' && "0123456789AaBbCcDdEeFfKkLlMmNnOoRrXx#".indexOf(b[i + 1]) > -1) {
|
||||
b[i] = '§';
|
||||
b[i + 1] = Character.toLowerCase(b[i + 1]);
|
||||
}
|
||||
}
|
||||
return new String(b);
|
||||
}
|
||||
|
||||
public static String parseSections(String text) {
|
||||
String value = MiniMessage.miniMessage().serialize(
|
||||
LegacyComponentSerializer.legacySection().deserialize(
|
||||
replaceAmpersandCodesWithSection(text)))
|
||||
.replace("\\<", "<");
|
||||
return MiniMessage.miniMessage().serialize(
|
||||
LegacyComponentSerializer.legacySection().deserialize(
|
||||
replaceAmpersandCodesWithSection(text)))
|
||||
.replace("\\<", "<");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.william278.velocitab.Velocitab;
|
||||
import net.william278.velocitab.config.Formatter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MiniPlaceholdersHook extends Hook {
|
||||
@ -34,7 +35,7 @@ public class MiniPlaceholdersHook extends Hook {
|
||||
|
||||
@NotNull
|
||||
public Component format(@NotNull String text, @NotNull Audience player) {
|
||||
return MiniMessage.miniMessage().deserialize(text, MiniPlaceholders.getAudienceGlobalPlaceholders(player));
|
||||
return MiniMessage.miniMessage().deserialize(Formatter.parseSections(text), MiniPlaceholders.getAudienceGlobalPlaceholders(player));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public class UpdateTeamsPacket implements MinecraftPacket {
|
||||
.mode(UpdateMode.CREATE_TEAM)
|
||||
.displayName(displayName)
|
||||
.friendlyFlags(List.of(FriendlyFlag.CAN_HURT_FRIENDLY))
|
||||
.nameTagVisibility(NameTagVisibility.ALWAYS)
|
||||
.nameTagVisibility(isNametagPresent(prefix, suffix) ? NameTagVisibility.ALWAYS : NameTagVisibility.NEVER)
|
||||
.collisionRule(CollisionRule.ALWAYS)
|
||||
.color(getLastColor(prefix))
|
||||
.prefix(prefix == null ? "" : prefix)
|
||||
@ -77,6 +77,10 @@ public class UpdateTeamsPacket implements MinecraftPacket {
|
||||
.entities(Arrays.asList(teamMembers));
|
||||
}
|
||||
|
||||
private static boolean isNametagPresent(@Nullable String prefix, @Nullable String suffix) {
|
||||
return prefix != null && !prefix.isEmpty() || suffix != null && !suffix.isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static UpdateTeamsPacket changeNameTag(@NotNull Velocitab plugin, @NotNull String teamName,
|
||||
@Nullable String prefix, @Nullable String suffix) {
|
||||
@ -85,7 +89,7 @@ public class UpdateTeamsPacket implements MinecraftPacket {
|
||||
.mode(UpdateMode.UPDATE_INFO)
|
||||
.displayName(teamName)
|
||||
.friendlyFlags(List.of(FriendlyFlag.CAN_HURT_FRIENDLY))
|
||||
.nameTagVisibility(NameTagVisibility.ALWAYS)
|
||||
.nameTagVisibility(isNametagPresent(prefix, suffix) ? NameTagVisibility.ALWAYS : NameTagVisibility.NEVER)
|
||||
.collisionRule(CollisionRule.ALWAYS)
|
||||
.color(getLastColor(prefix))
|
||||
.prefix(prefix == null ? "" : prefix)
|
||||
|
Loading…
Reference in New Issue
Block a user