<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Script] Mediator 0.2.1 (Update)]]></title><description><![CDATA[<h1>Mediator (v0.2)</h1>
<p dir="auto"><strong>Author : mumy255</strong></p>
<p dir="auto">This is a JavaScript script designed for managing and transmitting data between different modules or components. Its core functionality is to store data in the form of key-value pairs and use a listener mechanism to respond to data changes.</p>
<p dir="auto">Download:<br />
<a href="/assets/uploads/files/1741366386166-mediator-0.2.1.zip">Mediator 0.2.1 and Document.zip</a>  (for nextgen 0.27)<br />
<a href="/assets/uploads/files/1740659878218-mediator-0.2.zip">Mediator 0.2 and Document.zip</a> (for nextgen 0.26)<br />
<a href="/assets/uploads/files/1740637656186-mediator-0.1.zip">Mediator 0.1 and Document.zip</a> (for nextgen 0.26)</p>
<hr />
<h2>Getting the <code>Mediator</code> Module Instance</h2>
<h3>Code Example</h3>
<pre><code class="language-javascript">var mediator;
script.on("enable", () =&gt; {
    mediator = Client.getModuleManager().get("Mediator");
});
</code></pre>
<h3>Step-by-Step Explanation</h3>
<ol>
<li>
<p dir="auto"><strong><code>script.on("enable", callback)</code></strong>:</p>
<ul>
<li><code>script.on("enable", ...)</code> is an event listener that triggers when the script is enabled. The callback function is executed once the script is enabled.</li>
<li>Inside this callback, the operation to fetch the <code>Mediator</code> module instance is performed.</li>
</ul>
</li>
<li>
<p dir="auto"><strong><code>Client.getModuleManager()</code></strong>:</p>
<ul>
<li><code>Client.getModuleManager()</code> is an API that retrieves the client module manager. It is responsible for managing all loaded and enabled modules.</li>
</ul>
</li>
<li>
<p dir="auto"><strong><code>.get("Mediator")</code></strong>:</p>
<ul>
<li><code>get("Mediator")</code> is used to fetch the instance of the module named <code>Mediator</code> from the module manager. <code>"Mediator"</code> is the unique identifier for this module.</li>
<li>If the <code>Mediator</code> module is loaded and enabled, the <code>get()</code> method will return the module's instance. If the module is not enabled or loaded, it may return <code>null</code>.</li>
</ul>
</li>
<li>
<p dir="auto"><strong>Saving the Module Instance</strong>:</p>
<ul>
<li>The retrieved module instance is saved to the <code>mediator</code> variable, which can be used for subsequent operations.</li>
</ul>
</li>
</ol>
<h3>Notes</h3>
<ul>
<li>The <code>mediator</code> will only be correctly assigned after the script is enabled, so the fetching operation should be inside the <code>script.on("enable", ...)</code> callback.</li>
<li>If the module doesn't exist or wasn't loaded correctly, <code>mediator</code> will be <code>null</code>.</li>
</ul>
<h3>Extended Example</h3>
<pre><code class="language-javascript">var mediator;
script.on("enable", () =&gt; {
    mediator = Client.getModuleManager().get("Mediator");

    if (mediator) {
        Client.displayChatMessage("Mediator module is now available.");
    } else {
        Client.displayChatMessage("Failed to get Mediator module.");
    }
});
</code></pre>
<p dir="auto">In this example, the code checks if <code>mediator</code> was successfully fetched, and displays a message based on the result.</p>
<hr />
<h2>Methods</h2>
<h3><code>putData(key: string, value: any | null): boolean</code></h3>
<p dir="auto">Adds data to the data store and notifies relevant listeners when the data changes.</p>
<p dir="auto"><strong>Parameters:</strong></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Property</th>
<th>Description</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>key</td>
<td>The key of the data item</td>
<td><code>string</code></td>
</tr>
<tr>
<td>value</td>
<td>The value of the data item, can be <code>null</code> to clear the data</td>
<td><code>any/null</code></td>
</tr>
</tbody>
</table>
<p dir="auto"><strong>Return Value:</strong><br />
Returns a boolean indicating whether the operation was successful.</p>
<p dir="auto"><strong>Example:</strong></p>
<pre><code class="language-ts">const success = dataStore.putData("user", { name: "John", age: 30 });
Client.displayChatMessage(success); // true
</code></pre>
<hr />
<h3><code>getData(key: string): any | null</code></h3>
<p dir="auto">Retrieves the data for the specified key.</p>
<p dir="auto"><strong>Parameters:</strong></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Property</th>
<th>Description</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>key</td>
<td>The key of the data item</td>
<td><code>string</code></td>
</tr>
</tbody>
</table>
<p dir="auto"><strong>Return Value:</strong><br />
Returns the data for the specified key, or <code>null</code> if the data does not exist.</p>
<p dir="auto"><strong>Example:</strong></p>
<pre><code class="language-ts">const user = dataStore.getData("user");
Client.displayChatMessage(user); // { name: "John", age: 30 }
</code></pre>
<hr />
<h3><code>clearData(key: string): boolean</code></h3>
<p dir="auto">Clears the data for the specified key.</p>
<p dir="auto"><strong>Parameters:</strong></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Property</th>
<th>Description</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>key</td>
<td>The key of the data item</td>
<td><code>string</code></td>
</tr>
</tbody>
</table>
<p dir="auto"><strong>Return Value:</strong><br />
Returns a boolean indicating whether the operation was successful.</p>
<p dir="auto"><strong>Example:</strong></p>
<pre><code class="language-ts">const success = dataStore.clearData("user");
Client.displayChatMessage(success); // true
</code></pre>
<hr />
<h3><code>hasData(key: string): boolean</code></h3>
<p dir="auto">Checks if data exists for the specified key.</p>
<p dir="auto"><strong>Parameters:</strong></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Property</th>
<th>Description</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>key</td>
<td>The key of the data item</td>
<td><code>string</code></td>
</tr>
</tbody>
</table>
<p dir="auto"><strong>Return Value:</strong><br />
Returns a boolean indicating whether data exists for the specified key.</p>
<p dir="auto"><strong>Example:</strong></p>
<pre><code class="language-ts">const hasData = dataStore.hasData("user");
Client.displayChatMessage(hasData); // true
</code></pre>
<hr />
<h3><code>registerListener(jsObject: { key: string; name: string }, callback: Listener): boolean</code></h3>
<p dir="auto">Registers a listener to monitor changes in data for the specified key.</p>
<p dir="auto"><strong>Parameters:</strong></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Property</th>
<th>Description</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>jsObject</td>
<td>An object containing <code>key</code> (data item's key) and <code>name</code> (listener name)</td>
<td><code>{ key: string; name: string }</code></td>
</tr>
<tr>
<td>callback</td>
<td>The callback function for the listener, which accepts <code>value</code> and <code>state</code> (<code>PRE</code> or <code>POST</code>) as parameters</td>
<td><code>(value: any/null, state: string) =&gt; void</code></td>
</tr>
</tbody>
</table>
<p dir="auto"><strong>Return Value:</strong><br />
Returns a boolean indicating whether the listener was successfully registered.</p>
<p dir="auto"><strong>Example:</strong></p>
<pre><code class="language-ts">const listener: Listener = (value, state) =&gt; {
  Client.displayChatMessage(`Data changed: ${value}, State: ${state}`);
};

mediator.registerListener({ key: "user", name: "userListener" }, listener);
</code></pre>
<hr />
<h3><code>unregisterListener(key: string, name: string): boolean</code></h3>
<p dir="auto">Unregisters a listener to stop monitoring data changes for the specified key.</p>
<p dir="auto"><strong>Parameters:</strong></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Property</th>
<th>Description</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>key</td>
<td>The key of the data item</td>
<td><code>string</code></td>
</tr>
<tr>
<td>name</td>
<td>The name of the listener</td>
<td><code>string</code></td>
</tr>
</tbody>
</table>
<p dir="auto"><strong>Return Value:</strong><br />
Returns a boolean indicating whether the listener was successfully unregistered.</p>
<p dir="auto"><strong>Example:</strong></p>
<pre><code class="language-ts">const success = mediator.unregisterListener("user", "userListener");
Client.displayChatMessage(success); // true
</code></pre>
<hr />
<h2>Example Usage</h2>
<pre><code class="language-ts">// Add data to the data store
mediator.putData("user", { name: "John", age: 30 });

// Retrieve the data
const user = mediator.getData("user");
console.log(user); // Output: { name: "John", age: 30 }

// Check if the data exists
const hasData = mediator.hasData("user");
console.log(hasData); // Output: true

// Register a listener
const listener: Listener = (value, state) =&gt; {
  Client.displayChatMessage(`Data changed: ${value}, State: ${state}`);
};
mediator.registerListener({ key: "user", name: "userListener" }, listener);

// Update the data and trigger the listener
mediator.putData("user", { name: "Jane", age: 25 });  // The state will be "POST"

// Unregister the listener
mediator.unregisterListener("user", "userListener");

// Clear the data
mediator.clearData("user");
</code></pre>
]]></description><link>https://forum.liquidbounce.net/topic/8411/script-mediator-0.2.1-update</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 04:14:22 GMT</lastBuildDate><atom:link href="https://forum.liquidbounce.net/topic/8411.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 21 Feb 2025 06:41:23 GMT</pubDate><ttl>60</ttl></channel></rss>