mirror of
https://github.com/BentoBoxWorld/Boxed.git
synced 2025-01-06 18:47:52 +01:00
Added null checks.
This commit is contained in:
parent
b897a71cd2
commit
4b83e9b770
@ -33,9 +33,12 @@ public class PlaceholdersManager {
|
|||||||
* @return string of advancement count
|
* @return string of advancement count
|
||||||
*/
|
*/
|
||||||
public String getCountByLocation(User user) {
|
public String getCountByLocation(User user) {
|
||||||
if (user == null || user.getUniqueId() == null || user.getLocation() == null) return "";
|
if (user != null && user.getUniqueId() != null && user.getLocation() != null) {
|
||||||
return addon.getIslands().getIslandAt(user.getLocation())
|
return addon.getIslands().getIslandAt(user.getLocation())
|
||||||
.map(i -> String.valueOf(addon.getAdvManager().getIsland(i).getAdvancements().size())).orElse("");
|
.map(i -> String.valueOf(addon.getAdvManager().getIsland(i).getAdvancements().size())).orElse("");
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package world.bentobox.boxed.listeners;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Spliterator;
|
import java.util.Spliterator;
|
||||||
import java.util.Spliterators;
|
import java.util.Spliterators;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
@ -126,16 +127,16 @@ public class AdvancementListener implements Listener {
|
|||||||
int diff = addon.getAdvManager().checkIslandSize(island);
|
int diff = addon.getAdvManager().checkIslandSize(island);
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(diff));
|
user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(diff));
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F);
|
user.getPlayer().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F);
|
||||||
} else if (diff < 0) {
|
} else if (diff < 0) {
|
||||||
user.sendMessage("boxed.size-decreased", TextVariables.NUMBER, String.valueOf(Math.abs(diff)));
|
user.sendMessage("boxed.size-decreased", TextVariables.NUMBER, String.valueOf(Math.abs(diff)));
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.ENTITY_VILLAGER_DEATH, 1F, 2F);
|
user.getPlayer().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_VILLAGER_DEATH, 1F, 2F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void informPlayer(User user, NamespacedKey key, int score) {
|
private void informPlayer(User user, NamespacedKey key, int score) {
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F);
|
user.getPlayer().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F);
|
||||||
user.sendMessage("boxed.completed", TextVariables.NAME, keyToString(user, key));
|
user.sendMessage("boxed.completed", TextVariables.NAME, keyToString(user, key));
|
||||||
user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(score));
|
user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(score));
|
||||||
|
|
||||||
@ -193,7 +194,7 @@ public class AdvancementListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onTeamJoinTime(TeamJoinedEvent e) {
|
public void onTeamJoinTime(TeamJoinedEvent e) {
|
||||||
User user = User.getInstance(e.getPlayerUUID());
|
User user = User.getInstance(e.getPlayerUUID());
|
||||||
if (addon.getSettings().isOnJoinResetAdvancements() && user.isOnline()
|
if (user != null && addon.getSettings().isOnJoinResetAdvancements() && user.isOnline()
|
||||||
&& addon.getOverWorld().equals(Util.getWorld(user.getWorld()))) {
|
&& addon.getOverWorld().equals(Util.getWorld(user.getWorld()))) {
|
||||||
// Clear and set advancements
|
// Clear and set advancements
|
||||||
clearAndSetAdv(user, addon.getSettings().isOnJoinResetAdvancements(), addon.getSettings().getOnJoinGrantAdvancements());
|
clearAndSetAdv(user, addon.getSettings().isOnJoinResetAdvancements(), addon.getSettings().getOnJoinGrantAdvancements());
|
||||||
@ -205,7 +206,7 @@ public class AdvancementListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onTeamLeaveTime(TeamLeaveEvent e) {
|
public void onTeamLeaveTime(TeamLeaveEvent e) {
|
||||||
User user = User.getInstance(e.getPlayerUUID());
|
User user = User.getInstance(e.getPlayerUUID());
|
||||||
if (addon.getSettings().isOnJoinResetAdvancements() && user.isOnline()
|
if (user != null && addon.getSettings().isOnJoinResetAdvancements() && user.isOnline()
|
||||||
&& addon.getOverWorld().equals(Util.getWorld(user.getWorld()))) {
|
&& addon.getOverWorld().equals(Util.getWorld(user.getWorld()))) {
|
||||||
// Clear and set advancements
|
// Clear and set advancements
|
||||||
clearAndSetAdv(user, addon.getSettings().isOnLeaveResetAdvancements(), addon.getSettings().getOnLeaveGrantAdvancements());
|
clearAndSetAdv(user, addon.getSettings().isOnLeaveResetAdvancements(), addon.getSettings().getOnLeaveGrantAdvancements());
|
||||||
@ -215,7 +216,10 @@ public class AdvancementListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onFirstTime(IslandNewIslandEvent e) {
|
public void onFirstTime(IslandNewIslandEvent e) {
|
||||||
clearAndSetAdv(User.getInstance(e.getPlayerUUID()), addon.getSettings().isOnJoinResetAdvancements(), addon.getSettings().getOnJoinGrantAdvancements());
|
User user = User.getInstance(e.getPlayerUUID());
|
||||||
|
if (user != null) {
|
||||||
|
clearAndSetAdv(user, addon.getSettings().isOnJoinResetAdvancements(), addon.getSettings().getOnJoinGrantAdvancements());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user