SPIGOT-6789: Improve resource pack related API

By: Patrick Choe <mailpatrickkr@gmail.com>
This commit is contained in:
CraftBukkit/Spigot 2021-12-18 11:46:17 +11:00
parent 3736fd83de
commit edea21b253
2 changed files with 45 additions and 7 deletions

View File

@ -36,6 +36,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@ -670,6 +671,26 @@ public final class CraftServer implements Server {
return this.configuration.getBoolean("settings.query-plugins");
}
@Override
public String getResourcePack() {
return this.getServer().getResourcePack();
}
@Override
public String getResourcePackHash() {
return this.getServer().getResourcePackHash().toUpperCase(Locale.ROOT);
}
@Override
public String getResourcePackPrompt() {
return CraftChatMessage.fromComponent(this.getServer().getResourcePackPrompt());
}
@Override
public boolean isResourcePackRequired() {
return this.getServer().isResourcePackRequired();
}
@Override
public boolean hasWhitelist() {
return this.getProperties().whiteList.get();

View File

@ -1306,18 +1306,35 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public void setResourcePack(String url) {
Validate.notNull(url, "Resource pack URL cannot be null");
getHandle().sendTexturePack(url, "null", false, null);
setResourcePack(url, null);
}
@Override
public void setResourcePack(String url, byte[] hash) {
Validate.notNull(url, "Resource pack URL cannot be null");
Validate.notNull(hash, "Resource pack hash cannot be null");
Validate.isTrue(hash.length == 20, "Resource pack hash should be 20 bytes long but was " + hash.length);
setResourcePack(url, hash, false);
}
getHandle().sendTexturePack(url, BaseEncoding.base16().lowerCase().encode(hash), false, null);
@Override
public void setResourcePack(String url, byte[] hash, String prompt) {
setResourcePack(url, hash, prompt, false);
}
@Override
public void setResourcePack(String url, byte[] hash, boolean force) {
setResourcePack(url, hash, null, force);
}
@Override
public void setResourcePack(String url, byte[] hash, String prompt, boolean force) {
Validate.notNull(url, "Resource pack URL cannot be null");
if (hash != null) {
Validate.isTrue(hash.length == 20, "Resource pack hash should be 20 bytes long but was " + hash.length);
getHandle().sendTexturePack(url, BaseEncoding.base16().lowerCase().encode(hash), force, CraftChatMessage.fromStringOrNull(prompt, true));
} else {
getHandle().sendTexturePack(url, "", force, CraftChatMessage.fromStringOrNull(prompt, true));
}
}
public void addChannel(String channel) {