@@ -57,108 +57,41 @@ public bool RequiresPermissions(CCSPlayerController player, Permission permissio
5757 return true ;
5858 }
5959 }
60-
6160 /// <summary>
62- /// Checks if the command is on cooldown
61+ /// Moves the color tag one space the the left if it's not already there.
62+ /// Because the game doesn't support color tags at the start of a string.
6363 /// </summary>
64- /// <param name="player"></param>
65- /// <param name="cmd"></param>
64+ /// <param name="input"></param>
6665 /// <returns></returns>
67- public bool IsCommandOnCooldown ( CCSPlayerController player , Commands cmd )
68- {
69- // Check global cooldown
70- if ( IsCommandOnCooldownWithCondition ( x => x . IsGlobal == true && x . CommandID == cmd . ID , player , cmd ) )
71- return true ;
72-
73- // Check player cooldown
74- if ( IsCommandOnCooldownWithCondition ( x => x . PlayerID == player . UserId && x . CommandID == cmd . ID , player , cmd ) )
75- return true ;
76-
77- return false ;
78- }
79-
80- private bool IsCommandOnCooldownWithCondition ( Func < CooldownTimer , bool > predicate , CCSPlayerController player , Commands cmd )
81- {
82- int index = PluginGlobals . CooldownTimer . FindIndex ( x => predicate ( x ) && x . CooldownTime > DateTime . Now ) ;
83-
84- if ( index != - 1 )
85- {
86- string timeleft = PluginGlobals . CooldownTimer [ index ] . CooldownTime . Subtract ( DateTime . Now ) . Seconds . ToString ( ) ;
87- player . PrintToChat ( $ "{ PluginGlobals . Config . Prefix } { cmd . Cooldown . CooldownMessage . Replace ( "{TIME}" , timeleft )
88- ?? $ "This command is for { timeleft } seconds on cooldown"} " ) ;
89-
90- return true ;
91- }
92-
93- return false ;
94- }
95-
96- /// <summary>
97- /// Adds the command to the cooldown list
98- /// </summary>
99- /// <param name="isGlobal"></param>
100- /// <param name="playerID"></param>
101- /// <param name="commandID"></param>
102- /// <param name="cooldownTime"></param>
103- public void AddToCooldownList ( bool isGlobal , int playerID , Guid commandID , int cooldownTime )
66+ public string PadLeftColorTag ( string input )
10467 {
105- var timer = new CooldownTimer ( ) {
106- IsGlobal = isGlobal ,
107- CommandID = commandID ,
108- CooldownTime = DateTime . Now . AddSeconds ( cooldownTime )
68+ string [ ] colorTagList = new string [ ] {
69+ "{DEFAULT}" ,
70+ "{WHITE}" ,
71+ "{DARKRED}" ,
72+ "{RED}" ,
73+ "{LIGHTRED}" ,
74+ "{GREEN}" ,
75+ "{LIME}" ,
76+ "{OLIVE}" ,
77+ "{ORANGE}" ,
78+ "{GOLD}" ,
79+ "{YELLOW}" ,
80+ "{BLUE}" ,
81+ "{DARKBLUE}" ,
82+ "{LIGHTPURPLE}" ,
83+ "{PURPLE}" ,
84+ "{SILVER}" ,
85+ "{BLUEGREY}" ,
86+ "{GREY}" ,
10987 } ;
110-
111- if ( isGlobal )
88+ foreach ( var colorTag in colorTagList )
11289 {
113- int index = PluginGlobals . CooldownTimer . FindIndex ( x =>
114- x . IsGlobal == true
115- && x . CommandID == commandID ) ;
116- if ( index != - 1 )
117- PluginGlobals . CooldownTimer [ index ] . CooldownTime = timer . CooldownTime ;
118- else
119- PluginGlobals . CooldownTimer . Add ( timer ) ;
120- }
121- else
122- {
123- timer . PlayerID = playerID ;
124- int index = PluginGlobals . CooldownTimer . FindIndex ( x =>
125- x . PlayerID == playerID
126- && x . CommandID == commandID ) ;
127- if ( index != - 1 )
128- PluginGlobals . CooldownTimer [ index ] . CooldownTime = timer . CooldownTime ;
129- else
130- PluginGlobals . CooldownTimer . Add ( timer ) ;
131- }
132- }
133-
134- /// <summary>
135- /// Sets the cooldown for the command
136- /// </summary>
137- /// <param name="player">Need to add the player if the Cooldown is only for a specific player</param>
138- /// <param name="cmd"></param>
139- public void SetCooldown ( CCSPlayerController player , Commands cmd )
140- {
141- if ( cmd . Cooldown is JsonElement jsonElement )
142- {
143- switch ( jsonElement . ValueKind )
90+ if ( input . StartsWith ( colorTag ) )
14491 {
145- case JsonValueKind . Number :
146- int cooldown = ( int ) cmd . Cooldown ;
147- if ( cooldown == 0 )
148- break ;
149-
150- AddToCooldownList ( false , player . UserId ?? 0 , cmd . ID , cooldown ) ;
151- break ;
152-
153- case JsonValueKind . Object :
154- Cooldown cooldownObject = ( Cooldown ) cmd . Cooldown ;
155-
156- AddToCooldownList ( cooldownObject . IsGlobal , player . UserId ?? 0 , cmd . ID , cooldownObject . CooldownTime ) ;
157- break ;
158-
159- default :
160- break ;
92+ return " " + input ;
16193 }
16294 }
95+ return input ;
16396 }
16497}
0 commit comments