mirror of
https://github.com/plexusorg/Plex.git
synced 2025-01-22 22:20:06 +00:00
Add support for reasons
This commit is contained in:
parent
7dea0bcb72
commit
28ec8e1d2d
@ -5,6 +5,7 @@ import dev.plex.cache.DataUtils;
|
|||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.punishment.Punishment;
|
import dev.plex.punishment.Punishment;
|
||||||
|
import dev.plex.punishment.PunishmentManager;
|
||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -15,24 +16,28 @@ public class BanListener extends PlexListener
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPreLogin(AsyncPlayerPreLoginEvent event)
|
public void onPreLogin(AsyncPlayerPreLoginEvent event)
|
||||||
{
|
{
|
||||||
if (plugin.getPunishmentManager().isIndefUUIDBanned(event.getUniqueId()))
|
final PunishmentManager.IndefiniteBan uuidBan = plugin.getPunishmentManager().getIndefiniteBanByUUID(event.getUniqueId());
|
||||||
|
if (uuidBan != null)
|
||||||
{
|
{
|
||||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||||
Punishment.generateIndefBanMessage("UUID"));
|
uuidBan.getReason() != null ? Punishment.generateIndefBanMessageWithReason("UUID", uuidBan.getReason()) : Punishment.generateIndefBanMessage("UUID"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getPunishmentManager().isIndefIPBanned(event.getAddress().getHostAddress()))
|
final PunishmentManager.IndefiniteBan ipBan = plugin.getPunishmentManager().getIndefiniteBanByIP(event.getAddress().getHostAddress());
|
||||||
|
if (ipBan != null)
|
||||||
{
|
{
|
||||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||||
Punishment.generateIndefBanMessage("IP"));
|
ipBan.getReason() != null ? Punishment.generateIndefBanMessageWithReason("IP", ipBan.getReason()) : Punishment.generateIndefBanMessage("IP"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getPunishmentManager().isIndefUserBanned(event.getName()))
|
final PunishmentManager.IndefiniteBan userBan = plugin.getPunishmentManager().getIndefiniteBanByUsername(event.getName());
|
||||||
|
|
||||||
|
if (userBan != null)
|
||||||
{
|
{
|
||||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||||
Punishment.generateIndefBanMessage("username"));
|
userBan.getReason() != null ? Punishment.generateIndefBanMessageWithReason("username", userBan.getReason()) : Punishment.generateIndefBanMessage("username"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,11 @@ public class Punishment
|
|||||||
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
|
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Component generateIndefBanMessageWithReason(String type, String reason)
|
||||||
|
{
|
||||||
|
return PlexUtils.messageComponent("indefBanMessageReason", type, banUrl, reason);
|
||||||
|
}
|
||||||
|
|
||||||
public static Component generateIndefBanMessage(String type)
|
public static Component generateIndefBanMessage(String type)
|
||||||
{
|
{
|
||||||
return PlexUtils.messageComponent("indefBanMessage", type, banUrl);
|
return PlexUtils.messageComponent("indefBanMessage", type, banUrl);
|
||||||
|
@ -16,6 +16,7 @@ import lombok.Getter;
|
|||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
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;
|
||||||
@ -39,7 +40,7 @@ public class PunishmentManager implements PlexBase
|
|||||||
this.indefiniteBans.clear();
|
this.indefiniteBans.clear();
|
||||||
Plex.get().indefBans.getKeys(false).forEach(key ->
|
Plex.get().indefBans.getKeys(false).forEach(key ->
|
||||||
{
|
{
|
||||||
IndefiniteBan ban = new IndefiniteBan();
|
IndefiniteBan ban = new IndefiniteBan(Plex.get().getIndefBans().getString("reason", ""));
|
||||||
ban.ips.addAll(Plex.get().getIndefBans().getStringList(key + ".ips"));
|
ban.ips.addAll(Plex.get().getIndefBans().getStringList(key + ".ips"));
|
||||||
ban.usernames.addAll(Plex.get().getIndefBans().getStringList(key + ".users"));
|
ban.usernames.addAll(Plex.get().getIndefBans().getStringList(key + ".users"));
|
||||||
ban.uuids.addAll(Plex.get().getIndefBans().getStringList(key + ".uuids").stream().map(UUID::fromString).toList());
|
ban.uuids.addAll(Plex.get().getIndefBans().getStringList(key + ".uuids").stream().map(UUID::fromString).toList());
|
||||||
@ -58,7 +59,8 @@ public class PunishmentManager implements PlexBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIndefUUIDBanned(UUID uuid)
|
@Nullable
|
||||||
|
public IndefiniteBan getIndefiniteBanByUUID(UUID uuid)
|
||||||
{
|
{
|
||||||
if (Plex.get().getRedisConnection().isEnabled())
|
if (Plex.get().getRedisConnection().isEnabled())
|
||||||
{
|
{
|
||||||
@ -66,12 +68,12 @@ public class PunishmentManager implements PlexBase
|
|||||||
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUuids().contains(uuid));
|
return bans.stream().filter(indefiniteBan -> indefiniteBan.getUuids().contains(uuid)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUuids().contains(uuid));
|
return this.indefiniteBans.stream().filter(indefiniteBan -> indefiniteBan.getUuids().contains(uuid)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIndefIPBanned(String ip)
|
public IndefiniteBan getIndefiniteBanByIP(String ip)
|
||||||
{
|
{
|
||||||
if (Plex.get().getRedisConnection().isEnabled())
|
if (Plex.get().getRedisConnection().isEnabled())
|
||||||
{
|
{
|
||||||
@ -79,12 +81,12 @@ public class PunishmentManager implements PlexBase
|
|||||||
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getIps().contains(ip));
|
return bans.stream().filter(indefiniteBan -> indefiniteBan.getIps().contains(ip)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getIps().contains(ip));
|
return this.indefiniteBans.stream().filter(indefiniteBan -> indefiniteBan.getIps().contains(ip)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIndefUserBanned(String username)
|
public IndefiniteBan getIndefiniteBanByUsername(String username)
|
||||||
{
|
{
|
||||||
if (Plex.get().getRedisConnection().isEnabled())
|
if (Plex.get().getRedisConnection().isEnabled())
|
||||||
{
|
{
|
||||||
@ -92,9 +94,9 @@ public class PunishmentManager implements PlexBase
|
|||||||
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUsernames().contains(username));
|
return bans.stream().filter(indefiniteBan -> indefiniteBan.getUsernames().contains(username)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUsernames().contains(username));
|
return this.indefiniteBans.stream().filter(indefiniteBan -> indefiniteBan.getUsernames().contains(username)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void issuePunishment(PlexPlayer plexPlayer, Punishment punishment)
|
public void issuePunishment(PlexPlayer plexPlayer, Punishment punishment)
|
||||||
@ -262,5 +264,6 @@ public class PunishmentManager implements PlexBase
|
|||||||
private final List<String> usernames = Lists.newArrayList();
|
private final List<String> usernames = Lists.newArrayList();
|
||||||
private final List<UUID> uuids = Lists.newArrayList();
|
private final List<UUID> uuids = Lists.newArrayList();
|
||||||
private final List<String> ips = Lists.newArrayList();
|
private final List<String> ips = Lists.newArrayList();
|
||||||
|
private final String reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,10 @@ banMessage: "<red>You have been banned! You may appeal at <gold>{0}.\n<red>Reaso
|
|||||||
# 0 - The type of indefinite ban
|
# 0 - The type of indefinite ban
|
||||||
# 1 - Appeal URL
|
# 1 - Appeal URL
|
||||||
indefBanMessage: "<red>Your {0} is indefinitely banned! You may appeal at <gold>{1}."
|
indefBanMessage: "<red>Your {0} is indefinitely banned! You may appeal at <gold>{1}."
|
||||||
|
# 0 - The type of indefinite ban
|
||||||
|
# 1 - Appeal URL
|
||||||
|
# 2 - The reason
|
||||||
|
indefBanMessageReason: "<red>Your {0} is indefinitely banned! You may appeal at <gold>{1}.\n<red>Reason: <gold>{2}"
|
||||||
playerNotFound: "<red>Player not found!"
|
playerNotFound: "<red>Player not found!"
|
||||||
specifyPlayer: "<red>You must specify a player!"
|
specifyPlayer: "<red>You must specify a player!"
|
||||||
worldNotFound: "<red>World not found!"
|
worldNotFound: "<red>World not found!"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user