From 19dad58712d0339bbffa192c04e9bc822871126d Mon Sep 17 00:00:00 2001 From: MoBrot <90271578+MoBrot@users.noreply.github.com> Date: Sat, 13 Aug 2022 21:18:54 +0200 Subject: [PATCH] Replace BauLock to UserConfig Update BauLockState.ALL to BauLockState.NONE Add "BAU_LOCKED_OPTIONS" in BungeeCore_de.properties Add "BAU_LOCKED_OPTIONS" in BungeeCore.properties --- .../bungeecore/commands/BauCommand.java | 41 +++++++++---------- src/de/steamwar/bungeecore/sql/BauLock.java | 38 ----------------- .../steamwar/bungeecore/sql/BauLockState.java | 6 +-- .../steamwar/bungeecore/sql/UserConfig.java | 38 +++++++++++++++++ .../steamwar/messages/BungeeCore.properties | 6 ++- .../messages/BungeeCore_de.properties | 6 ++- 6 files changed, 69 insertions(+), 66 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/sql/BauLock.java create mode 100644 src/de/steamwar/bungeecore/sql/UserConfig.java diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index fa338efa..20e2e8c3 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -81,11 +81,11 @@ public class BauCommand extends BasicCommand { break; case "lock": - setLocked(SteamwarUser.get(p), args); + setLocked(SteamwarUser.get(p), args[1]); break; case "unlock": - setLocked(SteamwarUser.get(p), new String[]{"", "OPEN"}); + setLocked(SteamwarUser.get(p), "OPEN"); break; default: @@ -127,9 +127,15 @@ public class BauCommand extends BasicCommand { return; } + SteamwarUser worldOwner = SteamwarUser.get(args[1]); SteamwarUser user = SteamwarUser.get(p); + if (worldOwner == null) { + Message.send("UNKNOWN_PLAYER", user.getPlayer()); + return; + } + if(isLocked(worldOwner, user)) { Message.send("BAU_LOCKED_NOALLOWED", user.getPlayer()); return; @@ -321,29 +327,22 @@ public class BauCommand extends BasicCommand { } private static boolean isLocked(SteamwarUser owner, SteamwarUser target) { - if (owner == null) { - Message.send("UNKNOWN_PLAYER", target.getPlayer()); - return true; - } + BauLockState activeLockState = UserConfig.getUserLockState(owner.getId()); + if(activeLockState == null) + activeLockState = BauLockState.OPEN; - BauLockState activeLockState = BauLock.getUserLockState(owner.getId()); - return (activeLockState == BauLockState.TEAM && !(Team.get(owner.getId()) == Team.get(target.getId()))) || activeLockState == BauLockState.ALL; + return activeLockState == BauLockState.NONE || (activeLockState == BauLockState.TEAM && !(Team.get(owner.getId()) == Team.get(target.getId()))); } - private static void setLocked(SteamwarUser owner, String[] args) { - - BauLockState newState = BauLockState.OPEN; - if(args[1] != null) { - BauLockState.valueOf(args[1].toUpperCase()); - newState = BauLockState.valueOf(args[1].toUpperCase()); + private static void setLocked(SteamwarUser owner, String arg) { + if(arg == null || BauLockState.valueOf(arg) == null) { + Message.send("BAU_LOCKED_OPTIONS", owner.getPlayer()); + return; } + UserConfig.updateUserConfig(owner.getId(), UserConfig.lockConfigName, arg.toUpperCase()); - BauLock.updateUserConfig(owner.getId(), newState); - - String messageKey = "BAU_LOCKED"; - if(newState == BauLockState.OPEN) - messageKey = "BAU_UNLOCKED"; - - Message.send(messageKey, owner.getPlayer()); + Message.send("BAU_LOCKED_" + arg, owner.getPlayer()); } + + } diff --git a/src/de/steamwar/bungeecore/sql/BauLock.java b/src/de/steamwar/bungeecore/sql/BauLock.java deleted file mode 100644 index 4a5f5e1f..00000000 --- a/src/de/steamwar/bungeecore/sql/BauLock.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.steamwar.bungeecore.sql; - -public class BauLock { - - private static final String configName = "baulockstate"; - - private static final Statement insert = new Statement("INSERT INTO `UserConfig`(`User`, `Config`, `Value`) VALUES (?,?,?)"); - private static final Statement update = new Statement("UPDATE `UserConfig` SET `Value`= ? WHERE 'User' = ? AND 'Config' = ?"); - private static final Statement select = new Statement("SELECT `Value` FROM `UserConfig` WHERE 'User' = ? AND 'Config' = ?"); - private static final Statement selectAll = new Statement("SELECT * FROM `UserConfig` WHERE 'User' = ? AND Config' = ?"); - - public static BauLockState getUserLockState(int userID) { - select.select(rs -> { - if(rs.next()) - return BauLockState.valueOf(rs.getString("Value")); - return BauLockState.OPEN; - }, userID, configName); - return BauLockState.OPEN; - } - - public static void updateUserConfig(int userID, BauLockState state) { - - if(!exists(userID)) { - insert.update(userID, configName, String.valueOf(state)); - }else - update.update(String.valueOf(state), userID, configName); - } - - private static boolean exists(int userID) { - selectAll.select(rs -> { - if(rs.next()) - return rs.getString(1) != null; - return null; - }, userID, configName); - - return false; - } -} diff --git a/src/de/steamwar/bungeecore/sql/BauLockState.java b/src/de/steamwar/bungeecore/sql/BauLockState.java index 7abb02bf..a3ab2546 100644 --- a/src/de/steamwar/bungeecore/sql/BauLockState.java +++ b/src/de/steamwar/bungeecore/sql/BauLockState.java @@ -2,7 +2,7 @@ package de.steamwar.bungeecore.sql; public enum BauLockState { - ALL, // Locks the build server for all users - OPEN, //locks the build server for every user - TEAM //opens the build server only for every added user which is in the same team as the buildOwner + NONE, // Locks the build server for all users + TEAM, //opens the build server only for every added user which is in the same team as the buildOwner + OPEN //unlocks the build server for all users } diff --git a/src/de/steamwar/bungeecore/sql/UserConfig.java b/src/de/steamwar/bungeecore/sql/UserConfig.java new file mode 100644 index 00000000..3e962ac1 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/UserConfig.java @@ -0,0 +1,38 @@ +package de.steamwar.bungeecore.sql; + +import java.util.UUID; + +public class UserConfig { + + public static final String lockConfigName = "baulockstate"; + + private static final Statement insert = new Statement("INSERT INTO `UserConfig`(`User`, `Config`, `Value`) VALUES (?,?,?)"); + private static final Statement update = new Statement("UPDATE `UserConfig` SET `Value`= ? WHERE 'User' = ? AND 'Config' = ?"); + private static final Statement select = new Statement("SELECT `Value` FROM `UserConfig` WHERE 'User' = ? AND 'Config' = ?"); + private static final Statement delete = new Statement("DELETE FROM `UserConfig` WHERE 'User' = ? AND 'Config' = ?"); + + public static BauLockState getUserLockState(int userID) { + return BauLockState.valueOf(getConfig(userID, lockConfigName)); + } + + public static String getConfig(int userID, String config) { + return select.select(rs -> { + if(rs.next()) + return rs.getString("Value"); + return null; + }, userID, config); + } + + public static void updateUserConfig(int userID, String config, String value) { + + if (getConfig(userID, config) == null) { + insert.update(userID, config, value); + } else { + update.update(value, config, config); + } + } + + public static void removePlayerEntry(int userID, String config) { + delete.update(userID, config); + } +} diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index ec995b20..706d6376 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -197,8 +197,10 @@ 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 buildserver is currently locked. -BAU_LOCKED=&eYou have locked your buildserver. -BAU_UNLOCKED=&eYou have unlocked your buildserver. +BAU_LOCKED_OPTIONS=§eBuildserver lock options: none, team, open. +BAU_LOCKED_NONE=§eYou have closed your buildserver to all players. +BAU_LOCKED_TEAM=§eYou've closed your buildserver to all beside added team members. +BAU_LOCKED_OPEN=§eYou have reopened your build for all added players. BAU_DELMEMBER_USAGE=§8/§7build delmember §8[§eplayer§8] BAU_DELMEMBER_SELFDEL=§cYou cannot remove yourself! BAU_DELMEMBER_DELETED=§cPlayer was removed. diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index dd2664be..67750607 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -181,8 +181,10 @@ 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 Buildserver ist momentan gelocked. -BAU_LOCKED=&eDu hast dein Bau geschlossen. -BAU_UNLOCKED=&eDu hast dein Bau wieder freigegeben. +BAU_LOCKED_OPTIONS=§eBuildserver lock optionen: none, team, open. +BAU_LOCKED_NONE=§eDu hast dein Bau für alle Spieler geschlossen. +BAU_LOCKED_TEAM=§eDu hast dein Bau für alle außer hinzugefügte Teammitglieder geschlossen. +BAU_LOCKED_OPEN=§eDu hast dein Bau für alle hinzugefügten Spieler wieder geöffnet. BAU_DELMEMBER_USAGE=§8/§7bau delmember §8[§eSpieler§8] BAU_DELMEMBER_SELFDEL=§cDu kannst dich nicht selbst entfernen! BAU_DELMEMBER_DELETED=§cDer Spieler wurde entfernt.