Skip to content

Commit

Permalink
Added null checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jul 24, 2021
1 parent df24bea commit b897a71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String getCount(User user) {
* @return string of advancement count
*/
public String getCountByLocation(User user) {
if (user == null || user.getUniqueId() == null) return "";
if (user == null || user.getUniqueId() == null || user.getLocation() == null) return "";
return addon.getIslands().getIslandAt(user.getLocation())
.map(i -> String.valueOf(addon.getAdvManager().getIsland(i).getAdvancements().size())).orElse("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,27 @@ public void onAdvancement(PlayerAdvancementDoneEvent e) {
e.getAdvancement().getCriteria().forEach(c ->
e.getPlayer().getAdvancementProgress(e.getAdvancement()).revokeCriteria(c));
User u = User.getInstance(e.getPlayer());
u.notify("boxed.adv-disallowed", TextVariables.NAME, e.getPlayer().getName(), TextVariables.DESCRIPTION, this.keyToString(u, e.getAdvancement().getKey()));
if (u != null) {
u.notify("boxed.adv-disallowed", TextVariables.NAME, e.getPlayer().getName(), TextVariables.DESCRIPTION, this.keyToString(u, e.getAdvancement().getKey()));
}
return;
}

int score = addon.getAdvManager().addAdvancement(e.getPlayer(), e.getAdvancement());
if (score != 0) {
User user = User.getInstance(e.getPlayer());
Bukkit.getScheduler().runTask(addon.getPlugin(), () -> tellTeam(user, e.getAdvancement().getKey(), score));
if (user != null) {
Bukkit.getScheduler().runTask(addon.getPlugin(), () -> tellTeam(user, e.getAdvancement().getKey(), score));
}
}
}
}

private void tellTeam(User user, NamespacedKey key, int score) {
Island island = addon.getIslands().getIsland(addon.getOverWorld(), user);
if (island == null) {
return;
}
island.getMemberSet(RanksManager.MEMBER_RANK).stream()
.map(User::getInstance)
.filter(User::isOnline)
Expand Down

0 comments on commit b897a71

Please sign in to comment.