Skip to content

Commit

Permalink
Don't show 'Plugin X was unloaded' at server shutdown, and don't show…
Browse files Browse the repository at this point in the history
… built-in modules in /plugins anymore
  • Loading branch information
UnknownShadow200 committed Jan 1, 2023
1 parent 415771d commit eea094f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion MCGalaxy/Commands/Information/CmdHelp.cs
Expand Up @@ -212,7 +212,7 @@ public sealed class CmdHelp : Command2
}

bool ParsePlugin(Player p, string message) {
foreach (Plugin plugin in Plugin.all)
foreach (Plugin plugin in Plugin.custom)
{
if (plugin.name.CaselessEq(message)) {
plugin.Help(p); return true;
Expand Down
1 change: 0 additions & 1 deletion MCGalaxy/Commands/Information/CmdTime.cs
Expand Up @@ -17,7 +17,6 @@
*/
using System;
using MCGalaxy.Games;
using MCGalaxy.Modules.Games.ZS;

namespace MCGalaxy.Commands.Info
{
Expand Down
11 changes: 3 additions & 8 deletions MCGalaxy/Commands/Scripting/CmdPlugin.cs
Expand Up @@ -38,7 +38,7 @@ public sealed class CmdPlugin : Command2
string modifier = args.Length > 1 ? args[1] : "";

p.Message("Loaded plugins:");
Paginator.Output(p, Plugin.all, pl => pl.name,
Paginator.Output(p, Plugin.custom, pl => pl.name,
"Plugins", "plugins", modifier);
return;
}
Expand All @@ -63,16 +63,11 @@ public sealed class CmdPlugin : Command2

static void UnloadPlugin(Player p, string name) {
int matches;
Plugin plugin = Matcher.Find(p, name, out matches, Plugin.all,
Plugin plugin = Matcher.Find(p, name, out matches, Plugin.custom,
null, pln => pln.name, "plugins");
if (plugin == null) return;

if (Plugin.core.Contains(plugin)) {
p.Message(plugin.name + " is a core plugin and cannot be unloaded.");
return;
}

if (Plugin.Unload(plugin, false)) {
if (Plugin.Unload(plugin)) {
p.Message("Plugin unloaded successfully.");
} else {
p.Message("&WError unloading plugin. See error logs for more information.");
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Modules/Moderation/Notes/NotesPlugin.cs
Expand Up @@ -23,7 +23,7 @@ namespace MCGalaxy.Modules.Moderation.Notes
{
public sealed class NotesPlugin : Plugin
{
public override string name { get { return "Core_NotesPlugin"; } }
public override string name { get { return "Notes"; } }

Command cmdNotes = new CmdNotes();
Command cmdMyNotes = new CmdMyNotes();
Expand Down
37 changes: 24 additions & 13 deletions MCGalaxy/Scripting/Plugin.cs
Expand Up @@ -62,8 +62,8 @@ public abstract class Plugin
public virtual bool LoadAtStartup { get { return true; } }


internal static List<Plugin> core = new List<Plugin>();
public static List<Plugin> all = new List<Plugin>();
public static List<Plugin> core = new List<Plugin>();
public static List<Plugin> custom = new List<Plugin>();

public static bool Load(Plugin p, bool auto) {
try {
Expand All @@ -72,7 +72,7 @@ public abstract class Plugin
Logger.Log(LogType.Warning, "Plugin ({0}) requires a more recent version of {1}!", p.name, Server.SoftwareName);
return false;
}
all.Add(p);
custom.Add(p);

if (p.LoadAtStartup || !auto) {
p.Load(auto);
Expand All @@ -90,24 +90,36 @@ public abstract class Plugin
}
}

public static bool Unload(Plugin p, bool auto) {
bool success = true;
public static bool Unload(Plugin p) {
bool success = UnloadPlugin(p, false);

// TODO only remove if successful?
custom.Remove(p);
core.Remove(p);
return success;
}

static bool UnloadPlugin(Plugin p, bool auto) {
try {
p.Unload(auto);
Logger.Log(LogType.SystemActivity, "Plugin {0} was unloaded.", p.name);
return true;
} catch (Exception ex) {
Logger.LogError("Error unloading plugin " + p.name, ex);
success = false;
return false;
}

all.Remove(p);
return success;
}


public static void UnloadAll() {
for (int i = 0; i < all.Count; i++)
for (int i = 0; i < custom.Count; i++)
{
UnloadPlugin(custom[i], true);
}
custom.Clear();

for (int i = 0; i < core.Count; i++)
{
Unload(all[i], true); i--;
UnloadPlugin(core[i], true);
}
}

Expand All @@ -129,7 +141,6 @@ public abstract class Plugin

static void LoadCorePlugin(Plugin plugin) {
plugin.Load(true);
Plugin.all.Add(plugin);
Plugin.core.Add(plugin);
}
}
Expand Down

0 comments on commit eea094f

Please sign in to comment.