@@ -54,20 +54,44 @@ public RedeemCDKResult RedeemCDK(UnturnedPlayer player, string CDK)
5454
5555 if ( cdkdata . Items != string . Empty && cdkdata . Amount == string . Empty )
5656 {
57- foreach ( string item in cdkdata . Items . Split ( ',' ) )
57+ //foreach (string item in cdkdata.Items.Split(','))
58+ //{
59+ // player.GiveItem(Convert.ToUInt16(item), 1);
60+ //}
61+ var items = cdkdata . Items . Split ( ',' ) ;
62+ for ( int i = 0 ; i < items . Length ; i ++ )
5863 {
59- player . GiveItem ( Convert . ToUInt16 ( item ) , 1 ) ;
64+ if ( ushort . TryParse ( items [ i ] , out ushort id ) )
65+ {
66+ player . GiveItem ( id , 1 ) ;
67+ }
6068 }
6169 }
6270 else if ( cdkdata . Items != string . Empty && cdkdata . Amount != string . Empty )
6371 {
64- foreach ( string item in cdkdata . Items . Split ( ',' ) )
72+ var items = cdkdata . Items . Split ( ',' ) ;
73+ var amount = cdkdata . Items . Split ( ',' ) ;
74+ if ( items . Length == amount . Length )
6575 {
66- foreach ( string amount in cdkdata . Amount . Split ( ',' ) )
76+ for ( int i = 0 ; i < amount . Length ; i ++ )
6777 {
68- player . GiveItem ( Convert . ToUInt16 ( item ) , Convert . ToByte ( amount ) ) ;
78+ try
79+ {
80+ if ( ! player . GiveItem ( Convert . ToUInt16 ( items [ i ] ) , Convert . ToByte ( amount [ i ] ) ) )
81+ {
82+ UnturnedChat . Say ( player , Main . Instance . Translate ( "items_give_fail" ) , UnityEngine . Color . red ) ;
83+ }
84+ }
85+ catch
86+ {
87+ UnturnedChat . Say ( player , Main . Instance . Translate ( "cdk_config_error" ) , UnityEngine . Color . red ) ;
88+ }
6989 }
7090 }
91+ else
92+ {
93+ UnturnedChat . Say ( player , Main . Instance . Translate ( "cdk_config_error" ) , UnityEngine . Color . red ) ;
94+ }
7195 }
7296
7397 if ( cdkdata . Vehicle != 0 )
@@ -136,7 +160,14 @@ public RedeemCDKResult RedeemCDK(UnturnedPlayer player, string CDK)
136160 }
137161 else
138162 {
139- PermissionSync . Main . Instance . databese . UpdatePermission ( player , cdkdata . GrantPermissionGroup , cdkdata . ValidUntil , "CDKPlugin" ) ;
163+ Main . ExecuteDependencyCode ( "PermissionSync" , ( IRocketPlugin ps ) =>
164+ {
165+ if ( ps . State == PluginState . Loaded )
166+ {
167+ //PermissionSync.Main.Instance.databese.AddPermission("CDKPlugin", player, cdkdata.GrantPermissionGroup, cdkdata.ValidUntil.ToString());
168+ PermissionSync . Main . Instance . databese . UpdatePermission ( player , cdkdata . GrantPermissionGroup , cdkdata . ValidUntil , "CDKPlugin" ) ;
169+ }
170+ } ) ;
140171 UpdateLogInDB ( new LogData ( CDK , player . CSteamID , DateTime . Now , cdkdata . ValidUntil , cdkdata . GrantPermissionGroup , cdkdata . UsePermissionSync ) ) ;
141172 UpdateRenew ( CDK ) ;
142173 }
0 commit comments