-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
134 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
...main/kotlin/com/projectcitybuild/deprecated/modules/moderation/warnings/WarningsModule.kt
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
...com/projectcitybuild/deprecated/modules/moderation/warnings/actions/AcknowledgeWarning.kt
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
...ectcitybuild/deprecated/modules/moderation/warnings/commands/WarningAcknowledgeCommand.kt
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
...itybuild/deprecated/modules/moderation/warnings/listeners/NotifyWarningsOnJoinListener.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../main/kotlin/com/projectcitybuild/features/warnings/commands/WarningAcknowledgeCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.projectcitybuild.features.warnings.commands | ||
|
||
import com.projectcitybuild.features.warnings.repositories.PlayerWarningRepository | ||
import com.projectcitybuild.support.messages.CommandHelpBuilder | ||
import com.projectcitybuild.support.spigot.BadCommandUsageException | ||
import com.projectcitybuild.support.spigot.CommandArgsParser | ||
import com.projectcitybuild.support.spigot.SpigotCommand | ||
import org.bukkit.command.CommandSender | ||
|
||
class WarningAcknowledgeCommand( | ||
private val warningRepository: PlayerWarningRepository, | ||
): SpigotCommand<WarningAcknowledgeCommand.Args> { | ||
override val label = "warning" | ||
|
||
override val usage = CommandHelpBuilder() | ||
|
||
override suspend fun run(sender: CommandSender, args: Args) { | ||
warningRepository.acknowledge(args.id) | ||
sender.sendMessage("Warning acknowledged and hidden") | ||
} | ||
|
||
data class Args( | ||
val id: Int, | ||
) { | ||
class Parser: CommandArgsParser<Args> { | ||
override fun parse(args: List<String>): Args { | ||
if (args.isEmpty()) { | ||
throw BadCommandUsageException() | ||
} | ||
return Args(id = args[0].toInt()) | ||
} | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...n/kotlin/com/projectcitybuild/features/warnings/listeners/NotifyWarningsOnJoinListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.projectcitybuild.features.warnings.listeners | ||
|
||
import com.projectcitybuild.features.warnings.actions.GetUnacknowledgedWarnings | ||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.event.ClickEvent | ||
import net.kyori.adventure.text.format.NamedTextColor | ||
import net.kyori.adventure.text.format.TextDecoration | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.player.PlayerJoinEvent | ||
|
||
class NotifyWarningsOnJoinListener( | ||
private val getUnacknowledgedWarnings: GetUnacknowledgedWarnings, | ||
) : Listener { | ||
@EventHandler | ||
suspend fun onPlayerJoin(event: PlayerJoinEvent) { | ||
val player = event.player | ||
val warnings = getUnacknowledgedWarnings.execute( | ||
playerUUID = player.uniqueId, | ||
playerName = player.name, | ||
) | ||
if (warnings.isEmpty()) { | ||
return | ||
} | ||
|
||
val message = Component.text() | ||
.append( | ||
Component.text("You have ").color(NamedTextColor.RED), | ||
Component.text(warnings.size).decorate(TextDecoration.BOLD), | ||
Component.text(" unacknowledged warnings").color(NamedTextColor.RED), | ||
Component.newline(), | ||
Component.text("---").color(NamedTextColor.GRAY), | ||
Component.newline(), | ||
) | ||
|
||
warnings.forEach { warning -> | ||
message.append( | ||
Component.text(warning.reason), | ||
Component.newline(), | ||
Component.text("Date: ").color(NamedTextColor.GRAY), | ||
Component.text(warning.createdAt), | ||
Component.newline(), | ||
Component.newline(), | ||
Component.text("[I ACKNOWLEDGE]") | ||
.color(NamedTextColor.GOLD) | ||
.decorate(TextDecoration.BOLD, TextDecoration.UNDERLINED) | ||
.clickEvent(ClickEvent.runCommand("/warning acknowledge ${warning.id}")), | ||
Component.newline(), | ||
Component.text("---").color(NamedTextColor.GRAY), | ||
Component.newline(), | ||
) | ||
} | ||
message.append( | ||
Component.text("Click the 'acknowledge' button to mark it as read and hide it") | ||
.color(NamedTextColor.GRAY) | ||
.decorate(TextDecoration.ITALIC), | ||
) | ||
player.sendMessage(message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters