mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-27 20:46:19 +01:00
Added defensive code around null UUIDs
Relates to: https://github.com/BentoBoxWorld/BentoBox/issues/447
This commit is contained in:
parent
28e6ea4377
commit
8510f413f5
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user