Fix links in chat not clickable

This commit is contained in:
Lixfel
2024-11-30 10:31:49 +01:00
parent 996e4932d7
commit 2032a0b642
4 changed files with 14 additions and 15 deletions
@@ -26,9 +26,9 @@ import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import de.steamwar.persistent.Servertype;
import de.steamwar.persistent.Subserver;
import de.steamwar.velocitycore.VelocityCore;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;
import de.steamwar.velocitycore.VelocityCore;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
@@ -47,6 +47,7 @@ import java.util.function.Supplier;
import java.util.stream.Stream;
public interface Chatter {
LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder().extractUrls().build();
static Stream<Player> allPlayers() {
return VelocityCore.getProxy().getAllPlayers().stream();
@@ -138,7 +139,7 @@ public interface Chatter {
}
default String parseToLegacy(Message message) {
return LegacyComponentSerializer.legacySection().serialize(parse(message));
return SERIALIZER.serialize(parse(message));
}
default Component parse(String format, Object... params) {
@@ -178,7 +179,7 @@ public interface Chatter {
params[i] = func.apply(this);
}
}
return LegacyComponentSerializer.legacySection().deserialize(format.format(params));
return SERIALIZER.deserialize(format.format(params));
}
static PlayerChatter of(Player player) {
@@ -20,18 +20,17 @@
package de.steamwar.velocitycore.mods;
import com.velocitypowered.api.proxy.Player;
import de.steamwar.sql.Punishment;
import de.steamwar.velocitycore.VelocityCore;
import de.steamwar.velocitycore.commands.PunishmentCommand;
import de.steamwar.messages.Chatter;
import de.steamwar.sql.Mod;
import de.steamwar.sql.Mod.ModType;
import de.steamwar.sql.Punishment;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;
import de.steamwar.velocitycore.VelocityCore;
import de.steamwar.velocitycore.commands.PunishmentCommand;
import lombok.Getter;
import lombok.experimental.UtilityClass;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import java.sql.Timestamp;
import java.time.Instant;
@@ -88,7 +87,7 @@ public class ModUtils {
VelocityCore.getLogger().log(Level.SEVERE, "%s %s wurde automatisch wegen der Mods %s gebannt.".formatted(user.getUserName(), user.getId(), modList));
}
disconnect.accept(LegacyComponentSerializer.legacySection().deserialize(message));
disconnect.accept(Chatter.SERIALIZER.deserialize(message));
return false;
}
}
@@ -20,6 +20,7 @@
package de.steamwar.velocitycore.network.handlers;
import com.velocitypowered.api.proxy.Player;
import de.steamwar.messages.Chatter;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.network.packets.common.FightEndsPacket;
import de.steamwar.sql.SchematicType;
@@ -29,7 +30,6 @@ import de.steamwar.velocitycore.ArenaMode;
import de.steamwar.velocitycore.VelocityCore;
import lombok.RequiredArgsConstructor;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.title.Title;
import java.time.Duration;
@@ -186,10 +186,10 @@ public class EloPlayerHandler extends PacketHandler {
double eloStep = eloGain / 40.0;
for (int i = 0; i < 40; i++) {
Component eloGainComponent = LegacyComponentSerializer.legacySection().deserialize(color + (int) (eloStep * (i + 1)));
Component eloGainComponent = Chatter.SERIALIZER.deserialize(color + (int) (eloStep * (i + 1)));
int finalI = i;
VelocityCore.schedule(() -> player.showTitle(Title.title(
LegacyComponentSerializer.legacySection().deserialize(getRankup.apply(finalI)),
Chatter.SERIALIZER.deserialize(getRankup.apply(finalI)),
eloGainComponent,
Title.Times.times(Duration.ofMillis(finalI == 0 ? 250 : 0), Duration.ofSeconds(2), Duration.ofMillis(finalI == 39 ? 250 : 0))
))).delay(i * 50L, TimeUnit.MILLISECONDS).schedule();
@@ -26,7 +26,6 @@ import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import java.util.List;
import java.util.UUID;
@@ -43,7 +42,7 @@ public interface TablistPart {
public Item(UUID uuid, String displayName, List<GameProfile.Property> properties) {
this.uuid = uuid;
this.displayName = LegacyComponentSerializer.legacySection().deserialize(displayName);
this.displayName = Chatter.SERIALIZER.deserialize(displayName);
this.properties = properties;
}
@@ -55,9 +54,9 @@ public interface TablistPart {
this.uuid = player.getUniqueId();
UserPerm.Prefix prefix = SteamwarUser.get(player.getUniqueId()).prefix();
if (prefix == UserPerm.emptyPrefix && sameTeam) {
this.displayName = LegacyComponentSerializer.legacySection().deserialize("§f" + player.getUsername());
this.displayName = Chatter.SERIALIZER.deserialize("§f" + player.getUsername());
} else {
this.displayName = LegacyComponentSerializer.legacySection().deserialize(prefix.getColorCode() + player.getUsername());
this.displayName = Chatter.SERIALIZER.deserialize(prefix.getColorCode() + player.getUsername());
}
this.properties = player.getGameProfileProperties();
}