Removed source of null current world

Affects issues:
- Close #1119
This commit is contained in:
Rsl1122 2019-07-29 10:37:36 +03:00
parent 8f639f7f41
commit 91bbb00968
3 changed files with 11 additions and 6 deletions

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.data.time;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* Class that tracks the time spent in each World based on GMTimes.
@ -171,8 +172,8 @@ public class WorldTimes {
return b.toString();
}
public String getCurrentWorld() {
return currentWorld;
public Optional<String> getCurrentWorld() {
return Optional.ofNullable(currentWorld);
}
public void add(WorldTimes toAdd) {

View File

@ -63,6 +63,9 @@ public class ConfigNode {
}
public Optional<ConfigNode> getNode(String path) {
if (path == null) {
return Optional.empty();
}
String[] parts = splitPathInTwo(path);
String key = parts[0];
String leftover = parts[1];
@ -88,7 +91,7 @@ public class ConfigNode {
public ConfigNode addNode(String path) {
ConfigNode newParent = this;
if (!path.isEmpty()) {
if (path != null && !path.isEmpty()) {
String[] parts = splitPathInTwo(path);
String key = parts[0];
String leftover = parts[1];
@ -105,7 +108,7 @@ public class ConfigNode {
// Otherwise continue recursively.
return leftover.isEmpty() ? child : child.addNode(leftover);
}
throw new IllegalArgumentException("Can not add a node with empty path");
throw new IllegalArgumentException("Can not add a node with path '" + path + "'");
}
/**

View File

@ -157,8 +157,9 @@ public class WorldAliasSettings {
}
WorldTimes worldTimes = session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes());
if (!session.supports(SessionKeys.END)) {
String currentWorld = worldTimes.getCurrentWorld();
return "Current: " + (aliases.contains(currentWorld) ? aliases.getString(currentWorld) : currentWorld);
return worldTimes.getCurrentWorld()
.map(currentWorld -> "Current: " + (aliases.contains(currentWorld) ? aliases.getString(currentWorld) : currentWorld))
.orElse("Current: Unavailable");
}
Map<String, Long> playtimePerAlias = getPlaytimePerAlias(worldTimes);