@@ -144,11 +144,13 @@ internal void Prepare(Action callback)
144144
145145 if ( ! added )
146146 {
147- Interface . Oxide . RootLogger . WriteDebug ( LogType . Error , Logging . LogEvent . Compile , "CSharp" , $ "Failed to add default reference: { filename } - Not found!") ;
147+ Interface . Oxide . RootLogger . WriteDebug ( LogType . Error , LogEvent . Compile , "CSharp" , $ "Failed to add default reference: { filename } - Not found!") ;
148148 }
149149 }
150150
151- Interface . Oxide . RootLogger . WriteDebug ( LogType . Info , Logging . LogEvent . Compile , "CSharp" , $ "Preparing compilation") ;
151+ Interface . Oxide . RootLogger . WriteDebug ( LogType . Info , LogEvent . Compile , "CSharp" , $ "Preparing compilation") ;
152+
153+ List < CompilablePlugin > pluginsToAdd = new List < CompilablePlugin > ( ) ;
152154
153155 while ( queuedPlugins . TryDequeue ( out CompilablePlugin plugin ) )
154156 {
@@ -162,20 +164,21 @@ internal void Prepare(Action callback)
162164 plugin . References . Clear ( ) ;
163165 plugin . IncludePaths . Clear ( ) ;
164166 plugin . Requires . Clear ( ) ;
165- Interface . Oxide . RootLogger . WriteDebug ( LogType . Error , Logging . LogEvent . Compile , "CSharp" , $ "Script file is empty: { plugin . Name } ") ;
167+ Interface . Oxide . RootLogger . WriteDebug ( LogType . Error , LogEvent . Compile , "CSharp" , $ "Script file is empty: { plugin . Name } ") ;
166168 RemovePlugin ( plugin ) ;
167169 }
168- else if ( plugins . Add ( plugin ) )
169- {
170- Interface . Oxide . RootLogger . WriteDebug ( LogType . Info , Logging . LogEvent . Compile , "CSharp" , $ "Added plugin to compilation: { plugin . Name } ") ;
171- PreparseScript ( plugin ) ;
172- ResolveReferences ( plugin ) ;
173- }
174- else
170+
171+ if ( pluginsToAdd . Contains ( plugin ) )
175172 {
176- Interface . Oxide . RootLogger . WriteDebug ( LogType . Error , Logging . LogEvent . Compile , "CSharp" , $ "Plugin is already part of the compilation: { plugin . Name } ") ;
173+ Interface . Oxide . RootLogger . WriteDebug ( LogType . Error , LogEvent . Compile , "CSharp" , $ "Plugin is already part of the compilation: { plugin . Name } ") ;
174+ continue ;
177175 }
178176
177+ pluginsToAdd . Add ( plugin ) ;
178+
179+ PreparseScript ( plugin ) ;
180+ ResolveReferences ( plugin ) ;
181+
179182 CacheModifiedScripts ( ) ;
180183
181184 // We don't want the main thread to be able to add more plugins which could be missed
@@ -184,7 +187,21 @@ internal void Prepare(Action callback)
184187 Current = null ;
185188 }
186189 }
187- Interface . Oxide . RootLogger . WriteDebug ( LogType . Info , Logging . LogEvent . Compile , "CSharp" , $ "Done preparing compilation: { plugins . Select ( p => p . Name ) . ToSentence ( ) } ") ;
190+
191+ pluginsToAdd . Sort ( ( x , y ) => string . Compare ( x . Name , y . Name , StringComparison . Ordinal ) ) ;
192+
193+ foreach ( CompilablePlugin plugin in pluginsToAdd )
194+ {
195+ if ( ! plugins . Add ( plugin ) )
196+ {
197+ Interface . Oxide . RootLogger . WriteDebug ( LogType . Error , LogEvent . Compile , "CSharp" , $ "Failed to add plugin to compilation: { plugin . Name } ") ;
198+ continue ;
199+ }
200+
201+ Interface . Oxide . RootLogger . WriteDebug ( LogType . Info , LogEvent . Compile , "CSharp" , $ "Added plugin to compilation: { plugin . Name } ") ;
202+ }
203+
204+ Interface . Oxide . RootLogger . WriteDebug ( LogType . Info , LogEvent . Compile , "CSharp" , $ "Done preparing compilation: { plugins . Select ( p => p . Name ) . ToSentence ( ) } ") ;
188205
189206 callback ( ) ;
190207 }
0 commit comments