88
99namespace Oxide . Plugins {
1010
11- [ Info ( "Recycle" , "5Dev24" , "3.0.3 " ) ]
11+ [ Info ( "Recycle" , "5Dev24" , "3.0.4 " ) ]
1212 [ Description ( "Recycle items into their resources" ) ]
1313 public class Recycle : RustPlugin {
1414
@@ -238,15 +238,17 @@ public class SettingsWrapper {
238238 public bool InstantRecycling = false ;
239239 [ JsonProperty ( "Send Recycled Items To Inventory" ) ]
240240 public bool ToInventory = false ;
241+ [ JsonProperty ( "Send Items To Inventory Before Bag" ) ]
242+ public bool InventoryBeforeBag = false ;
241243 [ JsonProperty ( "NPC Ids" ) ]
242- public List < string > NPCIds = new List < string > ( ) ;
244+ public List < object > NPCIds = new List < object > ( ) ;
243245 [ JsonProperty ( "Recyclable Types" ) ]
244- public List < string > RecyclableTypes = new List < string > ( ) ;
246+ public List < object > RecyclableTypes = new List < object > ( ) ;
245247 [ JsonProperty ( "Blacklisted Items" ) ]
246- public List < string > Blacklist = new List < string > ( ) ;
248+ public List < object > Blacklist = new List < object > ( ) ;
247249 }
248250 public SettingsWrapper Settings = new SettingsWrapper ( ) ;
249- public string VERSION = "3.0.3 " ;
251+ public string VERSION = "3.0.4 " ;
250252 }
251253
252254 #endregion
@@ -255,7 +257,7 @@ public class SettingsWrapper {
255257
256258 protected override void LoadDefaultConfig ( ) {
257259 ConfigData tmp = new ConfigData ( ) ;
258- tmp . Settings . RecyclableTypes = new List < string > ( ) {
260+ tmp . Settings . RecyclableTypes = new List < object > ( ) {
259261 "Ammunition" , "Attire" , "Common" , "Component" , "Construction" , "Electrical" ,
260262 "Fun" , "Items" , "Medical" , "Misc" , "Tool" , "Traps" , "Weapon" } ;
261263 Config . WriteObject ( tmp , true ) ;
@@ -266,7 +268,7 @@ private T GetSetting<T>(string val, T defaultVal) {
266268 if ( val == null ) return default ( T ) ;
267269 object gotten = Config . Get ( "Settings" , val ) ;
268270 if ( gotten == null ) {
269- Config . Set ( "Settings" , defaultVal ) ;
271+ Config . Set ( "Settings" , val , defaultVal ) ;
270272 return defaultVal ;
271273 }
272274 return this . ConvertType ( gotten , defaultVal ) ;
@@ -289,25 +291,22 @@ private void ValidateConfig() {
289291 RefundRatio = this . GetSetting ( "refundRatio" , 0.5f ) ,
290292 RadiationMax = this . GetSetting ( "radiationMax" , 1f ) ,
291293 NPCOnly = this . GetSetting ( "NPCOnly" , false ) ,
292- NPCIds = this . GetSetting ( "NPCIDs" , new List < string > ( ) ) ,
293- RecyclableTypes = this . GetSetting ( "recyclableTypes" , new List < string > ( ) {
294+ NPCIds = this . GetSetting ( "NPCIDs" , new List < object > ( ) ) ,
295+ RecyclableTypes = this . GetSetting ( "recyclableTypes" , new List < object > ( ) {
294296 "Ammunition" , "Attire" , "Common" , "Component" , "Construction" , "Electrical" ,
295297 "Fun" , "Items" , "Medical" , "Misc" , "Tool" , "Traps" , "Weapon" } ) ,
296- Blacklist = this . GetSetting ( "blacklist" , new List < string > ( ) ) ,
298+ Blacklist = this . GetSetting ( "blacklist" , new List < object > ( ) ) ,
297299 AllowedInSafeZones = this . GetSetting ( "allowSafeZone" , true )
298300 }
299301 } ;
300302 this . UpdateAndSave ( ) ;
301- } else if ( version . Equals ( "3.0.0" ) || version . Equals ( "3.0.1" ) ) {
303+ } else if ( version . Equals ( "3.0.0" ) || version . Equals ( "3.0.1" ) || version . Equals ( "3.0.3" ) ) {
302304 /* All of these versions should handle updating fine due to
303305 * the ConfigData object having defaults
304306 */
305307 this . Data = Config . ReadObject < ConfigData > ( ) ;
306308 if ( this . Data == null || this . Data . Settings == null ) this . LoadDefaultConfig ( ) ;
307- else {
308- this . Data . Settings . ToInventory = false ;
309- this . UpdateAndSave ( ) ;
310- }
309+ else this . UpdateAndSave ( ) ;
311310 }
312311 } catch ( NullReferenceException ) { }
313312 }
@@ -357,6 +356,28 @@ private void DropRecyclerContents(BaseEntity e) {
357356 BasePlayer p = this . PlayerFromRecycler ( r . net . ID ) ;
358357 if ( p == null ) return ;
359358 this . PrintToChat ( p , this . GetMessage ( "Recycle" , "Dropped" , p ) ) ;
359+
360+ List < Item > items = r . inventory . itemList . ToList ( ) ;
361+
362+ if ( this . Data . Settings . InventoryBeforeBag ) {
363+ for ( int i = 0 ; i < items . Count ; i ++ ) {
364+ Item item = items [ i ] ;
365+
366+ bool flag = false ;
367+ if ( ! p . inventory . containerMain . IsFull ( ) )
368+ flag = item . MoveToContainer ( p . inventory . containerMain ) ;
369+ if ( ! flag && ! p . inventory . containerBelt . IsFull ( ) )
370+ item . MoveToContainer ( p . inventory . containerBelt ) ;
371+
372+ if ( flag ) {
373+ items . RemoveAt ( i ) ;
374+ i -- ;
375+ }
376+ }
377+ }
378+
379+ if ( items . Count == 0 ) return ;
380+
360381 DroppedItemContainer bag = GameManager . server . CreateEntity ( Recycle . BackpackPrefab , p . transform . position + Vector3 . up , Quaternion . identity ) as DroppedItemContainer ;
361382 bag . enableSaving = false ;
362383 bag . TakeFrom ( r . inventory ) ;
0 commit comments