mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2025-01-27 10:41:33 +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
|
* @param level - level
|
||||||
*/
|
*/
|
||||||
public void setIslandLevel(World world, UUID targetPlayer, long 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);
|
LevelsData ld = getLevelsData(targetPlayer);
|
||||||
if (ld == null) {
|
if (ld == null) {
|
||||||
ld = new LevelsData(targetPlayer, level, world);
|
ld = new LevelsData(targetPlayer, level, world);
|
||||||
@ -181,6 +185,10 @@ public class Level extends Addon {
|
|||||||
* @param level - initial calculated island level
|
* @param level - initial calculated island level
|
||||||
*/
|
*/
|
||||||
public void setInitialIslandLevel(Island island, long 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);
|
setIslandLevel(island.getWorld(), island.getOwner(), level);
|
||||||
levelsCache.get(island.getOwner()).setInitialIslandLevel(level);
|
levelsCache.get(island.getOwner()).setInitialIslandLevel(level);
|
||||||
}
|
}
|
||||||
@ -190,7 +198,7 @@ public class Level extends Addon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void uncachePlayer(UUID uniqueId) {
|
public void uncachePlayer(UUID uniqueId) {
|
||||||
if (levelsCache.containsKey(uniqueId)) {
|
if (levelsCache.containsKey(uniqueId) && levelsCache.get(uniqueId) != null) {
|
||||||
handler.saveObject(levelsCache.get(uniqueId));
|
handler.saveObject(levelsCache.get(uniqueId));
|
||||||
}
|
}
|
||||||
levelsCache.remove(uniqueId);
|
levelsCache.remove(uniqueId);
|
||||||
|
@ -33,12 +33,16 @@ public class NewIslandListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onNewIsland(IslandCreatedEvent e) {
|
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)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onNewIsland(IslandResettedEvent e) {
|
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) {
|
private void zeroLevel(Island island) {
|
||||||
|
Loading…
Reference in New Issue
Block a user