From 64f4f03597ab4f28680b45224cecea7f77141ebe Mon Sep 17 00:00:00 2001 From: duranaaron Date: Sat, 4 Jan 2025 02:10:58 +0100 Subject: [PATCH 1/2] =?UTF-8?q?First=20and=20foremost=20removed=20bloated?= =?UTF-8?q?=20getMinetopiaAsync,=20also=20fixed=20bug=20loading=20player?= =?UTF-8?q?=20data=20incorrectly=20due=20to=20me=20being=20stupid=E2=84=A2?= =?UTF-8?q?=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/nl/openminetopia/OpenMinetopia.java | 1 + .../api/player/PlayerManager.java | 96 +++---------------- .../api/player/fitness/Fitness.java | 6 +- .../api/player/objects/MinetopiaPlayer.java | 62 ++++++------ .../subcommands/BankingCreateCommand.java | 4 +- .../subcommands/BankingDeleteCommand.java | 4 +- .../subcommands/BankingInfoCommand.java | 4 +- .../subcommands/BankingUsersCommand.java | 8 +- .../banking/menus/BankContentsMenu.java | 8 +- .../chat/listeners/PlayerChatListener.java | 4 +- .../modules/chat/utils/SpyUtils.java | 8 +- .../modules/color/ColorModule.java | 4 +- .../modules/color/commands/ColorCommand.java | 20 ++-- .../commands/subcommands/ColorAddCommand.java | 8 +- .../subcommands/ColorCreateCommand.java | 4 +- .../subcommands/ColorRemoveCommand.java | 8 +- .../modules/data/adapters/MySQLAdapter.java | 3 +- .../subcommands/FitnessBoosterCommand.java | 40 +++++--- .../listeners/PlayerChangeWorldListener.java | 4 +- .../listeners/PlayerDeathListener.java | 4 +- .../listeners/PlayerDrinkListener.java | 4 +- .../fitness/listeners/PlayerEatListener.java | 4 +- .../modules/fitness/utils/FitnessUtils.java | 4 +- .../subcommands/MTCityCreateCommand.java | 6 +- .../subcommands/MTWorldCreateCommand.java | 4 +- .../places/listeners/PlayerJoinListener.java | 4 +- .../places/listeners/PlayerMoveListener.java | 4 +- .../listeners/PlayerTeleportListener.java | 4 +- .../modules/player/PlayerModule.java | 20 ++-- .../player/commands/PlaytimeCommand.java | 10 +- .../listeners/PlayerPreLoginListener.java | 19 +++- .../player/listeners/PlayerQuitListener.java | 10 +- .../modules/player/utils/LevelUtil.java | 33 ++----- .../subcommands/PlotClearCommand.java | 4 +- .../subcommands/PlotCreateCommand.java | 4 +- .../subcommands/PlotDeleteCommand.java | 4 +- .../subcommands/PlotDescriptionCommand.java | 4 +- .../commands/subcommands/PlotInfoCommand.java | 4 +- .../commands/subcommands/PlotListCommand.java | 4 +- .../subcommands/PlotTeleportCommand.java | 4 +- .../subcommands/PlotTransferCommand.java | 4 +- .../police/commands/BodysearchCommand.java | 8 +- .../commands/CriminalRecordCommand.java | 24 ++--- .../police/commands/EmergencyCommand.java | 8 +- .../listeners/PlayerHandcuffListener.java | 8 +- .../listeners/PlayerPeppersprayListener.java | 4 +- .../police/listeners/PlayerTaserListener.java | 4 +- .../listeners/PlayerInteractListener.java | 4 +- .../modules/prefix/PrefixModule.java | 4 +- .../prefix/commands/PrefixCommand.java | 4 +- .../subcommands/PrefixAddCommand.java | 8 +- .../subcommands/PrefixMenuCommand.java | 4 +- .../subcommands/PrefixRemoveCommand.java | 8 +- .../listeners/PlayerJoinListener.java | 4 +- .../subcommands/AdminToolOpenCommand.java | 18 +++- .../PlayerEntityInteractListener.java | 4 +- .../listeners/PlayerInteractListener.java | 4 +- .../staff/chat/commands/StaffchatCommand.java | 8 +- .../chat/listeners/PlayerChatListener.java | 4 +- .../subcommands/ModChatSpyCommand.java | 4 +- .../subcommands/ModCommandSpyCommand.java | 4 +- .../subcommands/ModSetLevelCommand.java | 4 +- 62 files changed, 273 insertions(+), 327 deletions(-) diff --git a/src/main/java/nl/openminetopia/OpenMinetopia.java b/src/main/java/nl/openminetopia/OpenMinetopia.java index b932b2e..0efb7e1 100644 --- a/src/main/java/nl/openminetopia/OpenMinetopia.java +++ b/src/main/java/nl/openminetopia/OpenMinetopia.java @@ -28,6 +28,7 @@ import nl.openminetopia.modules.data.DataModule; import nl.openminetopia.modules.detectiongates.DetectionModule; import nl.openminetopia.modules.fitness.FitnessModule; +import nl.openminetopia.modules.migrator.MigratorModule; import nl.openminetopia.modules.misc.MiscModule; import nl.openminetopia.modules.places.PlacesModule; import nl.openminetopia.modules.player.PlayerModule; diff --git a/src/main/java/nl/openminetopia/api/player/PlayerManager.java b/src/main/java/nl/openminetopia/api/player/PlayerManager.java index 60c6f10..9dbfed1 100644 --- a/src/main/java/nl/openminetopia/api/player/PlayerManager.java +++ b/src/main/java/nl/openminetopia/api/player/PlayerManager.java @@ -36,100 +36,32 @@ public MinetopiaPlayer getOnlineMinetopiaPlayer(Player player) { public CompletableFuture getMinetopiaPlayer(OfflinePlayer player) { CompletableFuture future = new CompletableFuture<>(); - getMinetopiaPlayerAsync(player, future::complete, future::completeExceptionally); - return future; - } - /** - * Fetches a MinetopiaPlayer asynchronously. If the player is online, retrieve it from the map. - * Otherwise, query the database. - * - * @param player The OfflinePlayer to retrieve the MinetopiaPlayer for. - * @param callback The action to perform if the MinetopiaPlayer is retrieved successfully. - * @param errorCallback The action to perform if there is an error during retrieval. - * - * @deprecated Use {@link #getMinetopiaPlayer(OfflinePlayer)} instead. - */ - @Deprecated - public void getMinetopiaPlayerAsync(OfflinePlayer player, - Consumer callback, - Consumer errorCallback) { - UUID playerId = player.getUniqueId(); - - // Check if player is online and already loaded - if (onlinePlayers.containsKey(playerId)) { - callback.accept(onlinePlayers.get(playerId)); - return; + if (onlinePlayers.containsKey(player.getUniqueId())) { + future.complete(onlinePlayers.get(player.getUniqueId())); + return future; } - // Load player if offline or not in the map - loadPlayerModel(player).whenComplete((playerModel, throwable) -> { + this.playerModule.getPlayerModel(player.getUniqueId()).whenComplete((playerModel, throwable) -> { if (throwable != null) { - errorCallback.accept(throwable); - return; - } - if (playerModel == null) { - callback.accept(null); + future.completeExceptionally(throwable); return; } - // Create a new MinetopiaPlayer - MinetopiaPlayer newMinetopiaPlayer = new MinetopiaPlayer(playerId, playerModel); - loadMinetopiaPlayer(newMinetopiaPlayer).whenComplete((loadedMinetopiaPlayer, loadThrowable) -> { - if (loadThrowable != null) { - errorCallback.accept(loadThrowable); - return; - } + MinetopiaPlayer minetopiaPlayer = new MinetopiaPlayer(player.getUniqueId(), playerModel); + + minetopiaPlayer.load().thenAccept(unused -> { if (player.isOnline()) { - onlinePlayers.put(playerId, loadedMinetopiaPlayer); - } else { - loadedMinetopiaPlayer.load(); + onlinePlayers.put(player.getUniqueId(), minetopiaPlayer); } - callback.accept(loadedMinetopiaPlayer); - }); - }); - } - /** - * Synchronously gets a MinetopiaPlayer if there's an ongoing async operation or if the player is online. - * - * @param player The player to retrieve. - * @return The MinetopiaPlayer object. - */ - public MinetopiaPlayer getMinetopiaPlayerSync(OfflinePlayer player) { - UUID playerId = player.getUniqueId(); - if (onlinePlayers.containsKey(playerId)) { - return onlinePlayers.get(playerId); - } - - // Perform synchronous retrieval if needed (not recommended if complex) - CompletableFuture future = new CompletableFuture<>(); - getMinetopiaPlayerAsync(player, future::complete, future::completeExceptionally); - return future.join(); - } - - private CompletableFuture loadPlayerModel(OfflinePlayer player) { - UUID playerId = player.getUniqueId(); - CompletableFuture future = new CompletableFuture<>(); - this.playerModule.loadPlayer(playerId).whenComplete((playerModel, throwable) -> { - if (throwable != null) { - future.completeExceptionally(throwable); - return; - } - future.complete(playerModel); + future.complete(minetopiaPlayer); + }).exceptionally(throwable2 -> { + future.completeExceptionally(throwable2); + return null; + }); }); - return future; - } - private CompletableFuture loadMinetopiaPlayer(MinetopiaPlayer minetopiaPlayer) { - CompletableFuture future = new CompletableFuture<>(); - minetopiaPlayer.load().whenComplete((unused, throwable) -> { - if (throwable != null) { - future.completeExceptionally(throwable); - return; - } - future.complete(minetopiaPlayer); - }); return future; } } \ No newline at end of file diff --git a/src/main/java/nl/openminetopia/api/player/fitness/Fitness.java b/src/main/java/nl/openminetopia/api/player/fitness/Fitness.java index 882c80a..8e3705d 100644 --- a/src/main/java/nl/openminetopia/api/player/fitness/Fitness.java +++ b/src/main/java/nl/openminetopia/api/player/fitness/Fitness.java @@ -111,15 +111,17 @@ public void addBooster(int amount, long expiresAtMillis) { boosterModel.setPlayerId(this.playerModel.getId()); boosterModel.setAmount(amount); boosterModel.setExpiresAt(expiresAtMillis); - playerModel.getBoosters().add(boosterModel); + this.playerModel.getBoosters().add(boosterModel); StormDatabase.getInstance().saveStormModel(boosterModel); + System.out.println(playerModel.getUniqueId()); + runnable.run(); } @SneakyThrows public void removeBooster(FitnessBoosterModel booster) { - playerModel.getBoosters().remove(booster); + this.playerModel.getBoosters().remove(booster); StormDatabase.getInstance().getStorm().delete(booster); runnable.run(); diff --git a/src/main/java/nl/openminetopia/api/player/objects/MinetopiaPlayer.java b/src/main/java/nl/openminetopia/api/player/objects/MinetopiaPlayer.java index f070a30..e868bf9 100644 --- a/src/main/java/nl/openminetopia/api/player/objects/MinetopiaPlayer.java +++ b/src/main/java/nl/openminetopia/api/player/objects/MinetopiaPlayer.java @@ -82,52 +82,44 @@ public MinetopiaPlayer(UUID uuid, PlayerModel playerModel) { public CompletableFuture load() { CompletableFuture loadFuture = new CompletableFuture<>(); - playerModule.getPlayerLoadFuture().whenComplete((unused, throwable) -> { - if (throwable != null) { - OpenMinetopia.getInstance().getLogger().severe("Failed to load player: " + throwable.getMessage()); - return; - } - - DefaultConfiguration configuration = OpenMinetopia.getDefaultConfiguration(); - - if (this.getBukkit().getPlayer() != null && this.getBukkit().isOnline()) - this.getBukkit().getPlayer().sendMessage(ChatUtils.color("Je data wordt geladen...")); + DefaultConfiguration configuration = OpenMinetopia.getDefaultConfiguration(); - this.fitness = new Fitness(this); + if (this.getBukkit().getPlayer() != null && this.getBukkit().isOnline()) + this.getBukkit().getPlayer().sendMessage(ChatUtils.color("Je data wordt geladen...")); - this.playtime = this.playerModel.getPlaytime(); - this.level = this.playerModel.getLevel(); - this.calculatedLevel = configuration.getDefaultLevel(); - this.staffchatEnabled = this.playerModel.getStaffchatEnabled(); - this.commandSpyEnabled = this.playerModel.getCommandSpyEnabled(); - this.chatSpyEnabled = this.playerModel.getChatSpyEnabled(); + this.fitness = new Fitness(this); - this.colors = colorModule.getColorsFromPlayer(this.playerModel); - this.activeChatColor = (ChatColor) colorModule.getActiveColorFromPlayer(this.playerModel, OwnableColorType.CHAT) - .orElse(OwnableColorType.CHAT.defaultColor()); + this.playtime = this.playerModel.getPlaytime(); + this.level = this.playerModel.getLevel(); + this.calculatedLevel = configuration.getDefaultLevel(); + this.staffchatEnabled = this.playerModel.getStaffchatEnabled(); + this.commandSpyEnabled = this.playerModel.getCommandSpyEnabled(); + this.chatSpyEnabled = this.playerModel.getChatSpyEnabled(); - this.activeNameColor = (NameColor) colorModule.getActiveColorFromPlayer(this.playerModel, OwnableColorType.NAME) - .orElse(OwnableColorType.NAME.defaultColor()); + this.colors = colorModule.getColorsFromPlayer(this.playerModel); + this.activeChatColor = (ChatColor) colorModule.getActiveColorFromPlayer(this.playerModel, OwnableColorType.CHAT) + .orElse(OwnableColorType.CHAT.defaultColor()); - this.activePrefixColor = (PrefixColor) colorModule.getActiveColorFromPlayer(this.playerModel, OwnableColorType.PREFIX) - .orElse(OwnableColorType.PREFIX.defaultColor()); + this.activeNameColor = (NameColor) colorModule.getActiveColorFromPlayer(this.playerModel, OwnableColorType.NAME) + .orElse(OwnableColorType.NAME.defaultColor()); - this.activeLevelColor = (LevelColor) colorModule.getActiveColorFromPlayer(this.playerModel, OwnableColorType.LEVEL) - .orElse(OwnableColorType.LEVEL.defaultColor()); + this.activePrefixColor = (PrefixColor) colorModule.getActiveColorFromPlayer(this.playerModel, OwnableColorType.PREFIX) + .orElse(OwnableColorType.PREFIX.defaultColor()); - this.prefixes = prefixModule.getPrefixesFromPlayer(this.playerModel); - this.activePrefix = prefixModule.getActivePrefixFromPlayer(playerModel) - .orElse(new Prefix(-1, configuration.getDefaultPrefix(), -1)); + this.activeLevelColor = (LevelColor) colorModule.getActiveColorFromPlayer(this.playerModel, OwnableColorType.LEVEL) + .orElse(OwnableColorType.LEVEL.defaultColor()); - this.playtimeRunnable = new PlaytimeRunnable(this); - playtimeRunnable.runTaskTimerAsynchronously(OpenMinetopia.getInstance(), 0, 20L); + this.prefixes = prefixModule.getPrefixesFromPlayer(this.playerModel); + this.activePrefix = prefixModule.getActivePrefixFromPlayer(playerModel) + .orElse(new Prefix(-1, configuration.getDefaultPrefix(), -1)); - this.levelcheckRunnable = new LevelCheckRunnable(this); - levelcheckRunnable.runTaskTimerAsynchronously(OpenMinetopia.getInstance(), 0, 20L * 30); + this.playtimeRunnable = new PlaytimeRunnable(this); + playtimeRunnable.runTaskTimerAsynchronously(OpenMinetopia.getInstance(), 20L, 20L); - loadFuture.complete(null); - }); + this.levelcheckRunnable = new LevelCheckRunnable(this); + levelcheckRunnable.runTaskTimerAsynchronously(OpenMinetopia.getInstance(), 20L, 20L * 30); + loadFuture.complete(null); return loadFuture; } diff --git a/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingCreateCommand.java b/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingCreateCommand.java index 8d3badb..9eca24e 100644 --- a/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingCreateCommand.java +++ b/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingCreateCommand.java @@ -27,7 +27,7 @@ public class BankingCreateCommand extends BaseCommand { public void createAccount(Player player, AccountType type, String name) { BankingModule bankingModule = OpenMinetopia.getModuleManager().getModule(BankingModule.class); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (type == AccountType.PRIVATE) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("banking_unique_private_account")); return; @@ -65,6 +65,6 @@ public void createAccount(Player player, AccountType type, String name) { bankingModule.getBankAccountModels().add(accountModel); accountModel.initSavingTask(); })); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingDeleteCommand.java b/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingDeleteCommand.java index cd563de..1903a5d 100644 --- a/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingDeleteCommand.java +++ b/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingDeleteCommand.java @@ -26,7 +26,7 @@ public void deleteAccount(CommandSender sender, String accountName) { BankingModule bankingModule = OpenMinetopia.getModuleManager().getModule(BankingModule.class); BankAccountModel accountModel = bankingModule.getAccountByName(accountName); - PlayerManager.getInstance().getMinetopiaPlayerAsync((OfflinePlayer) sender, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer((OfflinePlayer) sender).whenComplete((minetopiaPlayer, throwable1) -> { if (accountModel == null) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("banking_account_not_found")); return; @@ -42,6 +42,6 @@ public void deleteAccount(CommandSender sender, String accountName) { .replace("", accountModel.getName())); bankingModule.getBankAccountModels().remove(accountModel); }); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingInfoCommand.java b/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingInfoCommand.java index 6f49f37..a901be1 100644 --- a/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingInfoCommand.java +++ b/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingInfoCommand.java @@ -24,7 +24,7 @@ public void infoAccount(CommandSender sender, String accountName) { BankingModule bankingModule = OpenMinetopia.getModuleManager().getModule(BankingModule.class); BankAccountModel accountModel = bankingModule.getAccountByName(accountName); - PlayerManager.getInstance().getMinetopiaPlayerAsync((OfflinePlayer) sender, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer((OfflinePlayer) sender).whenComplete((minetopiaPlayer, throwable1 ) -> { if (accountModel == null) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("banking_account_not_found")); return; @@ -35,7 +35,7 @@ public void infoAccount(CommandSender sender, String accountName) { ChatUtils.sendFormattedMessage(minetopiaPlayer, replacePlaceholders(MessageConfiguration.message("banking_account_info_line3"), accountModel)); ChatUtils.sendFormattedMessage(minetopiaPlayer, replacePlaceholders(MessageConfiguration.message("banking_account_info_line4"), accountModel)); - }, Throwable::printStackTrace); + }); } private String replacePlaceholders(String message, BankAccountModel accountModel) { diff --git a/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingUsersCommand.java b/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingUsersCommand.java index ff50f2c..4fb7095 100644 --- a/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingUsersCommand.java +++ b/src/main/java/nl/openminetopia/modules/banking/commands/subcommands/BankingUsersCommand.java @@ -27,7 +27,7 @@ public class BankingUsersCommand extends BaseCommand { public void addUser(CommandSender sender, OfflinePlayer target, String accountName, AccountPermission permission) { BankingModule bankingModule = OpenMinetopia.getModuleManager().getModule(BankingModule.class); BankAccountModel accountModel = bankingModule.getAccountByName(accountName); - PlayerManager.getInstance().getMinetopiaPlayerAsync((Player) sender, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer((Player) sender).whenComplete((minetopiaPlayer, throwable1) -> { if (accountModel == null) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("banking_account_not_found")); return; @@ -51,7 +51,7 @@ public void addUser(CommandSender sender, OfflinePlayer target, String accountNa .replace("", accountModel.getName()) .replace("", permission.name())); })); - }, Throwable::printStackTrace); + }); } @Subcommand("removeuser") @@ -62,7 +62,7 @@ public void removeUser(CommandSender sender, OfflinePlayer target, String accoun BankingModule bankingModule = OpenMinetopia.getModuleManager().getModule(BankingModule.class); BankAccountModel accountModel = bankingModule.getAccountByName(accountName); - PlayerManager.getInstance().getMinetopiaPlayerAsync((Player) sender, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer((Player) sender).whenComplete((minetopiaPlayer, throwable1) -> { if (accountModel == null) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("banking_account_not_found")); return; @@ -79,6 +79,6 @@ public void removeUser(CommandSender sender, OfflinePlayer target, String accoun .replace("", (target.getName() == null ? "null" : target.getName())) .replace("", accountModel.getName())); }); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/banking/menus/BankContentsMenu.java b/src/main/java/nl/openminetopia/modules/banking/menus/BankContentsMenu.java index 8b735c5..8762856 100644 --- a/src/main/java/nl/openminetopia/modules/banking/menus/BankContentsMenu.java +++ b/src/main/java/nl/openminetopia/modules/banking/menus/BankContentsMenu.java @@ -99,7 +99,7 @@ public void onClick(InventoryClickEvent event) { if (!PersistentDataUtil.contains(item, "bank_note_value")) return; if (PersistentDataUtil.getDouble(item, "bank_note_value") == null) return; - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if(!isAsAdmin() && !accountModel.hasPermission(player.getUniqueId(), AccountPermission.DEPOSIT)) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("banking_no_deposit_permission")); return; @@ -113,14 +113,14 @@ public void onClick(InventoryClickEvent event) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("banking_deposit_message") .replace("", bankingModule.format(totalValue))); new BankContentsMenu(player, accountModel, isAsAdmin()).open(player); - }, Throwable::printStackTrace); + }); } private void withdrawMoney(BankNote note, int amount) { double balance = accountModel.getBalance(); double totalValue = note.getValue() * amount; - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (balance < totalValue) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("banking_not_enough_money")); return; @@ -137,7 +137,7 @@ private void withdrawMoney(BankNote note, int amount) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("banking_withdraw_message") .replace("", bankingModule.format(totalValue))); new BankContentsMenu(player, accountModel, isAsAdmin()).open(player); - }, Throwable::printStackTrace); + }); } @Getter diff --git a/src/main/java/nl/openminetopia/modules/chat/listeners/PlayerChatListener.java b/src/main/java/nl/openminetopia/modules/chat/listeners/PlayerChatListener.java index 2658ad3..78d3c7c 100644 --- a/src/main/java/nl/openminetopia/modules/chat/listeners/PlayerChatListener.java +++ b/src/main/java/nl/openminetopia/modules/chat/listeners/PlayerChatListener.java @@ -23,7 +23,7 @@ public class PlayerChatListener implements Listener { @EventHandler public void playerChat(AsyncChatEvent event) { Player source = event.getPlayer(); - PlayerManager.getInstance().getMinetopiaPlayerAsync(source, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(source).whenComplete((minetopiaPlayer, throwable1) -> { if (minetopiaPlayer == null) return; if (!minetopiaPlayer.isInPlace()) return; @@ -87,6 +87,6 @@ public void playerChat(AsyncChatEvent event) { // Send the formatted message to the target target.sendMessage(ChatUtils.format(minetopiaPlayer, finalMessage)); } - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/chat/utils/SpyUtils.java b/src/main/java/nl/openminetopia/modules/chat/utils/SpyUtils.java index b805231..9af6cba 100644 --- a/src/main/java/nl/openminetopia/modules/chat/utils/SpyUtils.java +++ b/src/main/java/nl/openminetopia/modules/chat/utils/SpyUtils.java @@ -21,11 +21,11 @@ public void chatSpy(Player player, String message, List ignore) { if (onlinePlayer.getUniqueId().equals(player.getUniqueId())) continue; if (ignore.contains(onlinePlayer)) continue; - PlayerManager.getInstance().getMinetopiaPlayerAsync(onlinePlayer, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(onlinePlayer).whenComplete((minetopiaPlayer, throwable1) -> { if (minetopiaPlayer == null) return; if (minetopiaPlayer.isChatSpyEnabled()) ChatUtils.sendFormattedMessage(minetopiaPlayer, spiedMessage); - }, Throwable::printStackTrace); + }); } } @@ -37,11 +37,11 @@ public void commandSpy(Player player, String command) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { if (onlinePlayer.getUniqueId().equals(player.getUniqueId())) continue; - PlayerManager.getInstance().getMinetopiaPlayerAsync(onlinePlayer, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(onlinePlayer).whenComplete((minetopiaPlayer, throwable1) -> { if (minetopiaPlayer == null) return; if (minetopiaPlayer.isCommandSpyEnabled()) ChatUtils.sendFormattedMessage(minetopiaPlayer, spiedMessage); - }, Throwable::printStackTrace); + }); } } } diff --git a/src/main/java/nl/openminetopia/modules/color/ColorModule.java b/src/main/java/nl/openminetopia/modules/color/ColorModule.java index 919c05b..bb61cdc 100644 --- a/src/main/java/nl/openminetopia/modules/color/ColorModule.java +++ b/src/main/java/nl/openminetopia/modules/color/ColorModule.java @@ -66,13 +66,13 @@ public void enable() { OpenMinetopia.getCommandManager().getCommandCompletions().registerCompletion("playerColors", context -> { List colors = new ArrayList<>(); - PlayerManager.getInstance().getMinetopiaPlayerAsync(context.getPlayer(), minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(context.getPlayer()).whenComplete((minetopiaPlayer, throwable1) -> { if (minetopiaPlayer == null) return; colors.addAll(minetopiaPlayer.getColors().stream() .map(OwnableColor::getColorId) .toList()); - }, Throwable::printStackTrace); + }); return colors; }); diff --git a/src/main/java/nl/openminetopia/modules/color/commands/ColorCommand.java b/src/main/java/nl/openminetopia/modules/color/commands/ColorCommand.java index 2dd4c76..2743ffe 100644 --- a/src/main/java/nl/openminetopia/modules/color/commands/ColorCommand.java +++ b/src/main/java/nl/openminetopia/modules/color/commands/ColorCommand.java @@ -21,42 +21,42 @@ public void onHelp(CommandHelp help) { @Default public void onDefault(Player player) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; new ColorTypeMenu(player, player, minetopiaPlayer).open(player); - }, Throwable::printStackTrace); + }); } @CommandAlias("prefixcolor|prefixkleur") public void onPrefixColor(Player player) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; new ColorSelectMenu(player, player, minetopiaPlayer, OwnableColorType.PREFIX).open(player); - }, Throwable::printStackTrace); + }); } @CommandAlias("chatcolor|chatkleur") public void onChatColor(Player player) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; new ColorSelectMenu(player, player, minetopiaPlayer, OwnableColorType.CHAT).open(player); - }, Throwable::printStackTrace); + }); } @CommandAlias("namecolor|naamkleur") public void onNameColor(Player player) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; new ColorSelectMenu(player, player, minetopiaPlayer, OwnableColorType.NAME).open(player); - }, Throwable::printStackTrace); + }); } @CommandAlias("levelcolor|levelkleur") public void onLevelColor(Player player) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; new ColorSelectMenu(player, player, minetopiaPlayer, OwnableColorType.LEVEL).open(player); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorAddCommand.java b/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorAddCommand.java index 2e4b4fc..727d563 100644 --- a/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorAddCommand.java +++ b/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorAddCommand.java @@ -40,9 +40,9 @@ public void prefix(Player player, OfflinePlayer offlinePlayer, OwnableColorType return; } - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; - PlayerManager.getInstance().getMinetopiaPlayerAsync(offlinePlayer, targetMinetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(offlinePlayer).whenComplete((targetMinetopiaPlayer, throwable1) -> { if (targetMinetopiaPlayer == null) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("player_not_found")); return; @@ -96,7 +96,7 @@ public void prefix(Player player, OfflinePlayer offlinePlayer, OwnableColorType break; } - }, Throwable::printStackTrace); - }, Throwable::printStackTrace); + }); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorCreateCommand.java b/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorCreateCommand.java index eedf5d5..5e4f3e4 100644 --- a/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorCreateCommand.java +++ b/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorCreateCommand.java @@ -20,11 +20,11 @@ public class ColorCreateCommand extends BaseCommand { @CommandPermission("openminetopia.color.create") @Description("Add a new color to the configuration.") public void create(Player player, String identifier, String displayName, String prefixColor) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { OpenMinetopia.getColorsConfiguration().createColor(identifier, displayName, prefixColor); ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("color_created") .replace("", displayName) .replace("", identifier)); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorRemoveCommand.java b/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorRemoveCommand.java index 5e08672..ffd7a17 100644 --- a/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorRemoveCommand.java +++ b/src/main/java/nl/openminetopia/modules/color/commands/subcommands/ColorRemoveCommand.java @@ -35,10 +35,10 @@ public void prefix(Player player, OfflinePlayer offlinePlayer, OwnableColorType return; } - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; - PlayerManager.getInstance().getMinetopiaPlayerAsync(offlinePlayer, targetMinetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(offlinePlayer).whenComplete((targetMinetopiaPlayer, throwable1) -> { if (targetMinetopiaPlayer == null) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("player_not_found")); return; @@ -111,7 +111,7 @@ public void prefix(Player player, OfflinePlayer offlinePlayer, OwnableColorType .replace("", levelColor.get().getColorId())); break; } - }, Throwable::printStackTrace); - }, Throwable::printStackTrace); + }); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/data/adapters/MySQLAdapter.java b/src/main/java/nl/openminetopia/modules/data/adapters/MySQLAdapter.java index bd1e7fc..fcfb8ee 100644 --- a/src/main/java/nl/openminetopia/modules/data/adapters/MySQLAdapter.java +++ b/src/main/java/nl/openminetopia/modules/data/adapters/MySQLAdapter.java @@ -29,8 +29,9 @@ import nl.openminetopia.modules.police.models.CriminalRecordModel; import nl.openminetopia.modules.prefix.models.PrefixModel; -public class MySQLAdapter implements DatabaseAdapter{ +public class MySQLAdapter implements DatabaseAdapter { + @Override public void connect() { DefaultConfiguration configuration = OpenMinetopia.getDefaultConfiguration(); String host = configuration.getDatabaseHost(); diff --git a/src/main/java/nl/openminetopia/modules/fitness/commands/subcommands/FitnessBoosterCommand.java b/src/main/java/nl/openminetopia/modules/fitness/commands/subcommands/FitnessBoosterCommand.java index 71b7961..2b44ee2 100644 --- a/src/main/java/nl/openminetopia/modules/fitness/commands/subcommands/FitnessBoosterCommand.java +++ b/src/main/java/nl/openminetopia/modules/fitness/commands/subcommands/FitnessBoosterCommand.java @@ -13,6 +13,8 @@ import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; +import java.util.concurrent.CompletableFuture; + @CommandAlias("fitness|fitheid") public class FitnessBoosterCommand extends BaseCommand { @@ -20,25 +22,33 @@ public class FitnessBoosterCommand extends BaseCommand { @CommandPermission("openminetopia.fitness.booster") @CommandCompletion("@players") public void booster(Player player, OfflinePlayer offlinePlayer, int amount, @Optional Integer expiresAt) { + MinetopiaPlayer minetopiaPlayer = PlayerManager.getInstance().getOnlineMinetopiaPlayer(player); + + if (offlinePlayer.getPlayer() == null) { + ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("player_not_found")); + return; + } + + CompletableFuture future = PlayerManager.getInstance().getMinetopiaPlayer(offlinePlayer.getPlayer()); - if (offlinePlayer.getPlayer() == null) return; + future.whenComplete((targetMinetopiaPlayer, throwable) -> { + if (throwable != null) { + throwable.printStackTrace(); + return; + } - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { - if (minetopiaPlayer == null) return; - PlayerManager.getInstance().getMinetopiaPlayerAsync(offlinePlayer.getPlayer(), targetMinetopiaPlayer -> { - if (targetMinetopiaPlayer == null) { - ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("player_not_found")); - return; - } + if (targetMinetopiaPlayer == null) { + ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("player_not_found")); + return; + } - int expiry = expiresAt == null || expiresAt <= 0 ? -1 : expiresAt; - long expiresAtMillis = expiry == -1 ? -1 : System.currentTimeMillis() + (expiry * 1000L); + int expiry = expiresAt == null || expiresAt <= 0 ? -1 : expiresAt; + long expiresAtMillis = expiry == -1 ? -1 : System.currentTimeMillis() + (expiry * 1000L); - targetMinetopiaPlayer.getFitness().addBooster(amount, expiresAtMillis); + targetMinetopiaPlayer.getFitness().addBooster(amount, expiresAtMillis); - ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("fitness_booster_added_to") - .replace("", (offlinePlayer.getName() == null ? "null" : offlinePlayer.getName()))); - }, Throwable::printStackTrace); - }, Throwable::printStackTrace); + ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("fitness_booster_added_to") + .replace("", (offlinePlayer.getName() == null ? "null" : offlinePlayer.getName()))); + }); } } \ No newline at end of file diff --git a/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerChangeWorldListener.java b/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerChangeWorldListener.java index 18d1811..0ebd5af 100644 --- a/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerChangeWorldListener.java +++ b/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerChangeWorldListener.java @@ -13,9 +13,9 @@ public class PlayerChangeWorldListener implements Listener { public void worldChange(final PlayerChangedWorldEvent event) { PlacesModule placesModule = OpenMinetopia.getModuleManager().getModule(PlacesModule.class); if (placesModule.getWorld(event.getFrom().getSpawnLocation()) != null) return; - PlayerManager.getInstance().getMinetopiaPlayerAsync(event.getPlayer(), minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(event.getPlayer()).whenComplete((minetopiaPlayer, throwable1) -> { if (minetopiaPlayer == null) return; minetopiaPlayer.getFitness().getRunnable().run(); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerDeathListener.java b/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerDeathListener.java index 44aaa52..71f661f 100644 --- a/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerDeathListener.java +++ b/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerDeathListener.java @@ -17,7 +17,7 @@ public void playerDeath(final PlayerDeathEvent event) { if (!configuration.isFitnessDeathPunishmentEnabled()) return; Player player = event.getEntity(); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; int punishmentInMillis = configuration.getFitnessDeathPunishmentDuration() * 60 * 1000; @@ -29,6 +29,6 @@ public void playerDeath(final PlayerDeathEvent event) { minetopiaPlayer.getFitness().addBooster(amount, expiry); minetopiaPlayer.getFitness().getRunnable().run(); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerDrinkListener.java b/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerDrinkListener.java index 92031ad..9e2becf 100644 --- a/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerDrinkListener.java +++ b/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerDrinkListener.java @@ -22,7 +22,7 @@ public void playerDrink(final PlayerItemConsumeEvent event) { PotionMeta meta = (PotionMeta) item.getItemMeta(); - PlayerManager.getInstance().getMinetopiaPlayerAsync(event.getPlayer(), minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(event.getPlayer()).whenComplete((minetopiaPlayer, throwable1) -> { if (minetopiaPlayer == null) return; FitnessConfiguration configuration = OpenMinetopia.getFitnessConfiguration(); @@ -62,6 +62,6 @@ public void playerDrink(final PlayerItemConsumeEvent event) { } minetopiaPlayer.getFitness().setStatistic(FitnessStatisticType.DRINKING, drinkingStatistic); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerEatListener.java b/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerEatListener.java index 40f62aa..a2591d8 100644 --- a/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerEatListener.java +++ b/src/main/java/nl/openminetopia/modules/fitness/listeners/PlayerEatListener.java @@ -20,7 +20,7 @@ public void playerEat(final PlayerItemConsumeEvent event) { if (!configuration.getCheapFood().contains(event.getItem().getType().name()) && !configuration.getLuxuryFood().contains(event.getItem().getType().name())) return; - PlayerManager.getInstance().getMinetopiaPlayerAsync(event.getPlayer(), minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(event.getPlayer()).whenComplete((minetopiaPlayer, throwable1) -> { if (minetopiaPlayer == null) return; FitnessStatisticModel eatingStatistic = minetopiaPlayer.getFitness().getStatistic(FitnessStatisticType.EATING); @@ -44,6 +44,6 @@ public void playerEat(final PlayerItemConsumeEvent event) { eatingStatistic.setPoints(0.0); } minetopiaPlayer.getFitness().setStatistic(FitnessStatisticType.EATING, eatingStatistic); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/fitness/utils/FitnessUtils.java b/src/main/java/nl/openminetopia/modules/fitness/utils/FitnessUtils.java index c6be812..97264e1 100644 --- a/src/main/java/nl/openminetopia/modules/fitness/utils/FitnessUtils.java +++ b/src/main/java/nl/openminetopia/modules/fitness/utils/FitnessUtils.java @@ -23,7 +23,7 @@ public class FitnessUtils { public static void applyFitness(Player player) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null || !minetopiaPlayer.isInPlace()) { clearFitnessEffects(player); return; @@ -44,7 +44,7 @@ public static void applyFitness(Player player) { // Apply walk speed and potion effects applyPlayerWalkSpeed(player, config, (float) effectLevel.getWalkSpeed()); applyPotionEffects(player, effectLevel); - }, Throwable::printStackTrace); + }); } private static void applyPlayerWalkSpeed(Player player, FitnessConfiguration config, float walkSpeed) { diff --git a/src/main/java/nl/openminetopia/modules/places/commands/mtcity/subcommands/MTCityCreateCommand.java b/src/main/java/nl/openminetopia/modules/places/commands/mtcity/subcommands/MTCityCreateCommand.java index 8bc68ae..d0a3cdc 100644 --- a/src/main/java/nl/openminetopia/modules/places/commands/mtcity/subcommands/MTCityCreateCommand.java +++ b/src/main/java/nl/openminetopia/modules/places/commands/mtcity/subcommands/MTCityCreateCommand.java @@ -23,7 +23,7 @@ public void create(Player player, String name, String loadingName) { PlacesModule placesModule = OpenMinetopia.getModuleManager().getModule(PlacesModule.class); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; WorldModel world = minetopiaPlayer.getWorld(); @@ -45,7 +45,7 @@ public void create(Player player, String name, String loadingName) { String title = "" + loadingName.toUpperCase(); placesModule.createCity(name, title, "", 21.64, loadingName) - .whenComplete((cityModel, throwable) -> { + .whenComplete((cityModel, throwable1) -> { if (throwable != null) { player.sendMessage(ChatUtils.color("Failed to create city: " + throwable.getMessage())); return; @@ -58,6 +58,6 @@ public void create(Player player, String name, String loadingName) { } player.sendMessage(ChatUtils.color("Region " + name + " does not exist!")); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/places/commands/mtworld/subcommands/MTWorldCreateCommand.java b/src/main/java/nl/openminetopia/modules/places/commands/mtworld/subcommands/MTWorldCreateCommand.java index 6cf8956..6aa4e40 100644 --- a/src/main/java/nl/openminetopia/modules/places/commands/mtworld/subcommands/MTWorldCreateCommand.java +++ b/src/main/java/nl/openminetopia/modules/places/commands/mtworld/subcommands/MTWorldCreateCommand.java @@ -39,11 +39,11 @@ public void create(Player player, String loadingName) { player.sendMessage(ChatUtils.color("World " + loadingName + " has been created!")); for (Player worldPlayer : player.getWorld().getPlayers()) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(worldPlayer, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(worldPlayer).whenComplete((minetopiaPlayer, throwable1) -> { if (minetopiaPlayer == null) return; minetopiaPlayer.getFitness().getRunnable().run(); - }, Throwable::printStackTrace); + }); } } } diff --git a/src/main/java/nl/openminetopia/modules/places/listeners/PlayerJoinListener.java b/src/main/java/nl/openminetopia/modules/places/listeners/PlayerJoinListener.java index 5cd3e47..2db220f 100644 --- a/src/main/java/nl/openminetopia/modules/places/listeners/PlayerJoinListener.java +++ b/src/main/java/nl/openminetopia/modules/places/listeners/PlayerJoinListener.java @@ -15,7 +15,7 @@ public class PlayerJoinListener implements Listener { public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (!minetopiaPlayer.isInPlace() || minetopiaPlayer.getPlace() == null) return; @@ -25,7 +25,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { ChatUtils.format(minetopiaPlayer, MessageConfiguration.message("place_enter_subtitle")) ); player.showTitle(title); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/places/listeners/PlayerMoveListener.java b/src/main/java/nl/openminetopia/modules/places/listeners/PlayerMoveListener.java index a592eca..5f29f77 100644 --- a/src/main/java/nl/openminetopia/modules/places/listeners/PlayerMoveListener.java +++ b/src/main/java/nl/openminetopia/modules/places/listeners/PlayerMoveListener.java @@ -20,7 +20,7 @@ public void onPlayerMove(PlayerMoveEvent event) { Bukkit.getScheduler().runTaskAsynchronously(OpenMinetopia.getInstance(), () -> { Player player = event.getPlayer(); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (!minetopiaPlayer.isInPlace() || minetopiaPlayer.getPlace() == null) return; @@ -36,7 +36,7 @@ public void onPlayerMove(PlayerMoveEvent event) { ); player.showTitle(title); - }, Throwable::printStackTrace); + }); }); } diff --git a/src/main/java/nl/openminetopia/modules/places/listeners/PlayerTeleportListener.java b/src/main/java/nl/openminetopia/modules/places/listeners/PlayerTeleportListener.java index 94ce619..0e553ee 100644 --- a/src/main/java/nl/openminetopia/modules/places/listeners/PlayerTeleportListener.java +++ b/src/main/java/nl/openminetopia/modules/places/listeners/PlayerTeleportListener.java @@ -16,7 +16,7 @@ public class PlayerTeleportListener implements Listener { @EventHandler public void onPlayerTeleport(PlayerTeleportEvent event) { Player player = event.getPlayer(); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (!minetopiaPlayer.isInPlace() || minetopiaPlayer.getPlace() == null) return; @@ -31,6 +31,6 @@ public void onPlayerTeleport(PlayerTeleportEvent event) { ChatUtils.format(minetopiaPlayer, MessageConfiguration.message("place_enter_subtitle")) ); player.showTitle(title); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/player/PlayerModule.java b/src/main/java/nl/openminetopia/modules/player/PlayerModule.java index efdf579..1024fd7 100644 --- a/src/main/java/nl/openminetopia/modules/player/PlayerModule.java +++ b/src/main/java/nl/openminetopia/modules/player/PlayerModule.java @@ -44,12 +44,12 @@ public void enable() { @Override public void disable() { for (Player player : Bukkit.getOnlinePlayers()) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; - minetopiaPlayer.save().whenComplete((unused, throwable) -> { + minetopiaPlayer.save().whenComplete((unused, throwable1) -> { if (throwable != null) throwable.printStackTrace(); }); - }, Throwable::printStackTrace); + }); } } @@ -61,6 +61,9 @@ private CompletableFuture> findPlayerModel(@NotNull UUID u .where("uuid", Where.EQUAL, uuid.toString()) .limit(1).execute().join(); + System.out.println("Found " + playerModel.size() + " player models for " + uuid); + System.out.println("Found player model: " + playerModel.stream().findFirst().get().getUniqueId()); + Bukkit.getScheduler().runTaskLaterAsynchronously(OpenMinetopia.getInstance(), () -> completableFuture.complete(playerModel.stream().findFirst()), 1L); } catch (Exception exception) { exception.printStackTrace(); @@ -70,8 +73,9 @@ private CompletableFuture> findPlayerModel(@NotNull UUID u return completableFuture; } - public CompletableFuture playerLoadFuture = new CompletableFuture<>(); - public CompletableFuture loadPlayer(UUID uuid) { + public CompletableFuture getPlayerModel(UUID uuid) { + CompletableFuture future = new CompletableFuture<>(); + findPlayerModel(uuid).thenAccept(playerModel -> { if (playerModel.isEmpty()) { PlayerModel createdModel = new PlayerModel(); @@ -89,15 +93,15 @@ public CompletableFuture loadPlayer(UUID uuid) { createdModel.setPrefixes(new ArrayList<>()); createdModel.setColors(new ArrayList<>()); createdModel.setFitnessReset(false); - playerLoadFuture.complete(createdModel); + future.complete(createdModel); StormDatabase.getInstance().saveStormModel(createdModel); return; } - playerLoadFuture.complete(playerModel.get()); + future.complete(playerModel.get()); }); - return playerLoadFuture; + return future; } } \ No newline at end of file diff --git a/src/main/java/nl/openminetopia/modules/player/commands/PlaytimeCommand.java b/src/main/java/nl/openminetopia/modules/player/commands/PlaytimeCommand.java index f5774e2..2a2bf74 100644 --- a/src/main/java/nl/openminetopia/modules/player/commands/PlaytimeCommand.java +++ b/src/main/java/nl/openminetopia/modules/player/commands/PlaytimeCommand.java @@ -21,7 +21,7 @@ public class PlaytimeCommand extends BaseCommand { @Description("Get your or another player's playtime.") public void playtime(Player player, @Optional OfflinePlayer target) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) { ChatUtils.sendMessage(player, MessageConfiguration.message("database_read_error")); return; @@ -33,7 +33,7 @@ public void playtime(Player player, @Optional OfflinePlayer target) { return; } - PlayerManager.getInstance().getMinetopiaPlayerAsync(target, targetMinetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(target).whenComplete((targetMinetopiaPlayer, throwable1) -> { if (targetMinetopiaPlayer == null) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("player_not_found")); return; @@ -42,13 +42,7 @@ public void playtime(Player player, @Optional OfflinePlayer target) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("player_time_other_player") .replace("", target.getName() == null ? "null" : target.getName()) .replace("", PlaytimeUtil.formatPlaytime(targetMinetopiaPlayer.getPlaytime()))); - }, throwable -> { - throwable.printStackTrace(); - ChatUtils.sendMessage(player, MessageConfiguration.message("database_read_error")); }); - }, throwable -> { - throwable.printStackTrace(); - ChatUtils.sendMessage(player, MessageConfiguration.message("database_read_error")); }); } } diff --git a/src/main/java/nl/openminetopia/modules/player/listeners/PlayerPreLoginListener.java b/src/main/java/nl/openminetopia/modules/player/listeners/PlayerPreLoginListener.java index e108ee3..32c17a1 100644 --- a/src/main/java/nl/openminetopia/modules/player/listeners/PlayerPreLoginListener.java +++ b/src/main/java/nl/openminetopia/modules/player/listeners/PlayerPreLoginListener.java @@ -4,6 +4,8 @@ import nl.openminetopia.api.player.PlayerManager; import nl.openminetopia.configuration.MessageConfiguration; import nl.openminetopia.modules.player.PlayerModule; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; @@ -17,7 +19,22 @@ public void playerPreLogin(final AsyncPlayerPreLoginEvent event) { PlayerModule playerModule = OpenMinetopia.getModuleManager().getModule(PlayerModule.class); try { - playerModule.loadPlayer(event.getUniqueId()); + OfflinePlayer player = Bukkit.getOfflinePlayer(event.getUniqueId()); + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { + if (throwable != null) { + event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, MessageConfiguration.component("player_data_not_loaded")); + OpenMinetopia.getInstance().getLogger().warning("Error loading player model: " + throwable.getMessage()); + return; + } + + if (minetopiaPlayer == null) { + event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, MessageConfiguration.component("player_data_not_loaded")); + OpenMinetopia.getInstance().getLogger().warning("Error loading player model: Player not found"); + return; + } + + OpenMinetopia.getInstance().getLogger().info("Loaded MinetopiaPlayer " + player.getName()); + }); } catch (Exception e) { event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, MessageConfiguration.component("player_data_not_loaded")); OpenMinetopia.getInstance().getLogger().warning("Error loading player model: " + e.getMessage()); diff --git a/src/main/java/nl/openminetopia/modules/player/listeners/PlayerQuitListener.java b/src/main/java/nl/openminetopia/modules/player/listeners/PlayerQuitListener.java index 0539dea..c267bf2 100644 --- a/src/main/java/nl/openminetopia/modules/player/listeners/PlayerQuitListener.java +++ b/src/main/java/nl/openminetopia/modules/player/listeners/PlayerQuitListener.java @@ -21,12 +21,12 @@ public void onPlayerQuit(PlayerQuitEvent event) { bankingModule.getBankAccountModels().remove(accountModel); accountModel.getSavingTask().saveAndCancel(); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; - minetopiaPlayer.save().whenComplete((unused, throwable) -> { - if (throwable != null) { - throwable.printStackTrace(); + minetopiaPlayer.save().whenComplete((unused, throwable1) -> { + if (throwable1 != null) { + throwable1.printStackTrace(); return; } OpenMinetopia.getInstance().getLogger().info("Saved player data for " + player.getName()); @@ -38,6 +38,6 @@ public void onPlayerQuit(PlayerQuitEvent event) { minetopiaPlayer.getLevelcheckRunnable().cancel(); PlayerManager.getInstance().getOnlinePlayers().remove(player.getUniqueId()); - }, Throwable::printStackTrace); + }); } } \ No newline at end of file diff --git a/src/main/java/nl/openminetopia/modules/player/utils/LevelUtil.java b/src/main/java/nl/openminetopia/modules/player/utils/LevelUtil.java index 9259aed..2deebfa 100644 --- a/src/main/java/nl/openminetopia/modules/player/utils/LevelUtil.java +++ b/src/main/java/nl/openminetopia/modules/player/utils/LevelUtil.java @@ -17,23 +17,10 @@ public static int calculateLevel(MinetopiaPlayer minetopiaPlayer) { LevelCheckConfiguration configuration = OpenMinetopia.getLevelcheckConfiguration(); double points = 0; - // TODO: Add points per vehicle - // Points per 5k balance BankAccountModel accountModel = OpenMinetopia.getModuleManager().getModule(BankingModule.class).getAccountById(minetopiaPlayer.getUuid()); - - double balance; - if (accountModel == null) { - balance = 0; - } else { - balance = accountModel.getBalance(); - } - - if (balance >= 5000) { - for (double tempBalance = balance; tempBalance >= 5000; tempBalance -= 5000) { - points += configuration.getPointsPer5KBalance(); - } - } + double balance = (accountModel == null) ? 0 : accountModel.getBalance(); + points += Math.floor(balance / 5000) * configuration.getPointsPer5KBalance(); // Points for having a prefix if (minetopiaPlayer.getPrefixes() != null && !minetopiaPlayer.getPrefixes().isEmpty()) { @@ -43,30 +30,22 @@ public static int calculateLevel(MinetopiaPlayer minetopiaPlayer) { // Points per 20 fitness Fitness fitness = minetopiaPlayer.getFitness(); if (fitness == null) return 0; - for (int i = fitness.getTotalFitness(); i >= 20; i -= 20) { - points += configuration.getPointsPer20Fitness(); - } + points += (double) (fitness.getTotalFitness() / 20) * configuration.getPointsPer20Fitness(); // Points per 1 hour playtime - for (int playtime = minetopiaPlayer.getPlaytime(); playtime >= 3600; playtime -= 3600) { - points += configuration.getPointsPerHourPlayed(); - } + points += (double) (minetopiaPlayer.getPlaytime() / 3600) * configuration.getPointsPerHourPlayed(); // Points per plot Player player = minetopiaPlayer.getBukkit().getPlayer(); if (player == null) return OpenMinetopia.getDefaultConfiguration().getDefaultLevel(); + points += WorldGuardUtils.getOwnedRegions(player) * configuration.getPointsPerPlot(); - for (int plots = WorldGuardUtils.getOwnedRegions(player); plots >= 1; plots--) { - points += configuration.getPointsPerPlot(); - } - int neededPoints = configuration.getPointsNeededForLevelUp(); int level = (int) Math.floor(points / neededPoints); level = Math.max(OpenMinetopia.getDefaultConfiguration().getDefaultLevel(), Math.min(level, OpenMinetopia.getLevelcheckConfiguration().getMaxLevel())); - return level; } -} +} \ No newline at end of file diff --git a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotClearCommand.java b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotClearCommand.java index 9a92b27..1be11de 100644 --- a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotClearCommand.java +++ b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotClearCommand.java @@ -22,7 +22,7 @@ public class PlotClearCommand extends BaseCommand { public void plotClear(Player player) { ProtectedRegion region = WorldGuardUtils.getProtectedRegion(player.getLocation(), priority -> priority >= 0); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (region == null) { @@ -39,6 +39,6 @@ public void plotClear(Player player) { region.getMembers().clear(); player.sendMessage(MessageConfiguration.component("plot_clear_success")); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotCreateCommand.java b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotCreateCommand.java index 24e066d..d1c6a7c 100644 --- a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotCreateCommand.java +++ b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotCreateCommand.java @@ -39,7 +39,7 @@ public void plotCreate(Player player, String name, @Optional Boolean topToDown) BukkitPlayer bukkitPlayer = BukkitAdapter.adapt(player); World bukkitWorld = player.getWorld(); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; boolean doTopToDown = topToDown == null || topToDown; @@ -83,6 +83,6 @@ public void plotCreate(Player player, String name, @Optional Boolean topToDown) } catch (IncompleteRegionException e) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("plot_no_selection")); } - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotDeleteCommand.java b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotDeleteCommand.java index 8514d62..d50e4f5 100644 --- a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotDeleteCommand.java +++ b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotDeleteCommand.java @@ -32,7 +32,7 @@ public void deletePlot(Player player, String name) { RegionContainer regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionManager regionManager = regionContainer.get(world); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (regionManager == null) { @@ -52,6 +52,6 @@ public void deletePlot(Player player, String name) { player.sendMessage(MessageConfiguration.component("plot_deletion_success")); regionManager.removeRegion(region.getId()); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotDescriptionCommand.java b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotDescriptionCommand.java index d14f99e..ef6b928 100644 --- a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotDescriptionCommand.java +++ b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotDescriptionCommand.java @@ -25,7 +25,7 @@ public class PlotDescriptionCommand extends BaseCommand { public void plotDescription(Player player, String description) { ProtectedRegion region = WorldGuardUtils.getProtectedRegion(player.getLocation(), priority -> priority >= 0); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (region == null) { @@ -50,6 +50,6 @@ public void plotDescription(Player player, String description) { ChatUtils.sendMessage(player, MessageConfiguration.message("plot_description_updated") .replace("", description) .replace("", region.getId())); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotInfoCommand.java b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotInfoCommand.java index 7f4a365..cc13b36 100644 --- a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotInfoCommand.java +++ b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotInfoCommand.java @@ -25,7 +25,7 @@ public class PlotInfoCommand extends BaseCommand { public void plotInfo(Player player) { ProtectedRegion region = WorldGuardUtils.getProtectedRegion(player.getLocation(), priority -> priority >= 0); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (region == null) { @@ -63,6 +63,6 @@ public void plotInfo(Player player) { } ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("plot_info_footer")); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotListCommand.java b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotListCommand.java index 39ca879..8fdd4ee 100644 --- a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotListCommand.java +++ b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotListCommand.java @@ -34,7 +34,7 @@ public void listCommand(Player player, @Optional Integer page) { RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionManager manager = container.get(world); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (manager == null) { @@ -64,6 +64,6 @@ public void listCommand(Player player, @Optional Integer page) { } player.sendMessage(ChatUtils.format(minetopiaPlayer, "Pagina " + finalPage + "/" + totalPages + ". Totaal: " + regionNames.size() + " regio's.")); - }, Throwable::printStackTrace); + }); } } \ No newline at end of file diff --git a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotTeleportCommand.java b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotTeleportCommand.java index f54e5be..62cc88a 100644 --- a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotTeleportCommand.java +++ b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotTeleportCommand.java @@ -33,7 +33,7 @@ public void tpCommand(Player player, String name) { RegionContainer regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionManager regionManager = regionContainer.get(world); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (regionManager == null) { @@ -52,6 +52,6 @@ public void tpCommand(Player player, String name) { Location location = new Location(player.getWorld(), center.x(), center.y(), center.z()); player.teleport(location); player.sendMessage(ChatUtils.format(minetopiaPlayer, "Je bent naar plot " + region.getId() + " geteleporteerd.")); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotTransferCommand.java b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotTransferCommand.java index c31cadd..4d7b897 100644 --- a/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotTransferCommand.java +++ b/src/main/java/nl/openminetopia/modules/plots/commands/subcommands/PlotTransferCommand.java @@ -20,7 +20,7 @@ public class PlotTransferCommand extends BaseCommand { public void plotTransfer(Player player, Boolean transferable) { ProtectedRegion region = WorldGuardUtils.getProtectedRegion(player.getLocation(), priority -> priority >= 0); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (region == null) { @@ -43,6 +43,6 @@ public void plotTransfer(Player player, Boolean transferable) { region.setFlag(OpenMinetopia.PLOT_TRANSFER, StateFlag.State.ALLOW); ChatUtils.sendMessage(player, MessageConfiguration.message("plot_set_tranferable") .replace("", region.getId())); - }, Throwable::printStackTrace); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/police/commands/BodysearchCommand.java b/src/main/java/nl/openminetopia/modules/police/commands/BodysearchCommand.java index 23da31f..5f77b7d 100644 --- a/src/main/java/nl/openminetopia/modules/police/commands/BodysearchCommand.java +++ b/src/main/java/nl/openminetopia/modules/police/commands/BodysearchCommand.java @@ -22,13 +22,13 @@ public class BodysearchCommand extends BaseCommand { @CommandPermission("openminetopia.bodysearch") public void bodysearch(Player player, OnlinePlayer onlineTarget) { Player target = onlineTarget.getPlayer(); - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (player == target) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("police_bodysearch_self")); return; } - PlayerManager.getInstance().getMinetopiaPlayerAsync(target, minetopiaTarget -> { + PlayerManager.getInstance().getMinetopiaPlayer(target).whenComplete((minetopiaTarget, throwable1) -> { if (minetopiaTarget == null) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("player_not_found")); return; @@ -49,7 +49,7 @@ public void bodysearch(Player player, OnlinePlayer onlineTarget) { .replace("", player.getName())); player.openInventory(target.getInventory()); - }, Throwable::printStackTrace); - }, Throwable::printStackTrace); + }); + }); } } diff --git a/src/main/java/nl/openminetopia/modules/police/commands/CriminalRecordCommand.java b/src/main/java/nl/openminetopia/modules/police/commands/CriminalRecordCommand.java index aba3ebe..e55e1f0 100644 --- a/src/main/java/nl/openminetopia/modules/police/commands/CriminalRecordCommand.java +++ b/src/main/java/nl/openminetopia/modules/police/commands/CriminalRecordCommand.java @@ -34,7 +34,7 @@ public void onHelp(CommandHelp help) { @CommandCompletion("@players") @CommandPermission("openminetopia.criminalrecord.add") public void add(Player player, OfflinePlayer target, String description) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (target == null) { @@ -42,15 +42,15 @@ public void add(Player player, OfflinePlayer target, String description) { return; } - PlayerManager.getInstance().getMinetopiaPlayerAsync(target, targetMinetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(target).whenComplete((targetMinetopiaPlayer, throwable1) -> { if (targetMinetopiaPlayer == null) return; targetMinetopiaPlayer.addCriminalRecord(description, player.getUniqueId(), System.currentTimeMillis()); ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("police_criminal_record_added") .replace("", (target.getName() == null ? "Onbekend" : target.getName())) .replace("", description)); - }, Throwable::printStackTrace); - }, Throwable::printStackTrace); + }); + }); } @Subcommand("remove") @@ -60,7 +60,7 @@ public void add(Player player, OfflinePlayer target, String description) { @CommandPermission("openminetopia.criminalrecord.remove") public void remove(Player player, OfflinePlayer target, int id) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (target == null) { @@ -68,7 +68,7 @@ public void remove(Player player, OfflinePlayer target, int id) { return; } - PlayerManager.getInstance().getMinetopiaPlayerAsync(target, targetMinetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(target).whenComplete((targetMinetopiaPlayer, throwable1) -> { if (targetMinetopiaPlayer == null) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("player_not_found")); return; @@ -86,8 +86,8 @@ public void remove(Player player, OfflinePlayer target, int id) { } ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("police_criminal_record_not_found")); - }, Throwable::printStackTrace); - }, Throwable::printStackTrace); + }); + }); } @Subcommand("info") @@ -97,7 +97,7 @@ public void remove(Player player, OfflinePlayer target, int id) { @CommandPermission("openminetopia.criminalrecord.info") public void info(Player player, OfflinePlayer target) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { if (minetopiaPlayer == null) return; if (target == null) { @@ -105,7 +105,7 @@ public void info(Player player, OfflinePlayer target) { return; } - PlayerManager.getInstance().getMinetopiaPlayerAsync(target, targetMinetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(target).whenComplete((targetMinetopiaPlayer, throwable1) -> { if (targetMinetopiaPlayer == null) { ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("player_not_found")); return; @@ -127,8 +127,8 @@ public void info(Player player, OfflinePlayer target) { .replace("", (officer.getName() == null ? "Onbekend" : officer.getName())) .replace("", formatDate(criminalRecord.getDate()))); }); - }, Throwable::printStackTrace); - }, Throwable::printStackTrace); + }); + }); } private final SimpleDateFormat dateFormat = new SimpleDateFormat(MessageConfiguration.message("police_criminal_record_date_format")); diff --git a/src/main/java/nl/openminetopia/modules/police/commands/EmergencyCommand.java b/src/main/java/nl/openminetopia/modules/police/commands/EmergencyCommand.java index 9e3ebc2..2d73c8a 100644 --- a/src/main/java/nl/openminetopia/modules/police/commands/EmergencyCommand.java +++ b/src/main/java/nl/openminetopia/modules/police/commands/EmergencyCommand.java @@ -17,23 +17,23 @@ public class EmergencyCommand extends BaseCommand { @Default public void emergency(Player player, String message) { if (hasCooldown(player)) { - PlayerManager.getInstance().getMinetopiaPlayerAsync(player, minetopiaPlayer -> { + PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete((minetopiaPlayer, throwable) -> { long cooldown = OpenMinetopia.getModuleManager().getModule(PoliceModule.class).getEmergencyCooldowns().get(player.getUniqueId()); ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("emergency_too_soon")); ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("emergency_cooldown") .replace("