Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Implement adventure title APIs
Dieser Commit ist enthalten in:
Ursprung
5c02d6b007
Commit
c4f143a2bc
@ -51,6 +51,7 @@ import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
|
||||
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
|
||||
import com.velocitypowered.proxy.tablist.VelocityTabList;
|
||||
import com.velocitypowered.proxy.tablist.VelocityTabListLegacy;
|
||||
import com.velocitypowered.proxy.util.DurationUtils;
|
||||
import com.velocitypowered.proxy.util.VelocityMessages;
|
||||
import com.velocitypowered.proxy.util.collect.CappedSet;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
@ -279,6 +280,39 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showTitle(net.kyori.adventure.title.@NonNull Title title) {
|
||||
Gson gson = VelocityServer.getGsonInstance(this.getProtocolVersion());
|
||||
|
||||
TitlePacket titlePkt = new TitlePacket();
|
||||
titlePkt.setAction(TitlePacket.SET_TITLE);
|
||||
titlePkt.setComponent(gson.toJson(title.title()));
|
||||
connection.delayedWrite(titlePkt);
|
||||
|
||||
TitlePacket subtitlePkt = new TitlePacket();
|
||||
subtitlePkt.setAction(TitlePacket.SET_SUBTITLE);
|
||||
subtitlePkt.setComponent(gson.toJson(title.subtitle()));
|
||||
connection.delayedWrite(titlePkt);
|
||||
|
||||
TitlePacket timesPkt = TitlePacket.timesForProtocolVersion(this.getProtocolVersion());
|
||||
timesPkt.setFadeIn((int) DurationUtils.convertDurationToTicks(title.fadeInTime()));
|
||||
timesPkt.setStay((int) DurationUtils.convertDurationToTicks(title.stayTime()));
|
||||
timesPkt.setFadeOut((int) DurationUtils.convertDurationToTicks(title.fadeOutTime()));
|
||||
connection.delayedWrite(timesPkt);
|
||||
|
||||
connection.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearTitle() {
|
||||
connection.write(TitlePacket.hideForProtocolVersion(this.getProtocolVersion()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTitle() {
|
||||
connection.write(TitlePacket.resetForProtocolVersion(this.getProtocolVersion()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionRequestBuilder createConnectionRequest(RegisteredServer server) {
|
||||
return new ConnectionRequestBuilderImpl(server);
|
||||
|
@ -25,7 +25,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.velocitypowered.proxy.util;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* Provides utility functions for working with durations.
|
||||
*/
|
||||
public class DurationUtils {
|
||||
private static final long ONE_TICK_IN_MILLISECONDS = 50;
|
||||
|
||||
private DurationUtils() {
|
||||
throw new AssertionError("Instances of this class should not be created.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given duration to Minecraft ticks.
|
||||
*
|
||||
* @param duration the duration to convert into Minecraft ticks
|
||||
* @return the duration represented as the number of Minecraft ticks
|
||||
*/
|
||||
public static long convertDurationToTicks(Duration duration) {
|
||||
return duration.toMillis() / ONE_TICK_IN_MILLISECONDS;
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren