Merge branch 'general-devel' of github.com:TShock/TShock into general-devel

This commit is contained in:
Lucas Nicodemus 2011-12-30 20:07:36 -07:00
commit ee5e465218
3 changed files with 37 additions and 8 deletions

View file

@ -195,7 +195,7 @@ namespace TShockAPI
[Description("Allows users to register any username with /register")] public bool AllowRegisterAnyUsername;
[Description("Allows users to register any username with /register")]
[Description("Allows users to login with any username with /login")]
public bool AllowLoginAnyUsername;
public static ConfigFile Read(string path)

View file

@ -58,9 +58,12 @@ namespace TShockAPI
public int Type { get; set; }
public byte EditType { get; set; }
}
public static HandlerList<TileEditEventArgs> TileEdit = new HandlerList<TileEditEventArgs>();
public static HandlerList<TileEditEventArgs> TileEdit;
public static bool OnTileEdit(int x, int y, int type, byte editType)
{
if (TileEdit == null)
return false;
var args = new TileEditEventArgs
{
X = x,

View file

@ -11,7 +11,7 @@ namespace TShockAPI
}
public class HandlerList<T> where T : EventArgs
{
protected class HandlerObject
public class HandlerItem
{
public EventHandler<T> Handler { get; set; }
public HandlerPriority Priority { get; set; }
@ -19,10 +19,10 @@ namespace TShockAPI
}
protected object HandlerLock = new object();
protected List<HandlerObject> Handlers { get; set; }
protected List<HandlerItem> Handlers { get; set; }
public HandlerList()
{
Handlers = new List<HandlerObject>();
Handlers = new List<HandlerItem>();
}
/// <summary>
@ -32,10 +32,15 @@ namespace TShockAPI
/// <param name="priority">Priority of the delegate</param>
/// <param name="gethandled">Should the handler receive a call even if it has been handled</param>
public void Register(EventHandler<T> handler, HandlerPriority priority = HandlerPriority.Normal, bool gethandled = false)
{
Register(Create(handler, priority, gethandled));
}
public void Register(HandlerItem obj)
{
lock (HandlerLock)
{
Handlers.Add(new HandlerObject { Handler = handler, Priority = priority, GetHandled = gethandled });
Handlers.Add(obj);
Handlers = Handlers.OrderBy(h => (int)h.Priority).ToList();
}
}
@ -50,11 +55,11 @@ namespace TShockAPI
public void Invoke(object sender, T e)
{
List<HandlerObject> handlers;
List<HandlerItem> handlers;
lock (HandlerLock)
{
//Copy the list for invoking as to not keep it locked during the invokes
handlers = new List<HandlerObject>(Handlers);
handlers = new List<HandlerItem>(Handlers);
}
var hargs = e as HandledEventArgs;
@ -66,6 +71,27 @@ namespace TShockAPI
}
}
}
public static HandlerItem Create(EventHandler<T> handler, HandlerPriority priority = HandlerPriority.Normal, bool gethandled = false)
{
return new HandlerItem { Handler = handler, Priority = priority, GetHandled = gethandled };
}
public static HandlerList<T> operator +(HandlerList<T> hand, HandlerItem obj)
{
if (hand == null)
hand = new HandlerList<T>();
hand.Register(obj);
return hand;
}
public static HandlerList<T> operator +(HandlerList<T> hand, EventHandler<T> handler)
{
if (hand == null)
hand = new HandlerList<T>();
hand.Register(Create(handler));
return hand;
}
}
public enum HandlerPriority