Cache whether the server is on a proxy or not

Fix kick where ban message was displayed instead of kick message
This commit is contained in:
Taah 2023-08-24 22:36:14 -07:00
parent b0240ef46e
commit f97411ce09
5 changed files with 21 additions and 13 deletions

View File

@ -39,14 +39,14 @@ public class BanCMD extends PlexCommand
return usage(); return usage();
} }
UUID targetUUID = WebUtils.getFromName(args[0]); final PlexPlayer plexPlayer = DataUtils.getPlayer(args[0]);
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) if (plexPlayer == null)
{ {
throw new PlayerNotFoundException(); throw new PlayerNotFoundException();
} }
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
Player player = Bukkit.getPlayer(targetUUID); Player player = Bukkit.getPlayer(plexPlayer.getUuid());
if (plugin.getSystem().equalsIgnoreCase("ranks")) if (plugin.getSystem().equalsIgnoreCase("ranks"))
{ {
@ -64,7 +64,7 @@ public class BanCMD extends PlexCommand
} }
} }
plugin.getPunishmentManager().isAsyncBanned(targetUUID).whenComplete((aBoolean, throwable) -> plugin.getPunishmentManager().isAsyncBanned(plexPlayer.getUuid()).whenComplete((aBoolean, throwable) ->
{ {
if (aBoolean) if (aBoolean)
{ {
@ -72,7 +72,7 @@ public class BanCMD extends PlexCommand
return; return;
} }
String reason; String reason;
Punishment punishment = new Punishment(targetUUID, getUUID(sender)); Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
punishment.setType(PunishmentType.BAN); punishment.setType(PunishmentType.BAN);
if (args.length > 1) if (args.length > 1)
{ {

View File

@ -38,21 +38,20 @@ public class KickCMD extends PlexCommand
return usage(); return usage();
} }
UUID targetUUID = WebUtils.getFromName(args[0]); PlexPlayer plexPlayer = DataUtils.getPlayer(args[0]);
String reason = "No reason provided"; String reason = "No reason provided";
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) if (plexPlayer == null)
{ {
throw new PlayerNotFoundException(); throw new PlayerNotFoundException();
} }
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID); Player player = Bukkit.getPlayer(plexPlayer.getUuid());
Player player = Bukkit.getPlayer(targetUUID);
if (player == null) if (player == null)
{ {
throw new PlayerNotFoundException(); throw new PlayerNotFoundException();
} }
Punishment punishment = new Punishment(targetUUID, getUUID(sender)); Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
punishment.setType(PunishmentType.KICK); punishment.setType(PunishmentType.KICK);
if (args.length > 1) if (args.length > 1)
{ {
@ -67,7 +66,7 @@ public class KickCMD extends PlexCommand
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim()); punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
plugin.getPunishmentManager().punish(plexPlayer, punishment); plugin.getPunishmentManager().punish(plexPlayer, punishment);
PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName())); PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName()));
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment)); BungeeUtil.kickPlayer(player, Punishment.generateKickMessage(punishment));
return null; return null;
} }
} }

View File

@ -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 generateKickMessage(Punishment punishment)
{
return PlexUtils.messageComponent("kickMessage", punishment.getReason(), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
}
public static Component generateIndefBanMessageWithReason(String type, String reason) public static Component generateIndefBanMessageWithReason(String type, String reason)
{ {
return PlexUtils.messageComponent("indefBanMessageReason", type, banUrl, reason); return PlexUtils.messageComponent("indefBanMessageReason", type, banUrl, reason);

View File

@ -10,6 +10,7 @@ import org.bukkit.entity.Player;
public class BungeeUtil public class BungeeUtil
{ {
public static final boolean PROXIED_SERVER = isBungeeCord() || isVelocity();
public static boolean isBungeeCord() public static boolean isBungeeCord()
{ {
return Bukkit.spigot().getSpigotConfig().getBoolean("settings.bungeecord"); return Bukkit.spigot().getSpigotConfig().getBoolean("settings.bungeecord");
@ -23,7 +24,7 @@ public class BungeeUtil
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
public static void kickPlayer(Player player, Component message) public static void kickPlayer(Player player, Component message)
{ {
if (isBungeeCord() || isVelocity()) if (PROXIED_SERVER)
{ {
ByteArrayDataOutput out = ByteStreams.newDataOutput(); ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("KickPlayer"); out.writeUTF("KickPlayer");

View File

@ -14,6 +14,9 @@
# 2 - Expiry # 2 - Expiry
# 3 - Punisher # 3 - Punisher
banMessage: "<red>You have been banned! You may appeal at <gold>{0}.\n<red>Reason: <gold>{1}\n<red>End date: <gold>{2}\n<red>Banned by: <gold>{3}" banMessage: "<red>You have been banned! You may appeal at <gold>{0}.\n<red>Reason: <gold>{1}\n<red>End date: <gold>{2}\n<red>Banned by: <gold>{3}"
# 0 - Reason
# 1 - Punisher
kickMessage: "<red>You have been kicked! \n<red>Reason: <gold>{0}\n<red>Kicked by: <gold>{1}"
# 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}."