gmitch215 / SocketMC

šŸ–„ļø Communicate directly with Minecraft Clients from the Server
http://socketmc.gmitch215.xyz/
GNU General Public License v3.0
11 stars 0 forks source link
client-to-server fabric forge minecraft paper paper-api spigot spigot-api

šŸ”Œ SocketMC

Minecraft Server-to-Client Direct Communication Library

Notice | License

Background

"Client-side only" is a term widely used when advancing in plugin development, where you're limited in interacting with player's own client. The goal of this library is to solve this issue: create a mod that can communicate with your plugin. That is exactly what SocketMC does! Send your own instructions to clients using our simple and efficient API.

ā“ Why?

šŸšš Features

šŸ“„ Installation

GitHub branch checks state GitHub GitHub issues

Prerequisites

All players on your server must have the SocketMC mod installed. You can download them from the following locations:

In your Plugin

GitHub release (latest by date) Static Badge Static Badge Static Badge

Maven ```xml codemc-releases https://repo.codemc.io/repository/maven-releases/ xyz.gmitch215.socketmc socketmc-core [VERSION] xyz.gmitch215.socketmc socketmc-spigot [VERSION] xyz.gmitch215.socketmc socketmc-paper [VERSION] ```
Gradle (Groovy) ```gradle repositories { maven { url 'https://repo.codemc.io/repository/maven-releases/' } } dependencies { // Include Core Module implementation 'xyz.gmitch215.socketmc:socketmc-core:[VERSION]' implementation 'xyz.gmitch215.socketmc:socketmc-spigot:[VERSION]' // Alternatively, use the Paper Build implementation 'xyz.gmitch215.socketmc:socketmc-paper:[VERSION]' } ```
Gradle (Kotlin DSL) ```kotlin repositories { maven(url = "https://repo.codemc.io/repository/maven-releases/") } dependencies { // Include Core Module implementation("xyz.gmitch215.socketmc:socketmc-core:[VERSION]") implementation("xyz.gmitch215.socketmc:socketmc-spigot:[VERSION]") // Alternatively, use the Paper Build implementation("xyz.gmitch215.socketmc:socketmc-paper:[VERSION]") } ```

šŸ“ŗ Example

Java

import xyz.gmitch215.socketmc.spigot.SocketPlayer;
import xyz.gmitch215.socketmc.instruction.Instruction;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.time.Duration;

public class MyPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        sendInstructions();
    }

    public void sendInstructions() {
        Player player = Bukkit.getPlayer("gmitch215");
        SocketPlayer sp = new SocketPlayer(player);

        // Specify X and Y, Text, and Duration
        // Pass the plugin instance to the sendInstruction method
        sp.sendInstruction(Instruction.drawText(100, 100, "Hello World", Duration.ofSeconds(5)), this);
    }
}

Kotlin

import xyz.gmitch215.socketmc.spigot.SocketPlayer
import xyz.gmitch215.socketmc.instruction.Instruction

import org.bukkit.Bukkit
import org.bukkit.entity.Player

import java.time.Duration

class MyPlugin : JavaPlugin() {
    override fun onEnable() {
        sendInstructions()
    }

    fun sendInstructions() {
        val player: Player = Bukkit.getPlayer("gmitch215")
        val sp = SocketPlayer(player)

        // Specify X and Y, Text, and Duration
        // Pass the plugin instance to the sendInstruction method
        sp.sendInstruction(Instruction.drawText(100, 100, "Hello World", Duration.ofSeconds(5)), this)
    }
}

Output:

Example