Skip to content

dev:Basic Extension Structure

Väinämö Łūmikērø edited this page Feb 2, 2017 · 4 revisions

Basic Extension Structure

This template contains all necessary properties and functions of an extension. However, it might not be always up to date. Explanations to the components are commented below.

public string Author { get; }
// Author of the extension

public bool ClientInstance { get; }
// Whether the extension needs a seperate instance in the client.
// This is always necessary when displaying Forms in the client.

public string CompatibleForestualVersion { get; } = "Any";
// Obsolete, keep "Any".

public string Description { get; }
// Description of the extension

public bool Disabled { get; set; }
// Used by the server to deactivate the extension.
// Check this field when doing stuff if the extension is enabled.

private List<Listener> ServerListeners_ = new List<Listener>();
public IEnumerable<Listener> ServerListeners => ServerListeners_;
// Contains all listeners for server events.

private List<Listener> ClientListeners_ = new List<Listener>();
public IEnumerable<Listener> ClientListeners => ClientListeners_;
// Contains all listeners for client events.

public string Name { get; }
// Name of the extension.

public string Namespace { get; }
// Namespace of the extension.
// Like package names in Java. Usually your domain backwards .{projectname}.
// Example: ml.festival.motd

public bool StorageNeeded { get; } = false;
// Set this to true if your extension needs storage to save data.

public string StoragePath { get; set; }
// Contains the path to the assigned storage.
// Use this when saving/loading data.

public string Path { get; set; }
// Unnecessary. Contains the path of your Extension.

public F2Core.Compatibility.Version Version { get; } = new F2Core.Compatibility.Version {
    Major = 1,
    Minor = 0,
    Patch = 0,
    Suffix = VersioningProfiler.Suffixes.none,
    Commit = "",
    ReleaseDate = "17w5",
    SupportedVersion = VersioningProfiler.Lowest.ToMediumString()
};
// Version of your extension.

public void RegisterServerListener(Delegate @delegate, Event @event) {
    ServerListeners_.Add(new Listener(@event, @delegate, this.Namespace));
}
// Optional function to facilitate registering server event listeners.

public void RegisterClientListener(Delegate @delegate, Event @event) {
    ClientListeners_.Add(new Listener(@event, @delegate, this.Namespace));
}
// Optional function to facilitate registering client event listeners.

// The following functions get called by the server and additionally by the client
// when ClientInstance is set to true.
// However, OnDisable() might not always be called when the server/client crashes.

public void OnEnable() { }
// Function called when the extension gets enabled.
// Register your listeners and severities here.

public void OnRun() { }
// Function called after the extension gets enabled.
// Only called when the extension gets enabled at the start of the server/client.
// Load your data here, because the StoragePath isn't set when OnEnabled() gets called.

public void OnDisable() { }
//  Function called when the extension gets disabled.