mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 20:16:36 -04:00
Now with less code duplication.
This commit is contained in:
parent
ad81975b95
commit
6e7c44e3e9
@ -153,7 +153,7 @@ namespace MCGalaxy {
|
||||
//try {
|
||||
if (PhysicsUpdate != null)
|
||||
PhysicsUpdate(x, y, z, C.data, this);
|
||||
if (OnPhysicsUpdateEvent.events.Count > 0)
|
||||
if (OnPhysicsUpdateEvent.handlers.Count > 0)
|
||||
OnPhysicsUpdateEvent.Call(x, y, z, C.data, this);
|
||||
|
||||
if ((C.data.Raw & mask) == 0 || ExtraInfoPhysics.DoComplex(this, ref C)) {
|
||||
|
@ -732,11 +732,11 @@ return;
|
||||
|
||||
if (OnMove != null) OnMove(this, x, y, z);
|
||||
if (PlayerMove != null) PlayerMove(this, x, y, z);
|
||||
if (PlayerMoveEvent.events.Count > 0) PlayerMoveEvent.Call(this, x, y, z);
|
||||
PlayerMoveEvent.Call(this, x, y, z);
|
||||
|
||||
if (OnRotate != null) OnRotate(this, rot);
|
||||
if (PlayerRotate != null) PlayerRotate(this, rot);
|
||||
if (PlayerRotateEvent.events.Count > 0) PlayerRotateEvent.Call(this, rot);
|
||||
PlayerRotateEvent.Call(this, rot);
|
||||
|
||||
if (cancelmove) {
|
||||
SendPos(0xFF, pos[0], pos[1], pos[2], rot[0], rot[1]); return;
|
||||
@ -1090,13 +1090,13 @@ return;
|
||||
//IRCBot.Say("<" + name + "> " + newtext);
|
||||
if (OnChat != null) OnChat(this, text);
|
||||
if (PlayerChat != null) PlayerChat(this, text);
|
||||
if (OnPlayerChatEvent.events.Count > 0) OnPlayerChatEvent.Call(this, text);
|
||||
if (OnPlayerChatEvent.handlers.Count > 0) OnPlayerChatEvent.Call(this, text);
|
||||
return;
|
||||
}
|
||||
Server.s.Log("<" + name + "> " + text);
|
||||
if (OnChat != null) OnChat(this, text);
|
||||
if (PlayerChat != null) PlayerChat(this, text);
|
||||
if (OnPlayerChatEvent.events.Count > 0) OnPlayerChatEvent.Call(this, text);
|
||||
if (OnPlayerChatEvent.handlers.Count > 0) OnPlayerChatEvent.Call(this, text);
|
||||
|
||||
if (cancelchat) {
|
||||
cancelchat = false; return;
|
||||
|
@ -26,14 +26,8 @@ namespace MCGalaxy {
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Group g) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(g);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling GroupLoaded Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(g));
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,14 +37,8 @@ namespace MCGalaxy {
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call() {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method();
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling GroupLoad Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl());
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,14 +48,8 @@ namespace MCGalaxy {
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call() {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method();
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling GroupSave Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl());
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,14 +59,8 @@ namespace MCGalaxy {
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p, Group newRank) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p, newRank);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling PlayerRankSet Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(p, newRank));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,71 +21,43 @@ using MCGalaxy.BlockPhysics;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
public sealed class OnLevelLoadedEvent : IPluginEvent<Level.OnLevelLoaded> {
|
||||
|
||||
public sealed class OnLevelLoadedEvent : IPluginEvent<Level.OnLevelLoaded> {
|
||||
internal OnLevelLoadedEvent(Level.OnLevelLoaded method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Level l) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(l);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling LevelLoaded Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(l));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class OnLevelLoadEvent : IPluginEvent<Level.OnLevelLoad> {
|
||||
|
||||
public sealed class OnLevelLoadEvent : IPluginEvent<Level.OnLevelLoad> {
|
||||
internal OnLevelLoadEvent(Level.OnLevelLoad method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(string name) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(name);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling LevelLoad Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(name));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class OnLevelSaveEvent : IPluginEvent<Level.OnLevelSave> {
|
||||
|
||||
public sealed class OnLevelSaveEvent : IPluginEvent<Level.OnLevelSave> {
|
||||
internal OnLevelSaveEvent(Level.OnLevelSave method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Level l) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(l);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling LevelSave Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(l));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class OnLevelUnloadEvent : IPluginEvent<Level.OnLevelUnload> {
|
||||
|
||||
public sealed class OnLevelUnloadEvent : IPluginEvent<Level.OnLevelUnload> {
|
||||
internal OnLevelUnloadEvent(Level.OnLevelUnload method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Level l) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(l);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling LevelUnload Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(l));
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,14 +67,8 @@ namespace MCGalaxy {
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(ushort x, ushort y, ushort z, PhysicsArgs extraInfo, Level l) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(x, y, z, extraInfo, l);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling PhysicsUpdate Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(x, y, z, extraInfo, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,200 +21,123 @@ using System.Collections.Generic;
|
||||
namespace MCGalaxy {
|
||||
|
||||
/// <summary> This event is called whenever a player chats on the server </summary>
|
||||
public sealed class OnPlayerChatEvent : IPluginEvent<Player.OnPlayerChat> {
|
||||
|
||||
public sealed class OnPlayerChatEvent : IPluginEvent<Player.OnPlayerChat> {
|
||||
internal OnPlayerChatEvent(Player.OnPlayerChat method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p, string message) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p, message);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling PlayerChat Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
public static void Call(Player p, string message) {
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(p, message));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> This event is called whenever a player moves </summary>
|
||||
public sealed class PlayerMoveEvent : IPluginEvent<Player.OnPlayerMove>
|
||||
{
|
||||
public sealed class PlayerMoveEvent : IPluginEvent<Player.OnPlayerMove> {
|
||||
internal PlayerMoveEvent(Player.OnPlayerMove method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p, ushort x, ushort y, ushort z) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p, x, y, z);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling PlayerMove Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(p, x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> This event is called whenever a player rotates </summary>
|
||||
public sealed class PlayerRotateEvent : IPluginEvent<Player.OnPlayerRotate> {
|
||||
|
||||
public sealed class PlayerRotateEvent : IPluginEvent<Player.OnPlayerRotate> {
|
||||
internal PlayerRotateEvent(Player.OnPlayerRotate method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p, byte[] rot) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p, rot);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling PlayerRotate Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
public static void Call(Player p, byte[] rot) {
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(p, rot));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> This event is called whenever the player goes AFK </summary>
|
||||
public sealed class OnPlayerAFKEvent: IPluginEvent<Player.OnAFK > {
|
||||
|
||||
internal OnPlayerAFKEvent(Player.OnAFK method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling OnAFK Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(p));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> This event is called whenever the server saves data to MySQL or SQLite </summary>
|
||||
public sealed class OnMySQLSaveEvent : IPluginEvent<Player.OnMySQLSave> {
|
||||
|
||||
internal OnMySQLSaveEvent(Player.OnMySQLSave method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p, string mysqlcommand) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p, mysqlcommand);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling MySQLSave Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(p, mysqlcommand));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> This event is called whenever a player uses a command </summary>
|
||||
public sealed class OnPlayerCommandEvent : IPluginEvent<Player.OnPlayerCommand> {
|
||||
|
||||
public sealed class OnPlayerCommandEvent : IPluginEvent<Player.OnPlayerCommand> {
|
||||
internal OnPlayerCommandEvent(Player.OnPlayerCommand method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(string cmd, Player p, string message) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(cmd, p, message);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling PlayerCommand Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(cmd, p, message));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> This event is called whenever a player connects to the server </summary>
|
||||
public sealed class OnPlayerConnectEvent: IPluginEvent<Player.OnPlayerConnect> {
|
||||
|
||||
public sealed class OnPlayerConnectEvent: IPluginEvent<Player.OnPlayerConnect> {
|
||||
internal OnPlayerConnectEvent(Player.OnPlayerConnect method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling PlayerConnect Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(p));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> This event is called whenever a player dies in-game </summary>
|
||||
public sealed class OnPlayerDeathEvent : IPluginEvent<Player.OnPlayerDeath> {
|
||||
|
||||
public sealed class OnPlayerDeathEvent : IPluginEvent<Player.OnPlayerDeath> {
|
||||
internal OnPlayerDeathEvent(Player.OnPlayerDeath method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p, byte type) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p, type);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling PlayerDeath Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
public static void Call(Player p, byte block) {
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(p, block));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> This event is called whenever a player connects to the server </summary>
|
||||
public sealed class OnPlayerDisconnectEvent : IPluginEvent<Player.OnPlayerDisconnect> {
|
||||
|
||||
public sealed class OnPlayerDisconnectEvent : IPluginEvent<Player.OnPlayerDisconnect> {
|
||||
internal OnPlayerDisconnectEvent(Player.OnPlayerDisconnect method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p, string reason) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p,reason);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling PlayerDisconnect Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(p, reason));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> This event is called whenever a player places or deletes a block </summary>
|
||||
public sealed class OnBlockChangeEvent : IPluginEvent<Player.BlockchangeEventHandler> {
|
||||
|
||||
public sealed class OnBlockChangeEvent : IPluginEvent<Player.BlockchangeEventHandler> {
|
||||
internal OnBlockChangeEvent(Player.BlockchangeEventHandler method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p, ushort x, ushort y, ushort z, byte block, byte extBlock) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p, x, y, z, block, extBlock);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored calling BlockChange Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(p, x, y, z, block, extBlock));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> This event is called whenever a player recieves a message from the server or from another player </summary>
|
||||
public sealed class OnMessageRecieveEvent : IPluginEvent<Player.OnPlayerMessageReceived> {
|
||||
|
||||
internal OnMessageRecieveEvent(Player.OnPlayerMessageReceived method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Player p, string message) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(p, message);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling MessageRecieve Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(p, message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,54 +20,33 @@ using System.Collections.Generic;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
public sealed class OnConsoleCommandEvent : IPluginEvent<Server.OnConsoleCommand> {
|
||||
|
||||
public sealed class OnConsoleCommandEvent : IPluginEvent<Server.OnConsoleCommand> {
|
||||
internal OnConsoleCommandEvent(Server.OnConsoleCommand method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(string cmd, string message) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(cmd, message);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling ConsoleCommand Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(cmd, message));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class OnServerErrorEvent : IPluginEvent<Server.OnServerError> {
|
||||
|
||||
public sealed class OnServerErrorEvent : IPluginEvent<Server.OnServerError> {
|
||||
internal OnServerErrorEvent(Server.OnServerError method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(Exception ex) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(ex);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling ServerError Event."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(ex));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class OnServerLogEvent : IPluginEvent<Server.OnServerLog> {
|
||||
|
||||
internal OnServerLogEvent(Server.OnServerLog method, Priority priority, Plugin plugin)
|
||||
: base(method, priority, plugin) { }
|
||||
|
||||
public static void Call(string message) {
|
||||
events.ForEach(
|
||||
pl => {
|
||||
try {
|
||||
pl.method(message);
|
||||
} catch (Exception e) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling the Server LogEvent."); Server.ErrorLog(e);
|
||||
}
|
||||
});
|
||||
if (handlers.Count == 0) return;
|
||||
CallImpl(pl => pl(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,13 +18,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MCGalaxy
|
||||
{
|
||||
// NOTE: You must use a different delegate type for each subclass
|
||||
// This is because the static events are unique to each generic instantiation, not each subclass.
|
||||
public class IPluginEvent<IMethod>
|
||||
{
|
||||
internal static List<IPluginEvent<IMethod>> events = new List<IPluginEvent<IMethod>>();
|
||||
namespace MCGalaxy {
|
||||
// NOTE: You must use a different delegate type for each subclass
|
||||
// This is because the static events are unique to each generic instantiation, not each subclass.
|
||||
public class IPluginEvent<IMethod> {
|
||||
internal static List<IPluginEvent<IMethod>> handlers = new List<IPluginEvent<IMethod>>();
|
||||
protected internal Plugin plugin;
|
||||
protected internal IMethod method;
|
||||
protected internal Priority priority;
|
||||
@ -34,18 +32,6 @@ namespace MCGalaxy
|
||||
this.priority = priority;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
protected static void Organize() {
|
||||
events.Sort((a, b) => b.priority.CompareTo(a.priority));
|
||||
}
|
||||
|
||||
public static IPluginEvent<IMethod> Find(Plugin plugin) {
|
||||
foreach (var p in events) {
|
||||
if (p.plugin == plugin)
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary> Register this event </summary>
|
||||
/// <param name="method">This is the delegate that will get called when this event occurs</param>
|
||||
@ -55,7 +41,7 @@ namespace MCGalaxy
|
||||
public static void Register(IMethod method, Priority priority, Plugin plugin, bool bypass = false) {
|
||||
if (Find(plugin) != null && !bypass)
|
||||
throw new ArgumentException("The user tried to register 2 of the same event!");
|
||||
events.Add(new IPluginEvent<IMethod>(method, priority, plugin));
|
||||
handlers.Add(new IPluginEvent<IMethod>(method, priority, plugin));
|
||||
Organize();
|
||||
}
|
||||
|
||||
@ -65,7 +51,35 @@ namespace MCGalaxy
|
||||
if (Find(plugin) == null)
|
||||
throw new ArgumentException("This plugin doesnt have this event registered!");
|
||||
else
|
||||
events.Remove(Find(plugin));
|
||||
handlers.Remove(Find(plugin));
|
||||
}
|
||||
|
||||
public static IPluginEvent<IMethod> Find(Plugin plugin) {
|
||||
foreach (var p in handlers) {
|
||||
if (p.plugin == plugin) return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected static void Organize() {
|
||||
handlers.Sort((a, b) => b.priority.CompareTo(a.priority));
|
||||
}
|
||||
|
||||
protected static void CallImpl(Action<IMethod> action) {
|
||||
try {
|
||||
foreach (var pl in handlers) {
|
||||
try {
|
||||
action(pl.method);
|
||||
} catch (Exception ex) {
|
||||
Server.s.Log("Plugin " + pl.plugin.name + " errored when calling " + typeof(IMethod).Name + " event");
|
||||
Server.ErrorLog(ex);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Server.s.Log("Error when calling " + typeof(IMethod).Name + " event");
|
||||
Server.ErrorLog(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user