13
0
geforkt von Mirrors/Velocity

Turn some APIs into no-ops if they apply to clients without the relevant client functionality.

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-02-07 15:19:59 -05:00
Ursprung b88c573eb1
Commit 7e42c5b2e7

Datei anzeigen

@ -330,54 +330,66 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
public void sendPlayerListHeaderAndFooter(final Component header, final Component footer) { public void sendPlayerListHeaderAndFooter(final Component header, final Component footer) {
this.playerListHeader = Objects.requireNonNull(header, "header"); this.playerListHeader = Objects.requireNonNull(header, "header");
this.playerListFooter = Objects.requireNonNull(footer, "footer"); this.playerListFooter = Objects.requireNonNull(footer, "footer");
this.connection.write(HeaderAndFooter.create(header, footer, this.getProtocolVersion())); if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
this.connection.write(HeaderAndFooter.create(header, footer, this.getProtocolVersion()));
}
} }
@Override @Override
public void showTitle(net.kyori.adventure.title.@NonNull Title title) { public void showTitle(net.kyori.adventure.title.@NonNull Title title) {
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
.getProtocolVersion()); GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this
.getProtocolVersion());
TitlePacket titlePkt = new TitlePacket(); TitlePacket titlePkt = new TitlePacket();
titlePkt.setAction(TitlePacket.SET_TITLE); titlePkt.setAction(TitlePacket.SET_TITLE);
titlePkt.setComponent(serializer.serialize(title.title())); titlePkt.setComponent(serializer.serialize(title.title()));
connection.delayedWrite(titlePkt); connection.delayedWrite(titlePkt);
TitlePacket subtitlePkt = new TitlePacket(); TitlePacket subtitlePkt = new TitlePacket();
subtitlePkt.setAction(TitlePacket.SET_SUBTITLE); subtitlePkt.setAction(TitlePacket.SET_SUBTITLE);
subtitlePkt.setComponent(serializer.serialize(title.subtitle())); subtitlePkt.setComponent(serializer.serialize(title.subtitle()));
connection.delayedWrite(subtitlePkt); connection.delayedWrite(subtitlePkt);
TitlePacket timesPkt = TitlePacket.timesForProtocolVersion(this.getProtocolVersion()); TitlePacket timesPkt = TitlePacket.timesForProtocolVersion(this.getProtocolVersion());
net.kyori.adventure.title.Title.Times times = title.times(); net.kyori.adventure.title.Title.Times times = title.times();
if (times != null) { if (times != null) {
timesPkt.setFadeIn((int) DurationUtils.toTicks(times.fadeIn())); timesPkt.setFadeIn((int) DurationUtils.toTicks(times.fadeIn()));
timesPkt.setStay((int) DurationUtils.toTicks(times.stay())); timesPkt.setStay((int) DurationUtils.toTicks(times.stay()));
timesPkt.setFadeOut((int) DurationUtils.toTicks(times.fadeOut())); timesPkt.setFadeOut((int) DurationUtils.toTicks(times.fadeOut()));
}
connection.delayedWrite(timesPkt);
connection.flush();
} }
connection.delayedWrite(timesPkt);
connection.flush();
} }
@Override @Override
public void clearTitle() { public void clearTitle() {
connection.write(TitlePacket.hideForProtocolVersion(this.getProtocolVersion())); if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
connection.write(TitlePacket.hideForProtocolVersion(this.getProtocolVersion()));
}
} }
@Override @Override
public void resetTitle() { public void resetTitle() {
connection.write(TitlePacket.resetForProtocolVersion(this.getProtocolVersion())); if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
connection.write(TitlePacket.resetForProtocolVersion(this.getProtocolVersion()));
}
} }
@Override @Override
public void hideBossBar(@NonNull BossBar bar) { public void hideBossBar(@NonNull BossBar bar) {
this.server.getBossBarManager().removeBossBar(this, bar); if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
this.server.getBossBarManager().removeBossBar(this, bar);
}
} }
@Override @Override
public void showBossBar(@NonNull BossBar bar) { public void showBossBar(@NonNull BossBar bar) {
this.server.getBossBarManager().addBossBar(this, bar); if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
this.server.getBossBarManager().addBossBar(this, bar);
}
} }
@Override @Override
@ -835,10 +847,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
public void sendResourcePack(String url) { public void sendResourcePack(String url) {
Preconditions.checkNotNull(url, "url"); Preconditions.checkNotNull(url, "url");
ResourcePackRequest request = new ResourcePackRequest(); if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
request.setUrl(url); ResourcePackRequest request = new ResourcePackRequest();
request.setHash(""); request.setUrl(url);
connection.write(request); request.setHash("");
connection.write(request);
}
} }
@Override @Override
@ -847,10 +861,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
Preconditions.checkNotNull(hash, "hash"); Preconditions.checkNotNull(hash, "hash");
Preconditions.checkArgument(hash.length == 20, "Hash length is not 20"); Preconditions.checkArgument(hash.length == 20, "Hash length is not 20");
ResourcePackRequest request = new ResourcePackRequest(); if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
request.setUrl(url); ResourcePackRequest request = new ResourcePackRequest();
request.setHash(ByteBufUtil.hexDump(hash)); request.setUrl(url);
connection.write(request); request.setHash(ByteBufUtil.hexDump(hash));
connection.write(request);
}
} }
/** /**