SteamWar/BungeeCore
Archiviert
13
2

Add BauLock
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Add BauCommand.isLocked
Add BauLockState
Add "BAU_LOCKED" and "BAU_UNLOCKED" in BungeeCore_de.properties
Add "Bau_LOCKED" and "BAU_UNLOCKED" in BungeeCore.properties
Dieser Commit ist enthalten in:
MoBrot 2022-08-10 19:20:33 +02:00
Ursprung e2f2968813
Commit 386395725d
5 geänderte Dateien mit 98 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -23,8 +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.BauweltMember;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.*;
import de.steamwar.bungeecore.util.Chat19;
import de.steamwar.messages.ChatSender;
import de.steamwar.network.packets.server.BaumemberUpdatePacket;
@ -67,7 +66,7 @@ public class BauCommand extends BasicCommand {
togglewe(p, args);
break;
case "toggleworld":
toggleworld(p, args);
toggleWorld(p, args);
break;
case "delmember":
delmember(p, args);
@ -80,6 +79,15 @@ public class BauCommand extends BasicCommand {
case "test":
testarena(p, args);
break;
case "lock":
setLocked(SteamwarUser.get(p), args);
break;
case "unlock":
setLocked(SteamwarUser.get(p), new String[]{"", "OPEN"});
break;
default:
HelpCommand.sendBauHelp(ChatSender.of(p));
}
@ -120,10 +128,14 @@ public class BauCommand extends BasicCommand {
}
SteamwarUser worldOwner = SteamwarUser.get(args[1]);
if (worldOwner == null) {
Message.send("UNKNOWN_PLAYER", p);
SteamwarUser user = SteamwarUser.get(p);
if(isLocked(worldOwner, user)) {
Message.send("BAU_LOCKED_NOALLOWED", user.getPlayer());
return;
}else if (!p.getUniqueId().equals(worldOwner.getUuid()) && BauweltMember.getBauMember(worldOwner.getUuid(), p.getUniqueId()) == null){
}
if ((!p.getUniqueId().equals(worldOwner.getUuid()) && BauweltMember.getBauMember(worldOwner.getUuid(), p.getUniqueId()) == null)){
SubserverSystem.sendDeniedMessage(p, worldOwner.getUuid());
Message.send("BAU_TP_NOALLOWED", p);
return;
@ -185,7 +197,7 @@ public class BauCommand extends BasicCommand {
isAllowedTo(target.isWorldEdit(), p, target, "BAU_MEMBER_TOGGLE_WORLD_EDIT");
}
private static void toggleworld(ProxiedPlayer p, String[] args){
private static void toggleWorld(ProxiedPlayer p, String[] args){
BauweltMember target = toggle(p, args, "toggleworld");
if(target == null)
return;
@ -307,4 +319,31 @@ public class BauCommand extends BasicCommand {
Message.send("BAU_MEMBER_TOGGLE_OFF", p, Message.parse(what, p));
}
}
private static boolean isLocked(SteamwarUser owner, SteamwarUser target) {
if (owner == null) {
Message.send("UNKNOWN_PLAYER", target.getPlayer());
return true;
}
BauLockState activeLockState = BauLock.getUserLockState(owner.getId());
return (activeLockState == BauLockState.TEAM && !(Team.get(owner.getId()) == Team.get(target.getId()))) || activeLockState == BauLockState.ALL;
}
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());
}
BauLock.updateUserConfig(owner.getId(), newState);
String messageKey = "BAU_LOCKED";
if(newState == BauLockState.OPEN)
messageKey = "BAU_UNLOCKED";
Message.send(messageKey, owner.getPlayer());
}
}

Datei anzeigen

@ -0,0 +1,38 @@
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;
}
}

Datei anzeigen

@ -0,0 +1,8 @@
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
}

Datei anzeigen

@ -196,6 +196,9 @@ BAU_ADDMEMBER_ADDED=§aThe player was added to your world.
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_DELMEMBER_USAGE=§8/§7build delmember §8[§eplayer§8]
BAU_DELMEMBER_SELFDEL=§cYou cannot remove yourself!
BAU_DELMEMBER_DELETED=§cPlayer was removed.

Datei anzeigen

@ -180,6 +180,9 @@ BAU_ADDMEMBER_ADDED=§aDer Spieler wurde zu deiner Welt hinzugefügt.
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_DELMEMBER_USAGE=§8/§7bau delmember §8[§eSpieler§8]
BAU_DELMEMBER_SELFDEL=§cDu kannst dich nicht selbst entfernen!
BAU_DELMEMBER_DELETED=§cDer Spieler wurde entfernt.