88
99namespace Oxide . Plugins {
1010
11- [ Info ( "Recycle" , "5Dev24" , "3.0.2 " ) ]
11+ [ Info ( "Recycle" , "5Dev24" , "3.0.3 " ) ]
1212 [ Description ( "Recycle items into their resources" ) ]
1313 public class Recycle : RustPlugin {
1414
@@ -49,29 +49,56 @@ private void OnLootEntityEnd(BasePlayer p, BaseEntity e) {
4949 private void OnPlayerDisconnected ( BasePlayer p , string reason ) {
5050 BaseEntity result = this . RecyclerFromPlayer ( p . userID ) ;
5151 if ( result != null ) this . DestroyRecycler ( result ) ;
52- foreach ( EntityAndPlayer eap in this . DroppedBags . Values )
53- if ( eap . Player . userID == p . userID ) eap . Entity . Kill ( ) ;
52+
53+ EntityAndPlayer [ ] eaps = this . DroppedBags . Values . Where ( e => e . Player . userID == p . userID ) . ToArray ( ) ;
54+ foreach ( EntityAndPlayer eap in eaps )
55+ eap . Entity . Kill ( ) ;
56+ }
57+
58+ private object CanMoveItem ( Item item , PlayerInventory pLoot , uint targetCon , int targetSlot , int amount ) {
59+ if ( this . Data . Settings . ToInventory && targetSlot >= 6 )
60+ foreach ( ItemContainer con in pLoot . loot . containers . Where ( c => c . uid == targetCon && c . entityOwner != null ) . ToArray ( ) ) {
61+ Recycler r = con . entityOwner as Recycler ;
62+ if ( this . IsRecycleBox ( r ) ) return false ;
63+ }
64+ return null ;
5465 }
5566
5667 private object CanAcceptItem ( ItemContainer con , Item i , int target ) {
5768 if ( con . entityOwner is Recycler ) {
5869 Recycler r = con . entityOwner as Recycler ;
5970 if ( this . IsRecycleBox ( r ) ) {
6071 BasePlayer p = this . PlayerFromRecycler ( r . net . ID ) ;
72+ if ( p == null ) return null ;
73+
6174 if ( target < 6 ) {
6275 if ( ! this . Data . Settings . RecyclableTypes . Contains ( Enum . GetName ( typeof ( ItemCategory ) , i . info . category ) ) ||
6376 this . Data . Settings . Blacklist . Contains ( i . info . shortname ) ) {
6477 if ( p != null ) this . PrintToChat ( p , this . GetMessage ( "Recycle" , "Invalid" , p ) ) ;
6578 return ItemContainer . CanAcceptResult . CannotAcceptRightNow ;
66- } else if ( this . Data . Settings . InstantRecycling ) {
67- if ( ! r . IsOn ( ) ) {
68- r . InvokeRepeating ( new Action ( r . RecycleThink ) , 0 , 0 ) ;
69- Effect . server . Run ( r . startSound . resourcePath , r , 0U , Vector3 . zero , Vector3 . zero , null , false ) ;
70- r . SetFlag ( BaseEntity . Flags . On , true , false , true ) ;
71- r . SendNetworkUpdateImmediate ( ) ;
72- }
73- } else r . StartRecycling ( ) ;
74- }
79+ } else
80+ NextFrame ( ( ) => {
81+ if ( r == null || ! r . HasRecyclable ( ) ) return ;
82+
83+ if ( this . Data . Settings . InstantRecycling ) {
84+ if ( ! r . IsOn ( ) ) {
85+ r . InvokeRepeating ( new Action ( r . RecycleThink ) , 0 , 0 ) ;
86+ r . SetFlag ( BaseEntity . Flags . On , true , false , true ) ;
87+ r . SendNetworkUpdateImmediate ( ) ;
88+ }
89+ } else r . StartRecycling ( ) ;
90+ } ) ;
91+ } else if ( this . Data . Settings . ToInventory )
92+ NextFrame ( ( ) => {
93+ if ( p == null || p . inventory == null || p . inventory . containerMain == null ||
94+ p . inventory . containerBelt == null || i == null ) return ;
95+
96+ bool flag = false ;
97+ if ( ! p . inventory . containerMain . IsFull ( ) )
98+ flag = i . MoveToContainer ( p . inventory . containerMain ) ;
99+ if ( ! flag && ! p . inventory . containerBelt . IsFull ( ) )
100+ i . MoveToContainer ( p . inventory . containerBelt ) ;
101+ } ) ;
75102 }
76103 }
77104 return null ;
@@ -209,6 +236,8 @@ public class SettingsWrapper {
209236 public bool AllowedInSafeZones = true ;
210237 [ JsonProperty ( "Instant Recycling" ) ]
211238 public bool InstantRecycling = false ;
239+ [ JsonProperty ( "Send Recycled Items To Inventory" ) ]
240+ public bool ToInventory = false ;
212241 [ JsonProperty ( "NPC Ids" ) ]
213242 public List < string > NPCIds = new List < string > ( ) ;
214243 [ JsonProperty ( "Recyclable Types" ) ]
@@ -217,7 +246,7 @@ public class SettingsWrapper {
217246 public List < string > Blacklist = new List < string > ( ) ;
218247 }
219248 public SettingsWrapper Settings = new SettingsWrapper ( ) ;
220- public string VERSION = "3.0.2 " ;
249+ public string VERSION = "3.0.3 " ;
221250 }
222251
223252 #endregion
@@ -265,28 +294,31 @@ private void ValidateConfig() {
265294 "Ammunition" , "Attire" , "Common" , "Component" , "Construction" , "Electrical" ,
266295 "Fun" , "Items" , "Medical" , "Misc" , "Tool" , "Traps" , "Weapon" } ) ,
267296 Blacklist = this . GetSetting ( "blacklist" , new List < string > ( ) ) ,
268- AllowedInSafeZones = this . GetSetting ( "allowSafeZone" , true ) ,
269- InstantRecycling = false ,
270- } ,
271- VERSION = Version . ToString ( )
297+ AllowedInSafeZones = this . GetSetting ( "allowSafeZone" , true )
298+ }
272299 } ;
273- Config . Clear ( ) ;
274- Config . WriteObject ( this . Data , true ) ;
275- Config . Save ( ) ;
276- } else if ( version . Equals ( "3.0.0" ) ) {
300+ this . UpdateAndSave ( ) ;
301+ } else if ( version . Equals ( "3.0.0" ) || version . Equals ( "3.0.1" ) ) {
302+ /* All of these versions should handle updating fine due to
303+ * the ConfigData object having defaults
304+ */
277305 this . Data = Config . ReadObject < ConfigData > ( ) ;
278- if ( this . Data == null ) this . LoadDefaultConfig ( ) ;
306+ if ( this . Data == null || this . Data . Settings == null ) this . LoadDefaultConfig ( ) ;
279307 else {
280- this . Data . VERSION = Version . ToString ( ) ;
281- this . Data . Settings . RecycleCommand = "recycle" ;
282- Config . Clear ( ) ;
283- Config . WriteObject ( this . Data , true ) ;
284- Config . Save ( ) ;
308+ this . Data . Settings . ToInventory = false ;
309+ this . UpdateAndSave ( ) ;
285310 }
286311 }
287312 } catch ( NullReferenceException ) { }
288313 }
289314
315+ private void UpdateAndSave ( ) {
316+ this . Data . VERSION = Version . ToString ( ) ;
317+ Config . Clear ( ) ;
318+ Config . WriteObject ( this . Data , true ) ;
319+ Config . Save ( ) ;
320+ }
321+
290322 #endregion
291323
292324 #region Helpers
0 commit comments