Skip to content

Commit

Permalink
Minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wertik committed Feb 15, 2021
1 parent a7a6fff commit 951afdb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public CompletableFuture<Void> build() {
MenuItem item;
if (used) {
item = new MenuItem(messageItemTaken);
messageItemTaken.setClickAction(click -> plugin.getSoundRegistry().play(player, SoundType.MENU_USED));
item.setClickAction(click -> plugin.getSoundRegistry().play(player, SoundType.MENU_USED));
} else {
item = new MenuItem(messageItem);
item.setClickAction((itemClick) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package space.devport.wertik.custommessages.storage.json;

import com.google.gson.reflect.TypeToken;
import lombok.extern.java.Log;
import space.devport.dock.util.json.GsonHelper;
import space.devport.wertik.custommessages.MessagePlugin;
Expand Down Expand Up @@ -30,20 +31,22 @@ public JsonStorage(MessagePlugin plugin, String fileName) {

@Override
public CompletableFuture<Boolean> initialize() {
return gsonHelper.loadMapAsync(plugin.getDataFolder() + "/" + fileName, UUID.class, User.class)
.thenApplyAsync(loaded -> {
if (loaded == null)
loaded = new HashMap<>();

storedUsers.clear();
storedUsers.putAll(loaded);
log.fine(() -> "Loaded JSON storage.");
return true;
}).exceptionally(e -> {
log.warning(() -> String.format("Failed to load users: %s", e.getMessage()));
e.printStackTrace();
return false;
});
CompletableFuture<Map<UUID, User>> future = gsonHelper.loadAsync(plugin.getDataFolder() + "/" + fileName, new TypeToken<Map<UUID, User>>() {
}.getType());

return future.thenApplyAsync(loaded -> {
if (loaded == null)
loaded = new HashMap<>();

storedUsers.clear();
storedUsers.putAll(loaded);
log.fine(() -> "Loaded " + storedUsers.size() + " user(s) from JSON storage.");
return true;
}).exceptionally(e -> {
log.warning(() -> String.format("Failed to load users: %s", e.getMessage()));
e.printStackTrace();
return false;
});
}

@Override
Expand Down

0 comments on commit 951afdb

Please sign in to comment.