// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 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; public void RaiseTerrainAtlasChanged() { Raise(TerrainAtlasChanged); } /// Raised when the texture pack is changed. public event EventHandler TexturePackChanged; public void RaiseTexturePackChanged() { Raise(TexturePackChanged); } /// Raised when a texture is changed. (such as "terrain", "rain") public event EventHandler TextureChanged; public 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; public void RaiseViewDistanceChanged() { Raise(ViewDistanceChanged); } /// Raised when the held block is changed by the user or by CPE. public event EventHandler HeldBlockChanged; public void RaiseHeldBlockChanged() { Raise(HeldBlockChanged); } /// Raised when the block permissions(can place or delete a block) for the player change. public event EventHandler BlockPermissionsChanged; public void RaiseBlockPermissionsChanged() { Raise(BlockPermissionsChanged); } /// Raised when a block definition is changed. public event EventHandler BlockDefinitionChanged; public void RaiseBlockDefinitionChanged() { Raise(BlockDefinitionChanged); } /// Raised when the server or a client-side command sends a message. public event EventHandler ChatReceived; public 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; public void RaiseChatFontChanged() { Raise(ChatFontChanged); } /// Raised when the hack permissions of the player changes. public event EventHandler HackPermissionsChanged; public void RaiseHackPermissionsChanged() { Raise(HackPermissionsChanged); } /// Raised when the colour codes usable by the player changes. public event EventHandler ColourCodeChanged; public void RaiseColourCodeChanged(char code) { colArgs.Code = code; Raise(ColourCodeChanged, colArgs); } /// Raised when the projection matrix changes. public event EventHandler ProjectionChanged; public void RaiseProjectionChanged() { Raise(ProjectionChanged); } /// Raised when the user is disconnected from the server. public event EventHandler Disconnected; public void RaiseDisconnected(string title, string reason) { discArgs.Title = title; discArgs.Reason = reason; Raise(Disconnected, discArgs); } ChatEventArgs chatArgs = new ChatEventArgs(); TextureEventArgs texArgs = new TextureEventArgs(); ColourCodeEventArgs colArgs = new ColourCodeEventArgs(); DisconnectedEventArgs discArgs = new DisconnectedEventArgs(); } 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; } public sealed class DisconnectedEventArgs : EventArgs { /// General type of the disconnection. public string Title; /// The specific reason for the disconnection. public string Reason; } }