1+ using Oxide . Core . Libraries . Covalence ;
12using System . Collections . Generic ;
23using Newtonsoft . Json ;
34using UnityEngine ;
78
89namespace Oxide . Plugins {
910
10- [ Info ( "Recycle" , "5Dev24" , "3.0.0 " ) ]
11+ [ Info ( "Recycle" , "5Dev24" , "3.0.1 " ) ]
1112 [ Description ( "Recycle items into their resources" ) ]
1213 public class Recycle : RustPlugin {
1314
@@ -29,6 +30,8 @@ private void Loaded() {
2930 this . ValidateConfig ( ) ;
3031 this . Data = Config . ReadObject < ConfigData > ( ) ;
3132
33+ this . AddCovalenceCommand ( this . Data ? . Settings ? . RecycleCommand ?? "recycle" , "RecycleCommand" , null ) ;
34+
3235 permission . RegisterPermission ( Recycle . AdminPermission , this ) ;
3336 permission . RegisterPermission ( Recycle . RecyclerPermission , this ) ;
3437 permission . RegisterPermission ( Recycle . CooldownBypassPermission , this ) ;
@@ -55,41 +58,25 @@ private object CanAcceptItem(ItemContainer con, Item i, int target) {
5558 Recycler r = con . entityOwner as Recycler ;
5659 if ( this . IsRecycleBox ( r ) ) {
5760 BasePlayer p = this . PlayerFromRecycler ( r . net . ID ) ;
58- if ( target < 6 && ( ! this . Data . Settings . RecyclableTypes . Contains ( Enum . GetName ( typeof ( ItemCategory ) , i . info . category ) ) ||
59- this . Data . Settings . Blacklist . Contains ( i . info . shortname ) ) ) {
60- if ( p != null ) this . PrintToChat ( p , this . GetMessage ( "Recycle" , "Invalid" , p ) ) ;
61- return ItemContainer . CanAcceptResult . CannotAcceptRightNow ;
61+ if ( target < 6 ) {
62+ if ( ! this . Data . Settings . RecyclableTypes . Contains ( Enum . GetName ( typeof ( ItemCategory ) , i . info . category ) ) ||
63+ this . Data . Settings . Blacklist . Contains ( i . info . shortname ) ) {
64+ if ( p != null ) this . PrintToChat ( p , this . GetMessage ( "Recycle" , "Invalid" , p ) ) ;
65+ 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 ( ) ;
6274 }
6375 }
6476 }
6577 return null ;
6678 }
6779
68- private void OnItemAddedToContainer ( ItemContainer con , Item i ) {
69- if ( con . entityOwner is Recycler ) {
70- Recycler r = con . entityOwner as Recycler ;
71- if ( this . IsRecycleBox ( r ) ) {
72- BasePlayer p = this . PlayerFromRecycler ( r . net . ID ) ;
73- if ( i == null || p == null || i . position >= 6 ) return ;
74- else if ( ! this . Data . Settings . RecyclableTypes . Contains ( Enum . GetName ( typeof ( ItemCategory ) , i . info . category ) ) ||
75- this . Data . Settings . Blacklist . Contains ( i . info . shortname ) ) {
76- this . PrintToChat ( p , this . GetMessage ( "Recycle" , "Invalid" , p ) ) ;
77- return ;
78- }
79-
80- if ( this . Data . Settings . InstantRecycling ) {
81- if ( ! r . IsOn ( ) ) {
82- r . InvokeRepeating ( new Action ( r . RecycleThink ) , 0 , 0 ) ;
83- Effect . server . Run ( r . startSound . resourcePath , r , 0U , Vector3 . zero , Vector3 . zero , null , false ) ;
84- r . SetFlag ( BaseEntity . Flags . On , true , false , true ) ;
85- r . SendNetworkUpdateImmediate ( ) ;
86- }
87- } else
88- r . StartRecycling ( ) ;
89- }
90- }
91- }
92-
9380 private object OnRecycleItem ( Recycler r , Item i ) {
9481 if ( this . IsRecycleBox ( r ) ) {
9582 BasePlayer p = this . PlayerFromRecycler ( r . net . ID ) ;
@@ -167,12 +154,9 @@ private void OnUseNPC(BasePlayer npc, BasePlayer p) {
167154
168155 #region Commands
169156
170- [ ConsoleCommand ( "recycle" ) ]
171- private void RecycleConsoleCommand ( ConsoleSystem . Arg arg ) =>
172- this . RecycleChatCommand ( arg . Connection . player as BasePlayer , arg . cmd . Name , arg . Args ) ;
173-
174- [ ChatCommand ( "recycle" ) ]
175- private void RecycleChatCommand ( BasePlayer p , string cmd , string [ ] args ) {
157+ private void RecycleCommand ( IPlayer iP , string cmd , string [ ] args ) {
158+ BasePlayer p = iP . Object as BasePlayer ;
159+ if ( p == null ) return ;
176160 if ( ! this . Data . Settings . NPCOnly && this . CanPlayerOpenRecycler ( p ) ) {
177161 this . OpenRecycler ( p ) ;
178162 if ( this . Data . Settings . Cooldown > 0 ) {
@@ -211,6 +195,8 @@ public struct EntityAndPlayer {
211195
212196 public class ConfigData {
213197 public class SettingsWrapper {
198+ [ JsonProperty ( "Command To Open Recycler" ) ]
199+ public string RecycleCommand = "recycle" ;
214200 [ JsonProperty ( "Cooldown (in minutes)" ) ]
215201 public float Cooldown = 5.0f ;
216202 [ JsonProperty ( "Maximum Radiation" ) ]
@@ -231,7 +217,7 @@ public class SettingsWrapper {
231217 public List < string > Blacklist = new List < string > ( ) ;
232218 }
233219 public SettingsWrapper Settings = new SettingsWrapper ( ) ;
234- public string VERSION = "3.0.0 " ;
220+ public string VERSION = "3.0.1 " ;
235221 }
236222
237223 #endregion
@@ -244,6 +230,7 @@ protected override void LoadDefaultConfig() {
244230 "Ammunition" , "Attire" , "Common" , "Component" , "Construction" , "Electrical" ,
245231 "Fun" , "Items" , "Medical" , "Misc" , "Tool" , "Traps" , "Weapon" } ;
246232 Config . WriteObject ( tmp , true ) ;
233+ this . Data = tmp ;
247234 }
248235
249236 private T GetSetting < T > ( string val , T defaultVal ) {
@@ -286,6 +273,16 @@ private void ValidateConfig() {
286273 Config . Clear ( ) ;
287274 Config . WriteObject ( this . Data , true ) ;
288275 Config . Save ( ) ;
276+ } else if ( version . Equals ( "3.0.0" ) ) {
277+ this . Data = Config . ReadObject < ConfigData > ( ) ;
278+ if ( this . Data == null ) this . LoadDefaultConfig ( ) ;
279+ 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 ( ) ;
285+ }
289286 }
290287 } catch ( NullReferenceException ) { }
291288 }
@@ -477,4 +474,4 @@ public void RemoveNPC(string id) {
477474
478475 }
479476
480- }
477+ }
0 commit comments