Skip to content

Commit

Permalink
fix bans not dispatching properly
Browse files Browse the repository at this point in the history
  • Loading branch information
98ping committed Apr 8, 2023
1 parent 6744f33 commit 9a5f6f0
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 5 deletions.
Binary file modified .gradle/7.1/dependencies-accessors/dependencies-accessors.lock
Binary file not shown.
Binary file modified .gradle/7.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/checksums/sha1-checksums.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion .idea/codestream.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package ltd.matrixstudios.alchemist.punishment.packets

import ltd.matrixstudios.alchemist.AlchemistSpigotPlugin
import ltd.matrixstudios.alchemist.api.AlchemistAPI
import ltd.matrixstudios.alchemist.punishments.PunishmentType
import ltd.matrixstudios.alchemist.redis.RedisPacket
import ltd.matrixstudios.alchemist.util.Chat
import ltd.matrixstudios.alchemist.util.TimeUtil
import org.bukkit.Bukkit
import org.bukkit.event.player.AsyncPlayerPreLoginEvent
import java.util.*

class PunishmentExecutePacket(
Expand All @@ -18,13 +21,55 @@ class PunishmentExecutePacket(

if (player != null) {
if (punishmentType == PunishmentType.BLACKLIST) {
AlchemistSpigotPlugin.instance.config.getStringList("blacklist-message").map { it.replace("<reason>", reason)}.forEach { player.sendMessage(Chat.format(it)) }
AlchemistSpigotPlugin.instance.config.getStringList("blacklist-message")
.map { it.replace("<reason>", reason) }.forEach { player.sendMessage(Chat.format(it)) }
} else if (punishmentType == PunishmentType.BAN) {
AlchemistSpigotPlugin.instance.config.getStringList("ban-message").map { it.replace("<reason>", reason)}.forEach { player.sendMessage(Chat.format(it)) }
AlchemistSpigotPlugin.instance.config.getStringList("ban-message")
.map { it.replace("<reason>", reason) }.forEach { player.sendMessage(Chat.format(it)) }
} else if (punishmentType == PunishmentType.MUTE) {
AlchemistSpigotPlugin.instance.config.getStringList("mute-message").map { it.replace("<reason>", reason)}.forEach { player.sendMessage(Chat.format(it)) }
AlchemistSpigotPlugin.instance.config.getStringList("mute-message")
.map { it.replace("<reason>", reason) }.forEach { player.sendMessage(Chat.format(it)) }
} else if (punishmentType == PunishmentType.WARN) {
AlchemistSpigotPlugin.instance.config.getStringList("warn-message").map { it.replace("<reason>", reason)}.forEach { player.sendMessage(Chat.format(it)) }
AlchemistSpigotPlugin.instance.config.getStringList("warn-message")
.map { it.replace("<reason>", reason) }.forEach { player.sendMessage(Chat.format(it)) }
}

if (punishmentType == PunishmentType.BAN) {

val profile = AlchemistAPI.syncFindProfile(target) ?: return
val punishment = profile.getActivePunishments(PunishmentType.BAN).firstOrNull()
val msgs = AlchemistSpigotPlugin.instance.config.getStringList("banned-join")

msgs.replaceAll { it.replace("<reason>", punishment!!.reason) }
msgs.replaceAll {
it.replace(
"<expires>",
if (punishment!!.expirable.duration == Long.MAX_VALUE) "Never" else TimeUtil.formatDuration(
punishment.expirable.addedAt + punishment.expirable.duration - System.currentTimeMillis()
)
)
}

player.kickPlayer(msgs.map { Chat.format(it) }.joinToString("\n"))
} else if (punishmentType == PunishmentType.BLACKLIST) {
val profile = AlchemistAPI.syncFindProfile(target) ?: return
val punishments = profile.getActivePunishments(PunishmentType.BLACKLIST).toMutableList()
punishments.addAll(profile.getActivePunishments(PunishmentType.BAN))

val punishment = profile.getActivePunishments(PunishmentType.BLACKLIST).firstOrNull()
val msgs = AlchemistSpigotPlugin.instance.config.getStringList("blacklisted-join")

msgs.replaceAll { it.replace("<reason>", punishment!!.reason) }
msgs.replaceAll {
it.replace(
"<expires>",
if (punishment!!.expirable.duration == Long.MAX_VALUE) "Never" else TimeUtil.formatDuration(
punishment.expirable.addedAt + punishment.expirable.duration - System.currentTimeMillis()
)
)
}

player.kickPlayer(msgs.map { Chat.format(it) }.joinToString("\n"))
}
}
}
Expand Down

0 comments on commit 9a5f6f0

Please sign in to comment.