88using System . Linq ;
99using System . Text . RegularExpressions ;
1010using Oxide . CSharp . Common ;
11+ using Oxide . Pooling ;
1112
1213namespace Oxide . Plugins
1314{
@@ -241,14 +242,27 @@ public void CompilationRequested(CompilablePlugin plugin)
241242 Compilation . Current . Add ( plugin ) ;
242243 return ;
243244 }
245+
244246 if ( _compilationQueue . Count < 1 )
245247 {
246248 Interface . Oxide . NextTick ( ( ) =>
247249 {
248- CompileAssembly ( _compilationQueue . ToArray ( ) ) ;
249- _compilationQueue . Clear ( ) ;
250+ List < CompilablePlugin > compilablePlugins = PoolFactory < List < CompilablePlugin > > . Shared . Take ( ) ;
251+ try
252+ {
253+ compilablePlugins . AddRange ( _compilationQueue ) ;
254+ _compilationQueue . Clear ( ) ;
255+
256+ CompileAssembly ( compilablePlugins ) ;
257+ }
258+ finally
259+ {
260+ compilablePlugins . Clear ( ) ;
261+ PoolFactory < List < CompilablePlugin > > . Shared . Return ( compilablePlugins ) ;
262+ }
250263 } ) ;
251264 }
265+
252266 _compilationQueue . Add ( plugin ) ;
253267 }
254268
@@ -278,7 +292,7 @@ private void PluginLoadingCompleted(CompilablePlugin plugin)
278292 }
279293 }
280294
281- private void CompileAssembly ( CompilablePlugin [ ] plugins )
295+ private void CompileAssembly ( List < CompilablePlugin > plugins )
282296 {
283297 _compiler . Compile ( plugins , compilation =>
284298 {
@@ -291,31 +305,41 @@ private void CompileAssembly(CompilablePlugin[] plugins)
291305 GetPluginErrors ( plugin . Name ) . Add ( $ "Failed to compile:{ Environment . NewLine } { errors } ") ;
292306 Interface . Oxide . LogError ( $ "Error while compiling { plugin . ScriptName } :{ Environment . NewLine } { errors } ") ;
293307 }
308+
309+ return ;
294310 }
295- else
311+
312+ if ( compilation . plugins . Count == 0 )
296313 {
297- if ( compilation . plugins . Count > 0 )
298- {
299- string [ ] compiledNames = compilation . plugins . Where ( pl => pl . CompilerErrors . Count == 0 ) . Select ( pl => pl . Name ) . ToArray ( ) ;
300- string verb = compiledNames . Length > 1 ? "were" : "was" ;
301- Interface . Oxide . LogInfo ( $ "{ compiledNames . ToSentence ( ) } { verb } compiled successfully in { Math . Round ( compilation . duration * 1000f ) } ms") ;
302- }
314+ return ;
315+ }
303316
317+ List < string > compiledPlugins = PoolFactory < List < string > > . Shared . Take ( ) ;
318+ try
319+ {
304320 foreach ( CompilablePlugin plugin in compilation . plugins )
305321 {
306- if ( plugin . CompilerErrors . Count == 0 )
307- {
308- Interface . Oxide . UnloadPlugin ( plugin . Name ) ;
309- plugin . OnCompilationSucceeded ( compilation . compiledAssembly ) ;
310- }
311- else
322+ if ( plugin . CompilerErrors . Count > 0 )
312323 {
313324 plugin . OnCompilationFailed ( ) ;
314325 string errors = plugin . CompilerErrors . JoinValues ( Environment . NewLine ) ;
315326 GetPluginErrors ( plugin . Name ) . Add ( $ "Failed to compile:{ Environment . NewLine } { errors } ") ;
316327 Interface . Oxide . LogError ( $ "Error while compiling { plugin . ScriptName } :{ Environment . NewLine } { errors } ") ;
328+ continue ;
317329 }
330+
331+ Interface . Oxide . UnloadPlugin ( plugin . Name ) ;
332+ plugin . OnCompilationSucceeded ( compilation . compiledAssembly ) ;
333+ compiledPlugins . Add ( plugin . Name ) ;
318334 }
335+
336+ string verb = compiledPlugins . Count > 1 ? "were" : "was" ;
337+ Interface . Oxide . LogInfo ( $ "{ compiledPlugins . JoinValues ( ", " ) } { verb } compiled successfully in { Math . Round ( compilation . duration * 1000f ) } ms") ;
338+ }
339+ finally
340+ {
341+ compiledPlugins . Clear ( ) ;
342+ PoolFactory < List < string > > . Shared . Return ( compiledPlugins ) ;
319343 }
320344 } ) ;
321345 }
0 commit comments