File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed
src/main/kotlin/com/mairwunnx/projectessentials/chat/api Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ package com.mairwunnx.projectessentials.chat.api
2+
3+ object MuteAPI {
4+ private val muteHashMap = hashMapOf<String , MuteData >()
5+
6+ fun mutePlayer (
7+ playerName : String ,
8+ mutedBy : String ,
9+ reason : String ,
10+ override : Boolean
11+ ): Boolean {
12+ if (isInMute(playerName)) {
13+ if (override ) {
14+ unmutePlayer(playerName)
15+ muteHashMap[playerName] = MuteData (mutedBy, playerName, reason)
16+ return true
17+ }
18+ return false
19+ } else {
20+ muteHashMap[playerName] = MuteData (mutedBy, playerName, reason)
21+ return true
22+ }
23+ }
24+
25+ fun unmutePlayer (playerName : String ): Boolean =
26+ if (isInMute(playerName)) {
27+ muteHashMap.remove(playerName)
28+ true
29+ } else {
30+ false
31+ }
32+
33+ fun isInMute (playerName : String ): Boolean = playerName in muteHashMap.keys
34+
35+ fun getMuteInitiator (mutedPlayer : String ): String? =
36+ if (isInMute(mutedPlayer)) muteHashMap[mutedPlayer]!! .mutedBy else null
37+
38+ fun getMuteReason (mutedPlayer : String ): String? =
39+ if (isInMute(mutedPlayer)) muteHashMap[mutedPlayer]!! .reason else null
40+
41+ fun getMutedPlayers (): List <String > = muteHashMap.keys.toList()
42+
43+ fun unmuteAll () = getMutedPlayers().forEach {
44+ unmutePlayer(it)
45+ }
46+ }
47+
Original file line number Diff line number Diff line change 1+ package com.mairwunnx.projectessentials.chat.api
2+
3+ data class MuteData (val mutedBy : String , val mutedPlayer : String , val reason : String ) {
4+ override fun equals (other : Any? ): Boolean {
5+ if (this == = other) return true
6+ if (javaClass != other?.javaClass) return false
7+
8+ other as MuteData
9+
10+ if (mutedBy != other.mutedBy) return false
11+ if (mutedPlayer != other.mutedPlayer) return false
12+
13+ return true
14+ }
15+
16+ override fun hashCode (): Int {
17+ var result = mutedBy.hashCode()
18+ result = 31 * result + mutedPlayer.hashCode()
19+ return result
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments