From 065f2d5e8463cf43f308affc3500a5678cfcf68d Mon Sep 17 00:00:00 2001 From: acrylic-style Date: Sun, 17 Apr 2022 11:16:14 +0900 Subject: [PATCH] Fetch player asynchronously --- .../spigot/commands/GiveGamingSaraCommand.java | 16 +++++++++------- .../spigot/commands/GiveSaraCommand.java | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/commands/GiveGamingSaraCommand.java b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/commands/GiveGamingSaraCommand.java index e381f23..95049e2 100644 --- a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/commands/GiveGamingSaraCommand.java +++ b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/commands/GiveGamingSaraCommand.java @@ -17,13 +17,15 @@ public void execute(@NotNull CommandSender sender, @NotNull String[] args) { sender.sendMessage(ChatColor.RED + "Usage: " + getFullUsage()); return; } - Player target = PlayerUtil.getOfflinePlayer(args[0]); - boolean res = Protocol.P_GIVE_GAMING_SARA.sendPacket(SpigotPlugin.getAnyPacketSenderOrNull(), new PlayerMessage(target)); - if (res) { - sender.sendMessage(ChatColor.GREEN + "Sent a request to give " + target.getUsername() + " the gaming sara"); - } else { - sender.sendMessage(ChatColor.RED + "Failed to send the packet (attempted to give " + target.getUsernameOrUniqueId() + " the gaming sara). Maybe check console for errors?"); - } + new Thread(() -> { + Player target = PlayerUtil.getOfflinePlayer(args[0]); + boolean res = Protocol.P_GIVE_GAMING_SARA.sendPacket(SpigotPlugin.getAnyPacketSenderOrNull(), new PlayerMessage(target)); + if (res) { + sender.sendMessage(ChatColor.GREEN + "Sent a request to give " + target.getUsername() + " the gaming sara"); + } else { + sender.sendMessage(ChatColor.RED + "Failed to send the packet (attempted to give " + target.getUsernameOrUniqueId() + " the gaming sara). Maybe check console for errors?"); + } + }).start(); } @Override diff --git a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/commands/GiveSaraCommand.java b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/commands/GiveSaraCommand.java index 8b42050..014fd97 100644 --- a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/commands/GiveSaraCommand.java +++ b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/commands/GiveSaraCommand.java @@ -18,13 +18,15 @@ public void execute(@NotNull CommandSender sender, @NotNull String[] args) { return; } int amount = Integer.parseInt(args[0]); - Player target = PlayerUtil.getOfflinePlayer(args[1]); - boolean res = Protocol.P_GIVE_SARA.sendPacket(SpigotPlugin.getAnyPacketSenderOrNull(), new ProxyboundGiveSaraMessage(amount, target)); - if (res) { - sender.sendMessage(ChatColor.GREEN + "Sent a request to give " + target.getUsername() + " the " + amount + "yen sara"); - } else { - sender.sendMessage(ChatColor.RED + "Failed to send the packet (attempted to give " + target.getUsernameOrUniqueId() + " the " + amount + "yen sara). Maybe check console for errors?"); - } + new Thread(() -> { + Player target = PlayerUtil.getOfflinePlayer(args[1]); + boolean res = Protocol.P_GIVE_SARA.sendPacket(SpigotPlugin.getAnyPacketSenderOrNull(), new ProxyboundGiveSaraMessage(amount, target)); + if (res) { + sender.sendMessage(ChatColor.GREEN + "Sent a request to give " + target.getUsername() + " the " + amount + "yen sara"); + } else { + sender.sendMessage(ChatColor.RED + "Failed to send the packet (attempted to give " + target.getUsernameOrUniqueId() + " the " + amount + "yen sara). Maybe check console for errors?"); + } + }).start(); } @Override