Skip to content

Commit

Permalink
Run kick on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Jan 17, 2025
1 parent 4cf344a commit 90ecbd2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class GlobalLinkServer extends JavaPlugin implements Listener {
public static LinkManager linkManager;
public static Config config;
public static List<String> permittedCommands;
public static Plugin plugin;

public final static Component LINK_INSTRUCTIONS = Component.text("Run the ").color(NamedTextColor.AQUA)
.append(Component.text("`/link`", NamedTextColor.GREEN))
Expand All @@ -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);
Expand Down
31 changes: 20 additions & 11 deletions src/main/java/org/geysermc/globallinkserver/util/CommandUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -92,13 +93,17 @@ public int linkWithCode(CommandContext<CommandSourceStack> 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;
}
Expand All @@ -120,11 +125,15 @@ public int unlink(CommandContext<CommandSourceStack> 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;
}
Expand Down

0 comments on commit 90ecbd2

Please sign in to comment.