Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix exceptions thrown from PlayerResourcePackStatusEvent listener on < 1.20.2 #138

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}

}
Loading