mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 03:27:56 +01:00
Add ResourcePack#optional overload to specify prompt (#600)
This commit is contained in:
parent
e0e5fe049d
commit
2d305cb0f0
@ -9,7 +9,7 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public record ResourcePackSendPacket(String url, String hash, boolean forced,
|
public record ResourcePackSendPacket(String url, String hash, boolean forced,
|
||||||
Component forcedMessage) implements ServerPacket {
|
Component prompt) implements ServerPacket {
|
||||||
public ResourcePackSendPacket(BinaryReader reader) {
|
public ResourcePackSendPacket(BinaryReader reader) {
|
||||||
this(reader.readSizedString(), reader.readSizedString(), reader.readBoolean(),
|
this(reader.readSizedString(), reader.readSizedString(), reader.readBoolean(),
|
||||||
reader.readBoolean() ? reader.readComponent() : null);
|
reader.readBoolean() ? reader.readComponent() : null);
|
||||||
@ -17,7 +17,7 @@ public record ResourcePackSendPacket(String url, String hash, boolean forced,
|
|||||||
|
|
||||||
public ResourcePackSendPacket(@NotNull ResourcePack resourcePack) {
|
public ResourcePackSendPacket(@NotNull ResourcePack resourcePack) {
|
||||||
this(resourcePack.getUrl(), resourcePack.getHash(), resourcePack.isForced(),
|
this(resourcePack.getUrl(), resourcePack.getHash(), resourcePack.isForced(),
|
||||||
resourcePack.getForcedMessage());
|
resourcePack.getPrompt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -25,9 +25,9 @@ public record ResourcePackSendPacket(String url, String hash, boolean forced,
|
|||||||
writer.writeSizedString(url);
|
writer.writeSizedString(url);
|
||||||
writer.writeSizedString(hash);
|
writer.writeSizedString(hash);
|
||||||
writer.writeBoolean(forced);
|
writer.writeBoolean(forced);
|
||||||
if (forcedMessage != null) {
|
if (prompt != null) {
|
||||||
writer.writeBoolean(true);
|
writer.writeBoolean(true);
|
||||||
writer.writeComponent(forcedMessage);
|
writer.writeComponent(prompt);
|
||||||
} else {
|
} else {
|
||||||
writer.writeBoolean(false);
|
writer.writeBoolean(false);
|
||||||
}
|
}
|
||||||
|
@ -13,22 +13,26 @@ public class ResourcePack {
|
|||||||
private final String url;
|
private final String url;
|
||||||
private final String hash;
|
private final String hash;
|
||||||
private final boolean forced;
|
private final boolean forced;
|
||||||
private final Component forcedMessage;
|
private final Component prompt;
|
||||||
|
|
||||||
private ResourcePack(@NotNull String url, @Nullable String hash, boolean forced, @Nullable Component forcedMessage) {
|
private ResourcePack(@NotNull String url, @Nullable String hash, boolean forced, @Nullable Component prompt) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
// Optional, set to empty if null
|
// Optional, set to empty if null
|
||||||
this.hash = hash == null ? "" : hash;
|
this.hash = hash == null ? "" : hash;
|
||||||
this.forced = forced;
|
this.forced = forced;
|
||||||
this.forcedMessage = forcedMessage;
|
this.prompt = prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResourcePack optional(@NotNull String url, @Nullable String hash, @Nullable Component prompt) {
|
||||||
|
return new ResourcePack(url, hash, false, prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourcePack optional(@NotNull String url, @Nullable String hash) {
|
public static ResourcePack optional(@NotNull String url, @Nullable String hash) {
|
||||||
return new ResourcePack(url, hash, false, null);
|
return optional(url, hash, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourcePack forced(@NotNull String url, @Nullable String hash, @Nullable Component forcedMessage) {
|
public static ResourcePack forced(@NotNull String url, @Nullable String hash, @Nullable Component prompt) {
|
||||||
return new ResourcePack(url, hash, true, forcedMessage);
|
return new ResourcePack(url, hash, true, prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourcePack forced(@NotNull String url, @Nullable String hash) {
|
public static ResourcePack forced(@NotNull String url, @Nullable String hash) {
|
||||||
@ -60,7 +64,7 @@ public class ResourcePack {
|
|||||||
return forced;
|
return forced;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Component getForcedMessage() {
|
public @Nullable Component getPrompt() {
|
||||||
return forcedMessage;
|
return prompt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user