Skip to content

Commit

Permalink
fix NoSuchMethodException being thrown within PlayerResourcePackStatu…
Browse files Browse the repository at this point in the history
…sEvent listener on < 1.20.2 (#138)
  • Loading branch information
Grabsky authored Aug 15, 2024
1 parent 75b7766 commit 5adbd4e
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void onWorldChange(@NotNull final PlayerChangedWorldEvent event) {
@EventHandler(priority = EventPriority.MONITOR)
public void onResourcePackStatus(@NotNull final PlayerResourcePackStatusEvent event) {
final UUID playerUniqueId = event.getPlayer().getUniqueId();
final UUID packUniqueId = event.getID();
final UUID packUniqueId = getResourcePackID(event);
// Adding accepted resource-pack to the list of currently loading resource-packs for that player.
if (event.getStatus() == Status.ACCEPTED)
loadingResourcePacks.computeIfAbsent(playerUniqueId, (___) -> new ArrayList<>()).add(packUniqueId);
Expand All @@ -84,4 +84,15 @@ else if (event.getStatus() == Status.SUCCESSFULLY_LOADED || event.getStatus() ==
}
}

// For 1.20.2 and higher this method returns actual pack identifier, while for older versions, the identifier is a dummy UUID full of zeroes.
// Versions prior 1.20.2 supports sending and receiving only one resource-pack and a dummy, constant identifier can be used as a key.
private static @NotNull UUID getResourcePackID(final @NotNull PlayerResourcePackStatusEvent event) {
try {
event.getClass().getMethod("getID");
return event.getID();
} catch (final @NotNull NoSuchMethodException e) {
return new UUID(0,0);
}
}

}

0 comments on commit 5adbd4e

Please sign in to comment.