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