diff --git a/src/main/kotlin/essentials/Commands.kt b/src/main/kotlin/essentials/Commands.kt index 0200c029..b27a749a 100644 --- a/src/main/kotlin/essentials/Commands.kt +++ b/src/main/kotlin/essentials/Commands.kt @@ -904,28 +904,21 @@ class Commands(var handler: CommandHandler, isClient: Boolean) { val name = data.name val ip = netServer.admins.getInfo(data.uuid).lastIP - if (!netServer.admins.unbanPlayerID(arg[0])) { - if (!netServer.admins.unbanPlayerIP(arg[0])) { + if (!netServer.admins.unbanPlayerID(data.uuid)) { + if (!netServer.admins.unbanPlayerIP(ip)) { err("player.not.found") } else { - send("command.unban.ip", arg[0]) + send("command.unban.ip", ip) } } else { - send("command.unban.id", arg[0]) + send("command.unban.id", data.uuid) } val json = JsonArray.readHjson(Fi(Config.banList).readString()).asArray() - json.forEachIndexed { index, jsonValue -> - if (jsonValue.asObject().get("ip").asArray().contains(JsonValue.valueOf(ip))) { - json.remove(index) - } + json.removeAll { + it.asObject().get("ip").asArray().contains(JsonValue.valueOf(ip)) || it.asObject().get("id").asString() == data.uuid } - json.forEachIndexed { index, jsonValue -> - if (jsonValue.asObject().get("id").asString() == data.uuid) { - json.remove(index) - } - } Fi(Config.banList).writeString(json.toString(Stringify.HJSON)) Event.log(Event.LogType.Player, Bundle()["log.player.banned", name, ip]) diff --git a/src/main/kotlin/essentials/Event.kt b/src/main/kotlin/essentials/Event.kt index 474cdfdd..de9de681 100644 --- a/src/main/kotlin/essentials/Event.kt +++ b/src/main/kotlin/essentials/Event.kt @@ -691,21 +691,20 @@ object Event { } Events.on(PlayerUnbanEvent::class.java) { + val ip = if (it.player != null) it.player.ip() else netServer.admins.getInfo(it.uuid).lastIP + if (Config.blockIP) { val os = System.getProperty("os.name").lowercase(Locale.getDefault()) if (os.contains("nix") || os.contains("nux") || os.contains("aix")) { - val ip = if (it.player != null) it.player.ip() else netServer.admins.getInfo(it.uuid).lastIP Runtime.getRuntime().exec(arrayOf("/bin/bash", "-c", "echo ${PluginData.sudoPassword} | sudo -S iptables -D INPUT -s $ip -j DROP")) } } val json = JsonArray.readHjson(Fi(Config.banList).readString()).asArray() - json.forEachIndexed { index, jsonValue -> - if (jsonValue.asObject().get("id").asString() == it.uuid) { - json.remove(index) - return@forEachIndexed - } + json.removeAll { js -> + js.asObject().get("ip").asArray().contains(JsonValue.valueOf(ip)) || js.asObject().get("id").asString() == it.uuid } + Fi(Config.banList).writeString(json.toString(Stringify.HJSON)) Events.fire(PlayerUnbanned(netServer.admins.getInfo(it.uuid).lastName, currentTime()))