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,11 +330,14 @@ 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");
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
this.connection.write(HeaderAndFooter.create(header, footer, this.getProtocolVersion())); 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) {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this
.getProtocolVersion()); .getProtocolVersion());
@ -359,26 +362,35 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
connection.flush(); connection.flush();
} }
}
@Override @Override
public void clearTitle() { public void clearTitle() {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
connection.write(TitlePacket.hideForProtocolVersion(this.getProtocolVersion())); connection.write(TitlePacket.hideForProtocolVersion(this.getProtocolVersion()));
} }
}
@Override @Override
public void resetTitle() { public void resetTitle() {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
connection.write(TitlePacket.resetForProtocolVersion(this.getProtocolVersion())); connection.write(TitlePacket.resetForProtocolVersion(this.getProtocolVersion()));
} }
}
@Override @Override
public void hideBossBar(@NonNull BossBar bar) { public void hideBossBar(@NonNull BossBar bar) {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
this.server.getBossBarManager().removeBossBar(this, bar); this.server.getBossBarManager().removeBossBar(this, bar);
} }
}
@Override @Override
public void showBossBar(@NonNull BossBar bar) { public void showBossBar(@NonNull BossBar bar) {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
this.server.getBossBarManager().addBossBar(this, bar); this.server.getBossBarManager().addBossBar(this, bar);
} }
}
@Override @Override
public ConnectionRequestBuilder createConnectionRequest(RegisteredServer server) { public ConnectionRequestBuilder createConnectionRequest(RegisteredServer server) {
@ -835,11 +847,13 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
public void sendResourcePack(String url) { public void sendResourcePack(String url) {
Preconditions.checkNotNull(url, "url"); Preconditions.checkNotNull(url, "url");
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
ResourcePackRequest request = new ResourcePackRequest(); ResourcePackRequest request = new ResourcePackRequest();
request.setUrl(url); request.setUrl(url);
request.setHash(""); request.setHash("");
connection.write(request); connection.write(request);
} }
}
@Override @Override
public void sendResourcePack(String url, byte[] hash) { public void sendResourcePack(String url, byte[] hash) {
@ -847,11 +861,13 @@ 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");
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
ResourcePackRequest request = new ResourcePackRequest(); ResourcePackRequest request = new ResourcePackRequest();
request.setUrl(url); request.setUrl(url);
request.setHash(ByteBufUtil.hexDump(hash)); request.setHash(ByteBufUtil.hexDump(hash));
connection.write(request); connection.write(request);
} }
}
/** /**
* Sends a {@link KeepAlive} packet to the player with a random ID. * Sends a {@link KeepAlive} packet to the player with a random ID.