2022-02-07 05:53:57 +00:00
|
|
|
package dev.plex.listener.impl;
|
|
|
|
|
2022-02-22 00:20:22 +00:00
|
|
|
import dev.plex.cache.PlayerCache;
|
2022-02-07 05:53:57 +00:00
|
|
|
import dev.plex.listener.PlexListener;
|
2022-02-22 00:20:22 +00:00
|
|
|
import dev.plex.player.PunishedPlayer;
|
2022-02-26 06:24:11 +00:00
|
|
|
import dev.plex.punishment.Punishment;
|
2022-02-22 00:20:22 +00:00
|
|
|
import dev.plex.punishment.PunishmentType;
|
2022-02-07 05:53:57 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
|
|
|
|
|
|
|
public class BanListener extends PlexListener
|
|
|
|
{
|
|
|
|
@EventHandler
|
|
|
|
public void onPreLogin(AsyncPlayerPreLoginEvent event)
|
|
|
|
{
|
2022-02-22 00:20:22 +00:00
|
|
|
if (plugin.getPunishmentManager().isBanned(event.getUniqueId()))
|
2022-02-07 05:53:57 +00:00
|
|
|
{
|
2022-02-22 00:20:22 +00:00
|
|
|
PunishedPlayer player = PlayerCache.getPunishedPlayer(event.getUniqueId());
|
|
|
|
player.getPunishments().stream().filter(punishment -> punishment.getType() == PunishmentType.BAN && punishment.isActive()).findFirst().ifPresent(punishment ->
|
2022-02-26 06:24:11 +00:00
|
|
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
|
|
|
Punishment.generateBanMessage(punishment)));
|
2022-02-07 05:53:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|