Base Extension
Base extensions for the Bot Viewer get called as soon as the user connects to the bot's server.
PluginCore.cs
1
[Plugin(1, "Bot Viewer Extension Plugin", "Test plugin to showcase bot viewer possible extensions.")]
2
public class PluginCore : IStartPlugin
3
{
4
public override void OnLoad(int version, int subversion, int buildversion) { }
5
public override PluginResponse OnEnable(IBotSettings botSettings) { return base.OnEnable(botSettings); }
6
}
7
8
public class ExampleHandler : IBotServerHandler {
9
public override async Task OnConnected() {
10
// This function is called once a user connects to the bot's proxy server.
11
12
this.Events.FromClient.ChatMessage += (message, token) => {
13
// Catch all messages from the client that start with a # symbol.
14
if (message.StartsWith("#")) {
15
16
// servers have to respond in a json format, e.g. https://minecraft.tools/en/json_text.php
17
this.Client.SendChat("{\"text\":\"Test plugin received '"+message+"' message from you.\", \"bold\":true}");
18
19
token.Cancel(); // Do not forward it to the server game server.
20
}
21
};
22
23
this.Events.ToClient.AddVelocityToEntity += (entityId, modifiers, token) => {
24
// Disable all velocity data being sent from the server (no knockback).
25
if(entityId == Context.Player.GetEntityId())
26
token.Cancel();
27
};
28
}
29
}
Copied!
Result from running the example code.

Events

As can be seen from the example code, there are two types of bot viewer based events: FromClient, which are events that get triggered by the client attempting to send data to the server, and ToClient, which are events that get triggered when the server is attempting to send data to the client.
Each of these events can be cancelled, which means it would never reach the desired destination (e.g.: cancel a ChatMessage event so a chat message is never actually sent to the server). This can be done by calling the token.Cancel() function, where the token variable is a pararemeter of each event.

Sending Data to Client

Data can be sent to the client through the Client variable, which should be accessed in the following way: this.Client, as can be seen in the example code. This class has functions that allow you to send data to the client, such as SendChat, which would send a chat message to che connected client.
To send data to the server you can still use the Context variable, which is heavilly documented in the API section of the docs.
Last modified 1yr ago