diff --git a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/SpigotPlugin.java b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/SpigotPlugin.java index efb509d..055faa5 100644 --- a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/SpigotPlugin.java +++ b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/SpigotPlugin.java @@ -61,7 +61,15 @@ public static PacketSender getAnyPacketSenderOrNull() { @EventHandler public void onPlayerJoin(PlayerJoinEvent e) { + PlayerImpl player = PlayerImpl.of(e.getPlayer()); + player.setEncrypted(false); + player.setRemotePublicKeyInternal(null); + int i = player.joins.incrementAndGet(); Bukkit.getScheduler().runTaskLaterAsynchronously(this, () -> { + if (player.joins.get() != i) { + return; + } + KeyPair keyPair; try { // generate keypair @@ -69,7 +77,6 @@ public void onPlayerJoin(PlayerJoinEvent e) { } catch (Exception ex) { throw new RuntimeException(ex); } - PlayerImpl player = PlayerImpl.of(e.getPlayer()); // set keypair player.setKeyPair(keyPair); diff --git a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/entity/PlayerImpl.java b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/entity/PlayerImpl.java index 862b37a..bb57c36 100644 --- a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/entity/PlayerImpl.java +++ b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/entity/PlayerImpl.java @@ -15,6 +15,7 @@ import java.util.Objects; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; public class PlayerImpl implements Player, PacketSender { private static final Map MAP = new ConcurrentHashMap<>(); @@ -23,6 +24,7 @@ public class PlayerImpl implements Player, PacketSender { private PublicKey remotePublicKey; private boolean encrypted = false; public String challenge = null; + public AtomicInteger joins = new AtomicInteger(); @Contract(value = "null -> fail", pure = true) private PlayerImpl(@Nullable org.bukkit.entity.Player handle) {