mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
(broken) ip bans
This commit is contained in:
parent
7bca348587
commit
79206d9354
@ -43,11 +43,26 @@ public class BanListener extends PlexListener
|
|||||||
|
|
||||||
if (plugin.getPunishmentManager().isBanned(event.getUniqueId()))
|
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());
|
PlexPlayer player = DataUtils.getPlayer(event.getUniqueId());
|
||||||
player.getPunishments().stream().filter(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive()).findFirst().ifPresent(punishment ->
|
player.getPunishments().stream().filter(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive()).findFirst().ifPresent(punishment ->
|
||||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||||
Punishment.generateBanMessage(punishment)));
|
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)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,17 +7,9 @@ import dev.plex.Plex;
|
|||||||
import dev.plex.PlexBase;
|
import dev.plex.PlexBase;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.storage.StorageType;
|
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -28,7 +20,12 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
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
|
public class PunishmentManager implements PlexBase
|
||||||
{
|
{
|
||||||
@ -135,7 +132,6 @@ public class PunishmentManager implements PlexBase
|
|||||||
|
|
||||||
public boolean isBanned(UUID uuid)
|
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))
|
if (!DataUtils.hasPlayedBefore(uuid))
|
||||||
{
|
{
|
||||||
return false;
|
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());
|
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)
|
public boolean isBanned(PlexPlayer player)
|
||||||
{
|
{
|
||||||
return isBanned(player.getUuid());
|
return isBanned(player.getUuid());
|
||||||
|
Loading…
Reference in New Issue
Block a user