Skip to content

Commit 554e9cd

Browse files
committed
Null handling
1 parent d88ec98 commit 554e9cd

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/main/java/world/bentobox/bentobox/api/user/User.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ public PlayerInventory getInventory() {
241241
*/
242242
@NonNull
243243
public Location getLocation() {
244-
return Objects.requireNonNull(player, "getLocation can only be called for online players!").getLocation();
244+
Player p = Objects.requireNonNull(player, "getLocation can only be called for online players!");
245+
Location loc = p.getLocation();
246+
return Objects.requireNonNull(loc, "Player's location cannot be null! The player may not have a location (has never played).");
245247
}
246248

247249
/**

src/main/java/world/bentobox/bentobox/database/objects/Island.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,11 @@ private boolean playerIsVisitor(Player player) {
851851
if (player.getGameMode() == GameMode.SPECTATOR) {
852852
return false;
853853
}
854-
854+
Location loc = player.getLocation();
855+
if (location == null) {
856+
// This will only be true if the player has never played. Allow them to be a visitor.
857+
return true;
858+
}
855859
return onIsland(player.getLocation()) && getRank(User.getInstance(player)) == RanksManager.VISITOR_RANK;
856860
}
857861

src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ private Object serialize(@Nullable Object object) {
598598
return switch (object) {
599599
case null -> "null";
600600

601-
// UUID has it's own serialization, that is not picked up automatically
601+
// UUID has its own serialization, that is not picked up automatically
602602
case UUID uuid -> object.toString();
603603

604604
// Only the world name is needed for worlds

0 commit comments

Comments
 (0)