Skip to content

Commit 6ef72cd

Browse files
Fix up ResourcePackSpell hash
1 parent 92776e8 commit 6ef72cd

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/com/nisovin/magicspells/spells/targeted/ResourcePackSpell.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public ResourcePackSpell(MagicConfig config, String spellName) {
1919
url = getConfigString("url", null);
2020
String hashString = getConfigString("hash", null);
2121
if (hashString != null) {
22-
hash = hashString.getBytes();
23-
22+
hash = hexStringToByteArray(hashString);
2423
if (hash.length != HASH_LENGTH) {
2524
// Send the message
2625
MagicSpells.error("Incorrect length for resource pack hash: " + hash.length);
26+
2727
MagicSpells.error("Avoiding use of the hash to avoid further problems.");
2828
// Null it to prevent further errors
2929
hash = null;
@@ -51,5 +51,15 @@ private void sendResourcePack(Player player) {
5151
player.setResourcePack(url, hash);
5252
}
5353
}
54+
55+
private static byte[] hexStringToByteArray(String s) {
56+
int len = s.length();
57+
byte[] data = new byte[len / 2];
58+
for (int i = 0; i < len; i += 2) {
59+
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
60+
+ Character.digit(s.charAt(i+1), 16));
61+
}
62+
return data;
63+
}
5464

5565
}

0 commit comments

Comments
 (0)