(broken) ip bans

This commit is contained in:
Telesphoreo 2024-01-16 21:03:50 -06:00
parent 7bca348587
commit 79206d9354
No known key found for this signature in database
GPG key ID: 9D1991811E093C02
2 changed files with 39 additions and 11 deletions

View file

@ -43,11 +43,26 @@ public class BanListener extends PlexListener
if (plugin.getPunishmentManager().isBanned(event.getUniqueId()))
{
if (Plex.get().getPermissions() != null && Plex.get().getPermissions().playerHas(null, Bukkit.getOfflinePlayer(event.getUniqueId()), "plex.ban.bypass")) return;
if (Plex.get().getPermissions() != null && Plex.get().getPermissions().playerHas(null, Bukkit.getOfflinePlayer(event.getUniqueId()), "plex.ban.bypass"))
{
return;
}
PlexPlayer player = DataUtils.getPlayer(event.getUniqueId());
player.getPunishments().stream().filter(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive()).findFirst().ifPresent(punishment ->
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
Punishment.generateBanMessage(punishment)));
}
else if (plugin.getPunishmentManager().isBanned(event.getAddress().getHostAddress()))
{
// Don't check if the other account that's banned has bypass abilities, check if current has only
if (Plex.get().getPermissions() != null && Plex.get().getPermissions().playerHas(null, Bukkit.getOfflinePlayer(event.getUniqueId()), "plex.ban.bypass"))
{
return;
}
PlexPlayer player = DataUtils.getPlayerByIP(event.getAddress().getHostAddress());
player.getPunishments().stream().filter(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive()).findFirst().ifPresent(punishment ->
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
Punishment.generateBanMessage(punishment)));
}
}
}

View file

@ -7,17 +7,9 @@ import dev.plex.Plex;
import dev.plex.PlexBase;
import dev.plex.cache.DataUtils;
import dev.plex.player.PlexPlayer;
import dev.plex.storage.StorageType;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils;
import lombok.Data;
import lombok.Getter;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@ -28,7 +20,12 @@ import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import lombok.Data;
import lombok.Getter;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.Nullable;
public class PunishmentManager implements PlexBase
{
@ -135,7 +132,6 @@ public class PunishmentManager implements PlexBase
public boolean isBanned(UUID uuid)
{
// TODO: If a person is using MongoDB, this will error out because it is checking for bans on a player that doesn't exist yet
if (!DataUtils.hasPlayedBefore(uuid))
{
return false;
@ -143,6 +139,23 @@ public class PunishmentManager implements PlexBase
return DataUtils.getPlayer(uuid).getPunishments().stream().anyMatch(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive());
}
/*public void isIPBanned(PlexPlayer player)
{
return getActiveBans().whenComplete(((punishments, throwable) ->
punishments.forEach(punishment ->
player.getIps().stream().forEach())
}*/
public boolean isBanned(String ip)
{
final PlexPlayer player = DataUtils.getPlayerByIP(ip);
if (player == null)
{
return false;
}
return player.getPunishments().stream().filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).anyMatch(Punishment::isActive);
}
public boolean isBanned(PlexPlayer player)
{
return isBanned(player.getUuid());