Merge pull request 'Update DevCommand' (#378) from CommandDev into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #378 Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
e46f68558a
@ -21,6 +21,7 @@ package de.steamwar.bungeecore.commands;
|
|||||||
|
|
||||||
import de.steamwar.bungeecore.sql.Punishment;
|
import de.steamwar.bungeecore.sql.Punishment;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import de.steamwar.command.*;
|
||||||
import de.steamwar.messages.ChatSender;
|
import de.steamwar.messages.ChatSender;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@ -34,76 +35,87 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DevCommand extends BasicCommand {
|
public class DevCommand extends SWCommand {
|
||||||
|
|
||||||
private final File devServerDir = new File("/configs/DevServer");
|
private final File devServerDir = new File("/configs/DevServer");
|
||||||
private final Map<String, ServerInfo> devServers = new HashMap<>();
|
private final Map<String, ServerInfo> devServers = new HashMap<>();
|
||||||
|
|
||||||
public DevCommand() {
|
public DevCommand() {
|
||||||
super("dev", "");
|
super("dev");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Register
|
||||||
public void execute(CommandSender s, String[] args) {
|
public void simpleCommand(@Guard ProxiedPlayer player) {
|
||||||
if (!(s instanceof ProxiedPlayer))
|
|
||||||
return;
|
|
||||||
ProxiedPlayer player = (ProxiedPlayer) s;
|
|
||||||
|
|
||||||
ChatSender sender = ChatSender.of(player);
|
|
||||||
if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoDevServer)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateDevServers();
|
updateDevServers();
|
||||||
if(devServers.isEmpty()) {
|
ChatSender sender = ChatSender.of(player);
|
||||||
|
if (devServers.isEmpty()) {
|
||||||
sender.system("DEV_NO_SERVER");
|
sender.system("DEV_NO_SERVER");
|
||||||
|
return;
|
||||||
} else if (devServers.size() == 1) {
|
} else if (devServers.size() == 1) {
|
||||||
player.connect(devServers.values().stream().findAny().get());
|
player.connect(devServers.values().stream().findAny().get());
|
||||||
} else if (args.length == 0) {
|
return;
|
||||||
ServerInfo info = devServers.get(player.getName().toLowerCase());
|
|
||||||
if (info == null) {
|
|
||||||
sender.system("DEV_UNKNOWN_SERVER");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.connect(info);
|
|
||||||
} else {
|
|
||||||
ServerInfo info = devServers.get(args[0].toLowerCase());
|
|
||||||
if (info == null) {
|
|
||||||
sender.system("DEV_NO_SERVER");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.connect(info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerInfo info = devServers.get(player.getName().toLowerCase());
|
||||||
|
if (info == null) {
|
||||||
|
sender.system("DEV_UNKNOWN_SERVER");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.connect(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Register
|
||||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
public void selectedCommand(@Guard ProxiedPlayer player, @Mapper("dev") String name) {
|
||||||
if (!(sender instanceof ProxiedPlayer) || args.length > 1) {
|
updateDevServers();
|
||||||
return Collections.emptyList();
|
ChatSender sender = ChatSender.of(player);
|
||||||
|
ServerInfo info = devServers.get(name.toLowerCase());
|
||||||
|
if (info == null) {
|
||||||
|
sender.system("DEV_NO_SERVER");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDevServers();
|
player.connect(info);
|
||||||
return devServers.keySet().stream().filter(s -> {
|
}
|
||||||
if (args.length == 0) return true;
|
|
||||||
return s.startsWith(args[0].toLowerCase());
|
@ClassGuard(value = GuardChecker.class, local = true)
|
||||||
}).collect(Collectors.toList());
|
public GuardChecker punishmentGuardChecker() {
|
||||||
|
return (commandSender, guardCheckType, previousArguments, s) -> {
|
||||||
|
ChatSender sender = ChatSender.of(commandSender);
|
||||||
|
if (guardCheckType == GuardCheckType.COMMAND) {
|
||||||
|
if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoDevServer)) {
|
||||||
|
return GuardResult.DENIED;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (sender.user().isPunished(Punishment.PunishmentType.NoDevServer)) {
|
||||||
|
return GuardResult.DENIED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return GuardResult.ALLOWED;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mapper(value = "dev", local = true)
|
||||||
|
public TypeMapper<String> devServers() {
|
||||||
|
return SWCommandUtils.createMapper(s -> s, s -> {
|
||||||
|
updateDevServers();
|
||||||
|
return devServers.keySet();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDevServers() {
|
private void updateDevServers() {
|
||||||
String[] serverFiles = devServerDir.list();
|
String[] serverFiles = devServerDir.list();
|
||||||
|
|
||||||
Map<String, Integer> devServerFiles = new HashMap<>();
|
Map<String, Integer> devServerFiles = new HashMap<>();
|
||||||
if(serverFiles != null) {
|
if (serverFiles != null) {
|
||||||
for(String serverFile : serverFiles) {
|
for (String serverFile : serverFiles) {
|
||||||
String[] server = serverFile.split("\\.");
|
String[] server = serverFile.split("\\.");
|
||||||
devServerFiles.put(server[0], Integer.parseInt(server[1]));
|
devServerFiles.put(server[0], Integer.parseInt(server[1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
devServers.entrySet().removeIf(entry -> {
|
devServers.entrySet().removeIf(entry -> {
|
||||||
if(!devServerFiles.containsKey(entry.getKey())) {
|
if (!devServerFiles.containsKey(entry.getKey())) {
|
||||||
ProxyServer.getInstance().getServers().remove(entry.getValue().getName());
|
ProxyServer.getInstance().getServers().remove(entry.getValue().getName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren