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