// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT using System; namespace ClassicalSharp.Events { public abstract class EventsBase { protected void Raise( EventHandler handler ) { if( handler == null ) return; handler( this, EventArgs.Empty ); } protected void Raise( EventHandler handler, T args ) where T : EventArgs { if( handler == null ) return; handler( this, args ); } } public class OtherEvents : EventsBase { /// Raised when the terrain atlas ("terrain.png") is changed. public event EventHandler TerrainAtlasChanged; internal void RaiseTerrainAtlasChanged() { Raise( TerrainAtlasChanged ); } /// Raised when the texture pack is changed. public event EventHandler TexturePackChanged; internal void RaiseTexturePackChanged() { Raise( TexturePackChanged ); } /// Raised when a texture is changed. (such as "terrain", "rain") public event EventHandler TextureChanged; internal void RaiseTextureChanged( string name, byte[] data ) { texArgs.Name = name; texArgs.Data = data; Raise( TextureChanged, texArgs ); } /// Raised when the user changed their view/fog distance. public event EventHandler ViewDistanceChanged; internal void RaiseViewDistanceChanged() { Raise( ViewDistanceChanged ); } /// Raised when the held block is changed by the user or by CPE. public event EventHandler HeldBlockChanged; internal void RaiseHeldBlockChanged() { Raise( HeldBlockChanged ); } /// Raised when the block permissions(can place or delete a block) for the player change. public event EventHandler BlockPermissionsChanged; internal void RaiseBlockPermissionsChanged() { Raise( BlockPermissionsChanged ); } /// Raised when a block definition is changed. public event EventHandler BlockDefinitionChanged; internal void RaiseBlockDefinitionChanged() { Raise( BlockDefinitionChanged ); } /// Raised when the server or a client-side command sends a message. public event EventHandler ChatReceived; internal void RaiseChatReceived( string text, MessageType type ) { chatArgs.Type = type; chatArgs.Text = text; Raise( ChatReceived, chatArgs ); } /// Raised when the user changes chat font to arial or back to bitmapped font, /// also raised when the bitmapped font changes. public event EventHandler ChatFontChanged; internal void RaiseChatFontChanged() { Raise( ChatFontChanged ); } /// Raised when the hack permissions of the player changes. public event EventHandler HackPermissionsChanged; internal void RaiseHackPermissionsChanged() { Raise( HackPermissionsChanged ); } /// Raised when the colour codes usable by the player changes. public event EventHandler ColourCodeChanged; internal void RaiseColourCodeChanged( char code ) { colArgs.Code = code; Raise( ColourCodeChanged, colArgs ); } /// Raised when the projection matrix changes. public event EventHandler ProjectionChanged; internal void RaiseProjectionChanged() { Raise( ProjectionChanged ); } ChatEventArgs chatArgs = new ChatEventArgs(); TextureEventArgs texArgs = new TextureEventArgs(); ColourCodeEventArgs colArgs = new ColourCodeEventArgs(); } public sealed class ChatEventArgs : EventArgs { /// Where this chat message should appear on the screen. public MessageType Type; /// Raw text of the message (including colour codes), /// with code page 437 indices converted to their unicode representations. public string Text; } public sealed class ColourCodeEventArgs : EventArgs { /// ASCII colour code that was changed. public char Code; } public sealed class TextureEventArgs : EventArgs { /// Location of the file within a texture pack, without a directory. (e.g. "snow.png") public string Name; /// Raw data of the file. public byte[] Data; } }