Fix possible NPEs when calling API storage events - fixes #384

This commit is contained in:
Luck 2017-07-22 00:06:37 +01:00
parent 65b0d45738
commit b4aeb04d1b
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -139,7 +139,10 @@ public class AbstractStorage implements Storage {
public CompletableFuture<Boolean> createAndLoadGroup(String name, CreationCause cause) {
return makeFuture(() -> {
if (backing.createAndLoadGroup(name)) {
plugin.getApiProvider().getEventFactory().handleGroupCreate(plugin.getGroupManager().getIfLoaded(name), cause);
Group g = plugin.getGroupManager().getIfLoaded(name);
if (g != null) {
plugin.getApiProvider().getEventFactory().handleGroupCreate(g, cause);
}
return true;
}
return false;
@ -150,7 +153,10 @@ public class AbstractStorage implements Storage {
public CompletableFuture<Boolean> loadGroup(String name) {
return makeFuture(() -> {
if (backing.loadGroup(name)) {
plugin.getApiProvider().getEventFactory().handleGroupLoad(plugin.getGroupManager().getIfLoaded(name));
Group g = plugin.getGroupManager().getIfLoaded(name);
if (g != null) {
plugin.getApiProvider().getEventFactory().handleGroupLoad(g);
}
return true;
}
return false;
@ -193,7 +199,10 @@ public class AbstractStorage implements Storage {
public CompletableFuture<Boolean> createAndLoadTrack(String name, CreationCause cause) {
return makeFuture(() -> {
if (backing.createAndLoadTrack(name)) {
plugin.getApiProvider().getEventFactory().handleTrackCreate(plugin.getTrackManager().getIfLoaded(name), cause);
Track t = plugin.getTrackManager().getIfLoaded(name);
if (t != null) {
plugin.getApiProvider().getEventFactory().handleTrackCreate(t, cause);
}
return true;
}
return false;
@ -204,7 +213,10 @@ public class AbstractStorage implements Storage {
public CompletableFuture<Boolean> loadTrack(String name) {
return makeFuture(() -> {
if (backing.loadTrack(name)) {
plugin.getApiProvider().getEventFactory().handleTrackLoad(plugin.getTrackManager().getIfLoaded(name));
Track t = plugin.getTrackManager().getIfLoaded(name);
if (t != null) {
plugin.getApiProvider().getEventFactory().handleTrackLoad(t);
}
return true;
}
return false;