Skip to content

Commit

Permalink
improved code.... #SoNowITravelToUSAAndBuyAGun!
Browse files Browse the repository at this point in the history
  • Loading branch information
LartyHD committed Oct 4, 2019
1 parent 69a6679 commit eedfc62
Show file tree
Hide file tree
Showing 30 changed files with 1,147 additions and 1,001 deletions.
286 changes: 131 additions & 155 deletions src/main/kotlin/de/tutorialwork/Main.kt

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions src/main/kotlin/de/tutorialwork/commands/Ban.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ import net.md_5.bungee.api.plugin.Command

object Ban : Command(simpleName<Ban>()) {

override fun execute(sender: CommandSender, args: Array<String>) = sender.hasPermission(name.toLowerCase()) {
if (args.size != 2) {
sender.sendBanReasonsList()
sender.msg("$prefix/${name.toLowerCase()} <Spieler> <Grund-ID>")
return
}
val uuid = UUIDFetcher.getUUID(args[0]) ?: return
if (!uuid.playerExists()) {
sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten")
return
}
if (uuid.isWebaccountAdmin) {
sender.msg("${prefix}§cDiesen Spieler kannst du nicht bannen/muten")
return
}
val id = args[1].toIntOrNull() ?: return //add fail message
val type = if (id.isBanReason) ActionType.Ban(id) else ActionType.Mute(id)
if (id.hasExtraPermissions && !sender.hasPermission(id.extraPermissions)) {
sender.msg("${prefix}§cDu hast keine Berechtigung diesen ${type::class.java.simpleName}grund zu nutzen")
return
}
val executor = sender.executor
type.execute(uuid, executor)
type.sendNotify(uuid.name, sender.name)
LogManager.createEntry(uuid.toString(), executor, type)
}
override fun execute(sender: CommandSender, args: Array<String>) = sender.hasPermission(name.toLowerCase()) {
if (args.size != 2) {
sender.sendBanReasonsList()
sender.msg("$prefix/${name.toLowerCase()} <Spieler> <Grund-ID>")
return
}
val uuid = UUIDFetcher.getUUID(args[0]) ?: return
if (!uuid.playerExists()) {
sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten")
return
}
if (uuid.isWebaccountAdmin) {
sender.msg("${prefix}§cDiesen Spieler kannst du nicht bannen/muten")
return
}
val id = args[1].toIntOrNull() ?: return //add fail message
val type = if (id.isBanReason) ActionType.Ban(id) else ActionType.Mute(id)
if (id.hasExtraPermissions && !sender.hasPermission(id.extraPermissions)) {
sender.msg("${prefix}§cDu hast keine Berechtigung diesen ${type::class.java.simpleName}grund zu nutzen")
return
}
val executor = sender.executor
type.execute(uuid, executor)
type.sendNotify(uuid.name, sender.name)
uuid.createLogEntry(executor, type)
}
}
54 changes: 27 additions & 27 deletions src/main/kotlin/de/tutorialwork/commands/Blacklist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ import net.md_5.bungee.api.plugin.Command

object Blacklist : Command(simpleName<Blacklist>()) {

override fun execute(sender: CommandSender, args: Array<String>) = sender.hasPermission(name) {
if (args.size != 2) {
sender.msg("${prefix}Derzeit sind §e§l${blacklist.size} Wörter §7auf der Blacklist")
sender.msg("$prefix/${name.toLowerCase()} <add/del> <Wort>")
return
}
val word = args[1]
val x = when (args[0].toLowerCase()) {
"add" -> {
blacklist.add(word)
"hinzugefügt"
}
"del" -> {
if (word !in blacklist) {
sender.msg("${prefix}§cDieses Wort steht nicht auf der Blacklist")
return
}
blacklist.remove(word)
"entfernt"
}
else -> return
}
LogManager.createEntry("", sender.executor, ActionType.Blacklist("${args[0].toUpperCase()}_WORD_BLACKLIST"))
sender.msg("${prefix}§e§l$word §7wurde zur Blacklist $x")
blacklistConfig.set("BLACKLIST", blacklist)
saveConfig(blacklistConfig, blacklistFile)
}
override fun execute(sender: CommandSender, args: Array<String>) = sender.hasPermission(name) {
if (args.size != 2) {
sender.msg("${prefix}Derzeit sind §e§l${blacklist.size} Wörter §7auf der Blacklist")
sender.msg("$prefix/${name.toLowerCase()} <add/del> <Wort>")
return
}
val word = args[1]
val x = when (args[0].toLowerCase()) {
"add" -> {
blacklist.add(word)
"hinzugefügt"
}
"del" -> {
if (word !in blacklist) {
sender.msg("${prefix}§cDieses Wort steht nicht auf der Blacklist")
return
}
blacklist.remove(word)
"entfernt"
}
else -> return
}
null.createLogEntry(sender.executor, ActionType.Blacklist("${args[0].toUpperCase()}_WORD_BLACKLIST"))
sender.msg("${prefix}§e§l$word §7wurde zur Blacklist $x")
blacklistConfig.set("BLACKLIST", blacklist)
saveConfig(blacklistConfig, blacklistFile)
}

}
44 changes: 22 additions & 22 deletions src/main/kotlin/de/tutorialwork/commands/ChatLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ import net.md_5.bungee.api.plugin.Command

