diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 8e2fb9a..9691ebc 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -23,10 +23,7 @@ import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.network.NetworkSender; -import de.steamwar.bungeecore.sql.BauLockState; -import de.steamwar.bungeecore.sql.BauweltMember; -import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.UserConfig; +import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.server.BaumemberUpdatePacket; @@ -88,10 +85,10 @@ public class BauCommand extends BasicCommand { return; } - setLocked(p, args[1].toUpperCase()); + BauLock.setLocked(p, args[1].toUpperCase()); break; case "unlock": - setLocked(p, "OPEN"); + BauLock.setLocked(p, "OPEN"); break; default: HelpCommand.sendBauHelp(ChatSender.of(p)); @@ -142,7 +139,7 @@ public class BauCommand extends BasicCommand { return; } - if(isLocked(worldOwner, SteamwarUser.get(p))) { + if(BauLock.isLocked(worldOwner, SteamwarUser.get(p))) { Message.send("BAU_LOCKED_NOALLOWED", p); return; } @@ -325,35 +322,4 @@ public class BauCommand extends BasicCommand { Message.send("BAU_MEMBER_TOGGLE_OFF", p, Message.parse(what, p)); } } - - private static final String BAU_LOCK_CONFIG_NAME = "baulockstate"; - private static void setLocked(ProxiedPlayer p, String arg) { - SteamwarUser owner = SteamwarUser.get(p.getUniqueId()); - BauLockState state; - try { - state = BauLockState.valueOf(arg); - } catch (IllegalArgumentException e) { - Message.send("BAU_LOCKED_OPTIONS", owner.getPlayer()); - return; - } - - UserConfig.updateUserConfig(owner.getId(), BAU_LOCK_CONFIG_NAME, state == BauLockState.OPEN ? null : state.name()); - Message.send("BAU_LOCKED_" + state.name(), owner.getPlayer()); - } - - private static boolean isLocked(SteamwarUser owner, SteamwarUser target) { - if (owner.getId() == target.getId()) - return false; - - String state = UserConfig.getConfig(owner.getId(), BAU_LOCK_CONFIG_NAME); - switch (state == null ? BauLockState.OPEN : BauLockState.valueOf(state)) { - case NOBODY: - return true; - case TEAM: - return owner.getTeam() != target.getTeam(); - case OPEN: - default: - return false; - } - } } diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index 1ac1a22..de61885 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -95,7 +95,9 @@ public class TpCommand extends BasicCommand { } else { sender.system("JOIN_PLAYER_BLOCK"); } - } else if (bauserver.getOwner().equals(player.getUniqueId()) || BauweltMember.getBauMember(bauserver.getOwner(), player.getUniqueId()) != null) { + }else if (BauLock.isLocked(SteamwarUser.get(bauserver.getOwner()), sender.user())) { + Message.send("BAU_LOCKED_NOALLOWED", player); + }else if (bauserver.getOwner().equals(player.getUniqueId()) || BauweltMember.getBauMember(bauserver.getOwner(), player.getUniqueId()) != null) { SubserverSystem.sendPlayer(subserver, player); } else { SubserverSystem.sendDeniedMessage(player, bauserver.getOwner()); diff --git a/src/de/steamwar/bungeecore/sql/BauLock.java b/src/de/steamwar/bungeecore/sql/BauLock.java new file mode 100644 index 0000000..8181610 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/BauLock.java @@ -0,0 +1,58 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bungeecore.sql; + +import de.steamwar.bungeecore.Message; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class BauLock { + + private static final String BAU_LOCK_CONFIG_NAME = "baulockstate"; + public static void setLocked(ProxiedPlayer p, String arg) { + SteamwarUser owner = SteamwarUser.get(p.getUniqueId()); + BauLockState state; + try { + state = BauLockState.valueOf(arg); + } catch (IllegalArgumentException e) { + Message.send("BAU_LOCKED_OPTIONS", owner.getPlayer()); + return; + } + + UserConfig.updateUserConfig(owner.getId(), BAU_LOCK_CONFIG_NAME, state == BauLockState.OPEN ? null : state.name()); + Message.send("BAU_LOCKED_" + state.name(), owner.getPlayer()); + } + + public static boolean isLocked(SteamwarUser owner, SteamwarUser target) { + if (owner.getId() == target.getId()) + return false; + + String state = UserConfig.getConfig(owner.getId(), BAU_LOCK_CONFIG_NAME); + switch (state == null ? BauLockState.OPEN : BauLockState.valueOf(state)) { + case NOBODY: + return true; + case TEAM: + return owner.getTeam() != target.getTeam(); + case OPEN: + default: + return false; + } + } + +}