From dabd880209729a2fa82a98b4fd0b683a768a8675 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 6 Feb 2024 22:34:23 +0100 Subject: [PATCH] Notify owner on lock blocking join Signed-off-by: Lixfel --- .../bungeecore/commands/BauCommand.java | 6 +--- .../bungeecore/commands/TpCommand.java | 4 +-- src/de/steamwar/bungeecore/util/BauLock.java | 31 +++++++++++++++---- .../steamwar/messages/BungeeCore.properties | 1 + .../messages/BungeeCore_de.properties | 1 + 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index c9e41bd..cd1c36b 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -161,11 +161,7 @@ public class BauCommand extends SWCommand { messageSender.send("BAU_TP_NOALLOWED"); return false; } - if(BauLock.isLocked(value, SteamwarUser.get(p.getUniqueId()))) { - messageSender.send("BAU_LOCKED_NOALLOWED"); - return false; - } - return true; + return !BauLock.checkNotifyLocked(value, p); }; } diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index b67fe1d..b98414d 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -20,7 +20,6 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.tablist.TablistManager; import de.steamwar.sql.*; import de.steamwar.bungeecore.util.BauLock; import de.steamwar.bungeecore.util.Chat19; @@ -122,8 +121,7 @@ public class TpCommand extends SWCommand { sender.system("JOIN_PLAYER_BLOCK"); return; } - } else if (BauLock.isLocked(SteamwarUser.get(bauserver.getOwner()), sender.user())) { - sender.system("BAU_LOCKED_NOALLOWED"); + } else if (BauLock.checkNotifyLocked(SteamwarUser.get(bauserver.getOwner()), player)) { return; } else if (!bauserver.getOwner().equals(player.getUniqueId()) && BauweltMember.getBauMember(bauserver.getOwner(), player.getUniqueId()) == null) { SubserverSystem.sendDeniedMessage(player, bauserver.getOwner()); diff --git a/src/de/steamwar/bungeecore/util/BauLock.java b/src/de/steamwar/bungeecore/util/BauLock.java index 238650d..e47dabe 100644 --- a/src/de/steamwar/bungeecore/util/BauLock.java +++ b/src/de/steamwar/bungeecore/util/BauLock.java @@ -20,10 +20,12 @@ package de.steamwar.bungeecore.util; import de.steamwar.bungeecore.Message; +import de.steamwar.messages.ChatSender; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserConfig; import de.steamwar.sql.UserPerm; import lombok.experimental.UtilityClass; +import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; @UtilityClass @@ -36,27 +38,44 @@ public class BauLock { Message.send("BAU_LOCKED_" + state.name(), p); } - public static boolean isLocked(SteamwarUser owner, SteamwarUser target) { + public static boolean checkNotifyLocked(SteamwarUser owner, ProxiedPlayer player) { + ChatSender sender = ChatSender.of(player); + SteamwarUser target = sender.user(); if (owner.getId() == target.getId()) return false; + boolean locked; String state = UserConfig.getConfig(owner.getId(), BAU_LOCK_CONFIG_NAME); switch (state == null ? BauLockState.OPEN : BauLockState.valueOf(state)) { case NOBODY: - return true; + locked = true; + break; case SERVERTEAM: - return !target.hasPerm(UserPerm.TEAM); + locked = !target.hasPerm(UserPerm.TEAM); + break; case TEAM_AND_SERVERTEAM: if (target.hasPerm(UserPerm.TEAM)) { return false; } - return owner.getTeam() != target.getTeam(); + locked = owner.getTeam() != target.getTeam(); + break; case TEAM: - return owner.getTeam() != target.getTeam(); + locked = owner.getTeam() != target.getTeam(); + break; case OPEN: default: - return false; + locked = false; } + + if(locked) { + sender.system("BAU_LOCKED_NOALLOWED"); + + ProxiedPlayer ownerPlayer = ProxyServer.getInstance().getPlayer(owner.getUUID()); + if(ownerPlayer != null) + ChatSender.of(ownerPlayer).system("BAU_LOCK_BLOCKED", player.getName()); + } + + return locked; } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 1c62ad3..d1e2a3c 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -210,6 +210,7 @@ BAU_ADDMEMBER_ADDED_TARGET=§aYou have been added to the world of §e{0}§a. BAU_TP_USAGE=§8/§7build tp §8[§eplayer§8] BAU_TP_NOALLOWED=§cYou are not allowed to teleport to this player's world. BAU_LOCKED_NOALLOWED=§cThe build server is currently locked. +BAU_LOCK_BLOCKED=§cYour build lock has prevented §e{0} §cfrom joining. BAU_LOCKED_OPTIONS=§7Build server lock options§8: §cnobody§8, §eserverteam§8, §eteam_and_serverteam§8, §eteam§8, §aopen BAU_LOCKED_NOBODY=§7You have locked your build server for all players. BAU_LOCKED_SERVERTEAM=§7You have locked your build server for all players except added server team members. diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index a0d4b27..8d23f5e 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -193,6 +193,7 @@ BAU_ADDMEMBER_ADDED_TARGET=§aDu wurdest zu der Welt von §e{0} §ahinzugefügt. BAU_TP_USAGE=§8/§7bau tp §8[§eSpieler§8] BAU_TP_NOALLOWED=§cDu darfst dich nicht auf diese Welt teleportieren. BAU_LOCKED_NOALLOWED=§cDer Bauserver ist momentan gesperrt. +BAU_LOCK_BLOCKED=§cDeine Bausperre hat den Beitritt von §e{0} §cverhindert. BAU_LOCKED_OPTIONS=§7Bauserver-Sperroptionen§8: §cnobody§8, §eserverteam§8, §eteam_and_serverteam§8, §eteam§8, §aopen BAU_LOCKED_NOBODY=§7Du hast deinen Bau für alle Spieler geschlossen. BAU_LOCKED_SERVERTEAM=§7Du hast deinen Bau für alle außer hinzugefügte Serverteammitglieder gesperrt. -- 2.39.5