object ChatLog : Command(simpleName<ChatLog>()) {

private val chatLogUrl by lazy { config.getString("CHATLOG.URL") }
private val chatLogUrl by lazy { config.getString("CHATLOG.URL") }

override fun execute(sender: CommandSender, args: Array<String>) {
if (args.size != 1) {
sender.msg("$prefix/${name.toLowerCase()} <Spieler>")
return
}
val target = args[0].getUUID(sender) ?: return
target.exists(sender) ?: return
if (sender is ProxiedPlayer && sender.uniqueId == target) {
sender.msg("${prefix}§cDu kannst kein ChatLog von dir selbst erstellen")
return
}
if (!Chat.hasMessages(target)) {
sender.msg("${prefix}§cDieser Spieler hat in der letzten Zeit keine Nachrichten verfasst")
return
}
val executor = sender.executor
val id = Chat.createChatLog(target, executor)
LogManager.createEntry(target.toString(), executor, ActionType.Chatlog("CREATE_CHATLOG", id))
sender.msg("${prefix}Der ChatLog von §e§l${target.name} §7wurde erfolgreich erstellt")
sender.msg("${prefix}Link: §e§l$chatLogUrl$id")
}
override fun execute(sender: CommandSender, args: Array<String>) {
if (args.size != 1) {
sender.msg("$prefix/${name.toLowerCase()} <Spieler>")
return
}
val target = args[0].getUUID(sender) ?: return
target.exists(sender) ?: return
if (sender is ProxiedPlayer && sender.uniqueId == target) {
sender.msg("${prefix}§cDu kannst kein ChatLog von dir selbst erstellen")
return
}
if (!Chat.hasMessages(target)) {
sender.msg("${prefix}§cDieser Spieler hat in der letzten Zeit keine Nachrichten verfasst")
return
}
val executor = sender.executor
val id = Chat.createChatLog(target, executor)
target.createLogEntry(executor, ActionType.Chatlog("CREATE_CHATLOG", id))
sender.msg("${prefix}Der ChatLog von §e§l${target.name} §7wurde erfolgreich erstellt")
sender.msg("${prefix}Link: §e§l$chatLogUrl$id")
}

}
112 changes: 56 additions & 56 deletions src/main/kotlin/de/tutorialwork/commands/IPBan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,63 @@ import net.md_5.bungee.api.plugin.Command

