Set resource pack url after generating hash

This commit is contained in:
NichtStudioCode 2022-01-15 15:41:49 +01:00
parent 3c7a85b2a9
commit 84c1736542

@ -76,18 +76,20 @@ public class ForceResourcePack implements Listener {
* @param sendToOnlinePlayers If the resource pack should also be sent to all currently online players * @param sendToOnlinePlayers If the resource pack should also be sent to all currently online players
*/ */
public void setResourcePack(@Nullable String resourcePackUrl, @Nullable BaseComponent[] prompt, boolean sendToOnlinePlayers) { public void setResourcePack(@Nullable String resourcePackUrl, @Nullable BaseComponent[] prompt, boolean sendToOnlinePlayers) {
this.resourcePackUrl = resourcePackUrl;
this.prompt = prompt; this.prompt = prompt;
if (resourcePackUrl != null) { if (resourcePackUrl != null) {
try { try {
URL url = new URL(resourcePackUrl); URL url = new URL(resourcePackUrl);
hash = DataUtils.createSha1Hash(url.openStream()); hash = DataUtils.createSha1Hash(url.openStream());
this.resourcePackUrl = resourcePackUrl;
} catch (IOException | NoSuchAlgorithmException e) { } catch (IOException | NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (sendToOnlinePlayers) Bukkit.getOnlinePlayers().forEach(this::sendResourcePack); if (sendToOnlinePlayers) Bukkit.getOnlinePlayers().forEach(this::sendResourcePack);
} else {
this.resourcePackUrl = null;
} }
} }