Added defensive code around null UUIDs

Relates to:
https://github.com/BentoBoxWorld/BentoBox/issues/447
This commit is contained in:
tastybento 2019-01-07 07:29:03 -08:00
parent 28e6ea4377
commit 8510f413f5
2 changed files with 15 additions and 3 deletions

View File

@ -164,6 +164,10 @@ public class Level extends Addon {
* @param level - level
*/
public void setIslandLevel(World world, UUID targetPlayer, long level) {
if (world == null || targetPlayer == null) {
this.logError("Level: request to store a null " + world + " " + targetPlayer);
return;
}
LevelsData ld = getLevelsData(targetPlayer);
if (ld == null) {
ld = new LevelsData(targetPlayer, level, world);
@ -181,6 +185,10 @@ public class Level extends Addon {
* @param level - initial calculated island level
*/
public void setInitialIslandLevel(Island island, long level) {
if (island.getWorld() == null || island.getOwner() == null) {
this.logError("Level: request to store a null (initial) " + island.getWorld() + " " + island.getOwner());
return;
}
setIslandLevel(island.getWorld(), island.getOwner(), level);
levelsCache.get(island.getOwner()).setInitialIslandLevel(level);
}
@ -190,7 +198,7 @@ public class Level extends Addon {
}
public void uncachePlayer(UUID uniqueId) {
if (levelsCache.containsKey(uniqueId)) {
if (levelsCache.containsKey(uniqueId) && levelsCache.get(uniqueId) != null) {
handler.saveObject(levelsCache.get(uniqueId));
}
levelsCache.remove(uniqueId);

View File

@ -33,12 +33,16 @@ public class NewIslandListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onNewIsland(IslandCreatedEvent e) {
cil.putIfAbsent(e.getIsland(), new CalcIslandLevel(addon, e.getIsland(), () -> zeroLevel(e.getIsland())));
if (e.getIsland().getOwner() != null && e.getIsland().getWorld() != null) {
cil.putIfAbsent(e.getIsland(), new CalcIslandLevel(addon, e.getIsland(), () -> zeroLevel(e.getIsland())));
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onNewIsland(IslandResettedEvent e) {
cil.putIfAbsent(e.getIsland(), new CalcIslandLevel(addon, e.getIsland(), () -> zeroLevel(e.getIsland())));
if (e.getIsland().getOwner() != null && e.getIsland().getWorld() != null) {
cil.putIfAbsent(e.getIsland(), new CalcIslandLevel(addon, e.getIsland(), () -> zeroLevel(e.getIsland())));
}
}
private void zeroLevel(Island island) {