diff --git a/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java b/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java index 10eda56..8bc8462 100644 --- a/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java +++ b/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java @@ -46,6 +46,7 @@ public class GlobalLinkServer extends JavaPlugin implements Listener { public static LinkManager linkManager; public static Config config; public static List permittedCommands; + public static Plugin plugin; public final static Component LINK_INSTRUCTIONS = Component.text("Run the ").color(NamedTextColor.AQUA) .append(Component.text("`/link`", NamedTextColor.GREEN)) @@ -59,6 +60,8 @@ public class GlobalLinkServer extends JavaPlugin implements Listener { public void onEnable() { LOGGER = getLogger(); + plugin = this; + config = ConfigReader.readConfig(this); linkManager = new LinkManager(config); diff --git a/src/main/java/org/geysermc/globallinkserver/util/CommandUtils.java b/src/main/java/org/geysermc/globallinkserver/util/CommandUtils.java index 930b47a..1ba3395 100644 --- a/src/main/java/org/geysermc/globallinkserver/util/CommandUtils.java +++ b/src/main/java/org/geysermc/globallinkserver/util/CommandUtils.java @@ -12,6 +12,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.geysermc.globallinkserver.GlobalLinkServer; import org.geysermc.globallinkserver.link.LinkManager; import org.geysermc.globallinkserver.link.TempLink; @@ -92,13 +93,17 @@ public int linkWithCode(CommandContext ctx) { Player javaPlayer = Bukkit.getPlayer(tempLink.javaId()); Player bedrockPlayer = Bukkit.getPlayer(tempLink.bedrockId()); - if (javaPlayer != null) { - javaPlayer.kick(Component.text("You are now successfully linked! :)").color(NamedTextColor.GREEN)); - } + Bukkit.getScheduler().callSyncMethod(GlobalLinkServer.plugin, () -> { + if (javaPlayer != null) { + javaPlayer.kick(Component.text("You are now successfully linked! :)").color(NamedTextColor.GREEN)); + } - if (bedrockPlayer != null) { - bedrockPlayer.kick(Component.text("You are now successfully linked! :)").color(NamedTextColor.GREEN)); - } + if (bedrockPlayer != null) { + bedrockPlayer.kick(Component.text("You are now successfully linked! :)").color(NamedTextColor.GREEN)); + } + + return null; + }); }); return 1; } @@ -120,11 +125,15 @@ public int unlink(CommandContext ctx) { return; } - if (result) { - player.kick(Component.text("You are successfully unlinked.").color(NamedTextColor.GREEN)); - } else { - player.kick(Component.text("You are not linked to any account!").color(NamedTextColor.RED)); - } + Bukkit.getScheduler().callSyncMethod(GlobalLinkServer.plugin, () -> { + if (result) { + player.kick(Component.text("You are successfully unlinked.").color(NamedTextColor.GREEN)); + } else { + player.kick(Component.text("You are not linked to any account!").color(NamedTextColor.RED)); + } + + return null; + }); }); return 1; }