Skip to content

Commit

Permalink
patches to resourcepack from testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 18, 2021
1 parent 1c4df1f commit 75e6914
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
Expand Up @@ -69,6 +69,11 @@ public void setSignLine(Sign sign, int line, String text) {

@Override
public void sendResourcePack(Player player, String url, String hash, boolean forced, String prompt) {
player.setResourcePack(url, hash == null ? null : CoreUtilities.toLowerCase(hash), forced, prompt == null ? null : PaperModule.parseFormattedText(prompt, ChatColor.WHITE));
if (prompt == null && !forced) {
super.sendResourcePack(player, url, hash, false, null);
}
else {
player.setResourcePack(url, CoreUtilities.toLowerCase(hash), forced, PaperModule.parseFormattedText(prompt, ChatColor.WHITE));
}
}
}
Expand Up @@ -19,15 +19,15 @@ public class ResourcePackCommand extends AbstractCommand {

public ResourcePackCommand() {
setName("resourcepack");
setSyntax("resourcepack [url:<url>] (hash:<hash>) (forced) (prompt:<text>) (target:<player>|...)");
setRequiredArguments(1, 5);
setSyntax("resourcepack [url:<url>] [hash:<hash>] (forced) (prompt:<text>) (target:<player>|...)");
setRequiredArguments(2, 5);
isProcedural = false;
}

// <--[command]
// @Name ResourcePack
// @Syntax resourcepack [url:<url>] (hash:<hash>) (forced) (prompt:<text>) (target:<player>|...)
// @Required 1
// @Syntax resourcepack [url:<url>] [hash:<hash>] (forced) (prompt:<text>) (target:<player>|...)
// @Required 2
// @Maximum 5
// @Short Prompts a player to download a server resource pack.
// @group player
Expand All @@ -39,8 +39,9 @@ public ResourcePackCommand() {
// Once a player says "yes" once, all future packs will be automatically downloaded. If the player selects "no" once, all future packs will automatically be rejected.
// Players can change the automatic setting from their server list in the main menu.
//
// Optionally, use "hash:" to specify a 40-character (20 byte) hexadecimal SHA-1 hash value (without '0x') for the resource pack to prevent redownloading cached data.
// Specifying a hash is strongly recommended.
// Use "hash:" to specify a 40-character (20 byte) hexadecimal SHA-1 hash value (without '0x') for the resource pack to prevent redownloading cached data.
// Specifying a hash is required, though you can get away with copy/pasting a fake value if you don't care for the consequences.
// There are a variety of tools to generate the real hash, such as the `sha1sum` command on Linux, or using the 7-Zip GUI's Checksum option on Windows.
//
// Specify "forced" to tell the vanilla client they must accept the pack or quit the server. Hacked clients may still bypass this requirement.
//
Expand Down Expand Up @@ -90,6 +91,9 @@ else if (!scriptEntry.hasObject("targets")
if (!scriptEntry.hasObject("url")) {
throw new InvalidArgumentsException("Must specify a URL!");
}
if (!scriptEntry.hasObject("hash")) {
throw new InvalidArgumentsException("Must specify a hash!");
}
if (!scriptEntry.hasObject("targets")) {
if (Utilities.entryHasPlayer(scriptEntry) && Utilities.getEntryPlayer(scriptEntry).isOnline()) {
scriptEntry.addObject("targets", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
Expand All @@ -110,7 +114,7 @@ public void execute(ScriptEntry scriptEntry) {
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), ArgumentHelper.debugList("Targets", targets), url, hash, prompt, forced);
}
if (hash != null && hash.asString().length() != 40) {
if (hash.asString().length() != 40) {
Debug.echoError("Invalid resource_pack hash. Should be 40 characters of hexadecimal data.");
return;
}
Expand All @@ -119,7 +123,7 @@ public void execute(ScriptEntry scriptEntry) {
Debug.echoDebug(scriptEntry, "Player is offline, can't send resource pack to them. Skipping.");
continue;
}
AdvancedTextImpl.instance.sendResourcePack(player.getPlayerEntity(), url.asString(), hash == null ? null : hash.asString(), forced != null && forced.asBoolean(), prompt == null ? null : prompt.asString());
AdvancedTextImpl.instance.sendResourcePack(player.getPlayerEntity(), url.asString(), hash.asString(), forced != null && forced.asBoolean(), prompt == null ? null : prompt.asString());
}
}
}
Expand Up @@ -50,15 +50,10 @@ public void setSignLine(Sign sign, int line, String text) {
}

public void sendResourcePack(Player player, String url, String hash, boolean forced, String prompt) {
if (hash != null) {
byte[] hashData = new byte[20];
for (int i = 0; i < 20; i++) {
hashData[i] = (byte) Integer.parseInt(hash.substring(i * 2, i * 2 + 2), 16);
}
player.setResourcePack(url, hashData);
}
else {
player.setResourcePack(url);
byte[] hashData = new byte[20];
for (int i = 0; i < 20; i++) {
hashData[i] = (byte) Integer.parseInt(hash.substring(i * 2, i * 2 + 2), 16);
}
player.setResourcePack(url, hashData);
}
}

0 comments on commit 75e6914

Please sign in to comment.