Avoid infinite loop on plugin unloading.

This commit is contained in:
UnknownShadow200 2016-08-21 20:09:40 +10:00
parent 36ec4f5d31
commit 2b06416426

View File

@ -1,19 +1,19 @@
/* /*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -40,7 +40,7 @@ namespace MCGalaxy {
foreach (Plugin p in tempList) { foreach (Plugin p in tempList) {
if (p.name.ToLower() == name) return p; if (p.name.ToLower() == name) return p;
if (p.name.ToLower().Contains(name)) { if (p.name.ToLower().Contains(name)) {
match = p; matches++; match = p; matches++;
} }
} }
return matches == 1 ? match : null; return matches == 1 ? match : null;
@ -59,10 +59,10 @@ namespace MCGalaxy {
Assembly lib = Assembly.Load(data); Assembly lib = Assembly.Load(data);
try { try {
foreach (Type t in lib.GetTypes()) { foreach (Type t in lib.GetTypes()) {
if (!t.IsSubclassOf(typeof(Plugin))) continue; if (!t.IsSubclassOf(typeof(Plugin))) continue;
instance = (Plugin)Activator.CreateInstance(t); instance = (Plugin)Activator.CreateInstance(t);
break; break;
} }
} catch { } } catch { }
if (instance == null) { if (instance == null) {
@ -103,17 +103,19 @@ namespace MCGalaxy {
public static void Unload(Plugin p, bool shutdown) { public static void Unload(Plugin p, bool shutdown) {
try { try {
p.Unload(shutdown); p.Unload(shutdown);
all.Remove(p);
Server.s.Log(p.name + " was unloaded."); Server.s.Log(p.name + " was unloaded.");
} catch { Server.s.Log("An error occurred while unloading a plugin."); } catch (Exception ex) {
} Server.ErrorLog(ex);
Server.s.Log("An error occurred while unloading a plugin.");
}
all.Remove(p);
} }
/// <summary> Unload all plugins </summary> /// <summary> Unload all plugins </summary>
public static void Unload() { public static void Unload() {
for (int i = 0; i < all.Count; i++) { for (int i = 0; i < all.Count; i++) {
Unload(all[i], true); i--; Unload(all[i], true); i--;
} }
} }
/// <summary> Load all plugins </summary> /// <summary> Load all plugins </summary>
@ -123,9 +125,9 @@ namespace MCGalaxy {
string name = Path.GetFileNameWithoutExtension(path); string name = Path.GetFileNameWithoutExtension(path);
Load(name, true); Load(name, true);
} }
} else { } else {
Directory.CreateDirectory("plugins"); Directory.CreateDirectory("plugins");
} }
// Load Internal Plugins // Load Internal Plugins
CTF.Setup temp = new CTF.Setup(); CTF.Setup temp = new CTF.Setup();