Fix ResourcePackSendPacket

This commit is contained in:
TheMode 2021-06-19 17:44:11 +02:00
parent 731a1006a7
commit 15cfea6f9a
2 changed files with 15 additions and 4 deletions

View File

@ -13,7 +13,7 @@ public class ResourcePackSendPacket implements ServerPacket {
public String url = "";
public String hash = "0000000000000000000000000000000000000000"; // Size 40
public boolean forced;
public Component forcedMessage = Component.empty();
public Component forcedMessage;
public ResourcePackSendPacket() {
}
@ -30,8 +30,11 @@ public class ResourcePackSendPacket implements ServerPacket {
writer.writeSizedString(url);
writer.writeSizedString(hash);
writer.writeBoolean(forced);
if (forced) {
if (forcedMessage != null) {
writer.writeBoolean(true);
writer.writeComponent(forcedMessage);
} else {
writer.writeBoolean(false);
}
}
@ -40,8 +43,12 @@ public class ResourcePackSendPacket implements ServerPacket {
this.url = reader.readSizedString();
this.hash = reader.readSizedString();
this.forced = reader.readBoolean();
if (forced) {
final boolean hasMessage = reader.readBoolean();
if (hasMessage) {
this.forcedMessage = reader.readComponent();
} else {
this.forcedMessage = null;
}
}

View File

@ -35,10 +35,14 @@ public class ResourcePack {
return new ResourcePack(url, hash);
}
public static ResourcePack forced(@NotNull String url, @Nullable String hash, @NotNull Component forcedMessage) {
public static ResourcePack forced(@NotNull String url, @Nullable String hash, @Nullable Component forcedMessage) {
return new ResourcePack(url, hash, true, forcedMessage);
}
public static ResourcePack forced(@NotNull String url, @Nullable String hash) {
return forced(url, hash, null);
}
/**
* Gets the resource pack URL.
*