object IPBan : Command(IPBan::class.java.simpleName) {

override fun execute(sender: CommandSender, args: Array<String>) = sender.hasPermission(name.toLowerCase()) {
if (sender is ProxiedPlayer) {
if (args.isEmpty() || args.size == 1) {
for (zaehler in 1 until countReasons() + 1) {
if (zaehler.isBanReason) {
sender.sendBanReasonsList()
sender.msg("§7$zaehler §8| §e${zaehler.reason}")
}
}
sender.msg("$prefix/ipban <IP/Spieler> <Grund-ID>")
} else {
val ip = args[0]
val id = Integer.valueOf(args[1])
if (validate(ip)) {
if (ip.ipExists) {
ip.ban(id, sender.uniqueId.toString())
ip.bans += 1
ActionType.IpBan(id).sendNotify(ip, sender.name)
} else {
ip.insertIP(sender.uniqueId)
ip.ban(id, sender.uniqueId.toString())
ip.bans += 1
ActionType.IpBan(id).sendNotify(ip, sender.name)
}
disconnectIPBannedPlayers(ip)
LogManager.createEntry("", sender.uniqueId.toString(), ActionType.IpBan("IPBAN_IP"))
} else {
val uuid = UUIDFetcher.getUUID(args[0]) ?: return
val dbip = uuid.ip
dbip.ban(id, sender.uniqueId.toString())
ip.bans += 1
ActionType.IpBan(id).sendNotify(dbip, sender.name)
disconnectIPBannedPlayers(dbip)
LogManager.createEntry("", sender.uniqueId.toString(), ActionType.IpBan("IPBAN_PLAYER"))
}
}
}
}
override fun execute(sender: CommandSender, args: Array<String>) = sender.hasPermission(name.toLowerCase()) {
if (sender is ProxiedPlayer) {
if (args.isEmpty() || args.size == 1) {
for (zaehler in 1 until countReasons() + 1) {
if (zaehler.isBanReason) {
sender.sendBanReasonsList()
sender.msg("§7$zaehler §8| §e${zaehler.reason}")
}
}
sender.msg("$prefix/ipban <IP/Spieler> <Grund-ID>")
} else {
val ip = args[0]
val id = Integer.valueOf(args[1])
if (validate(ip)) {
if (ip.ipExists) {
ip.ban(id, sender.uniqueId.toString())
ip.bans += 1
ActionType.IpBan(id).sendNotify(ip, sender.name)
} else {
ip.insertIP(sender.uniqueId)
ip.ban(id, sender.uniqueId.toString())
ip.bans += 1
ActionType.IpBan(id).sendNotify(ip, sender.name)
}
disconnectIPBannedPlayers(ip)
null.createLogEntry(sender.uniqueId.toString(), ActionType.IpBan("IPBAN_IP"))
} else {
val uuid = UUIDFetcher.getUUID(args[0]) ?: return
val dbip = uuid.ip
dbip.ban(id, sender.uniqueId.toString())
ip.bans += 1
ActionType.IpBan(id).sendNotify(dbip, sender.name)
disconnectIPBannedPlayers(dbip)
null.createLogEntry(sender.uniqueId.toString(), ActionType.IpBan("IPBAN_PLAYER"))
}
}
}
}

private fun disconnectIPBannedPlayers(ip: String) {
for (all in players) {
if (all.address.hostString == ip) {
if (ip.rawEnd == -1L) {
all.kick(config.getString("LAYOUT.IPBAN").replace("%grund%", ip.reason).translateColors())
} else {
if (System.currentTimeMillis() < ip.rawEnd) {
var msg = config.getString("LAYOUT.TEMPIPBAN")
msg = msg.replace("%grund%", ip.reason)
msg = msg.replace("%dauer%", getEnd(ip))
all.kick(msg.translateColors())
} else ip.unBan()
}
}
}
}
private fun disconnectIPBannedPlayers(ip: String) {
for (all in players) {
if (all.address.hostString == ip) {
if (ip.rawEnd == -1L) {
all.kick(config.getString("LAYOUT.IPBAN").replace("%grund%", ip.reason).translateColors())
} else {
if (System.currentTimeMillis() < ip.rawEnd) {
var msg = config.getString("LAYOUT.TEMPIPBAN")
msg = msg.replace("%grund%", ip.reason)
msg = msg.replace("%dauer%", getEnd(ip))
all.kick(msg.translateColors())
} else ip.unBan()
}
}
}
}

private val PATTERN = "^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$".toPattern()
fun validate(ip: String): Boolean = PATTERN.matcher(ip).matches()
private val PATTERN = "^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$".toPattern()
fun validate(ip: String): Boolean = PATTERN.matcher(ip).matches()

}
28 changes: 14 additions & 14 deletions src/main/kotlin/de/tutorialwork/commands/Kick.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import net.md_5.bungee.api.plugin.Command

object Kick : Command(simpleName<Kick>()) {

override fun execute(sender: CommandSender, args: Array<String>) = sender.hasPermission(name.toLowerCase()) {
if (args.size != 2) {
sender.msg("$prefix/${name.toLowerCase()} <Spieler> <Grund>")
return
}
val tokick = proxyServer.getPlayer(args[0])
if (tokick != null) {
val grund = args.joinToString(" ")
ActionType.Kick(grund).sendNotify(tokick.name, sender.name)
LogManager.createEntry(tokick.uniqueId.toString(), sender.executor, ActionType.Kick(grund))
tokick.kick(config.getString("LAYOUT.KICK")
.replace("%grund%", grund).translateColors())
} else sender.msg("${prefix}§cDieser Spieler ist nicht online")
}
override fun execute(sender: CommandSender, args: Array<String>) = sender.hasPermission(name.toLowerCase()) {
if (args.size != 2) {
sender.msg("$prefix/${name.toLowerCase()} <Spieler> <Grund>")
return
}
val tokick = proxyServer.getPlayer(args[0])
if (tokick != null) {
val grund = args.joinToString(" ")
ActionType.Kick(grund).sendNotify(tokick.name, sender.name)
tokick.uniqueId.createLogEntry(sender.executor, ActionType.Kick(grund))
tokick.kick(config.getString("LAYOUT.KICK")
.replace("%grund%", grund).translateColors())
} else sender.msg("${prefix}§cDieser Spieler ist nicht online")
}
}
Loading

0 comments on commit eedfc62

Please sign in to comment.