Handling unauthenticated disconnect - server password

This commit is contained in:
LabodiDavid 2025-03-28 19:19:13 +01:00
parent b82f47fb3b
commit 571fa366bc

View File

@ -14,6 +14,8 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.util.UUID;
public class ServerPasswordEvents implements Listener { public class ServerPasswordEvents implements Listener {
private STPlugin plugin; private STPlugin plugin;
private FileConfiguration config; private FileConfiguration config;
@ -79,9 +81,24 @@ public class ServerPasswordEvents implements Listener {
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
if ((!config.getBoolean("ServerPassword.rememberUntilRestart")) Player player = event.getPlayer();
|| (!plugin.getServerPasswordData().getAuthenticatedPlayers().getOrDefault(event.getPlayer().getUniqueId(),false))) { UUID uuid = player.getUniqueId();
plugin.getServerPasswordData().getAuthenticatedPlayers().remove(event.getPlayer().getUniqueId());
if (plugin.getServerPasswordData().getAuthenticatedPlayers().getOrDefault(uuid, false)) {
if (!config.getBoolean("ServerPassword.rememberUntilRestart")) {
plugin.getServerPasswordData().getAuthenticatedPlayers().remove(uuid);
}
} else {
if (plugin.getConfig().getBoolean("ServerPassword.preventInventory")) {
if (plugin.getServerPasswordData().getInventoryMap().containsKey(uuid)) {
player.getInventory().setContents(plugin.getServerPasswordData().getInventoryMap().get(uuid));
plugin.getServerPasswordData().getInventoryMap().remove(uuid);
}
if (plugin.getServerPasswordData().getArmorMap().containsKey(uuid)) {
player.getInventory().setArmorContents(plugin.getServerPasswordData().getArmorMap().get(uuid));
plugin.getServerPasswordData().getArmorMap().remove(uuid);
}
}
} }
} }
} }