Skip to content

gmitch215/SocketMC

πŸ”Œ 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?

  • Extensive: SocketMC provides thorough documentation and examples to help you get started.
  • Robust: SocketMC is built with performance and reliability in mind, especially since it is version-dependent.
  • Transparent: SocketMC is open-source, meaning you can see how it works and contribute to its development.

🚚 Features

  • Client Instructions
    • Draw Shapes
    • Draw Text
    • Play Audio
    • And More!
  • Client Events
    • Player Type and Click Events

πŸ“₯ 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
<project>
    
    <!-- Import CodeMC Repo -->
    
    <repositories>
        <repository>
            <id>codemc-releases</id>
            <url>https://repo.codemc.io/repository/maven-releases/</url>
        </repository>
    </repositories>
    
    <dependencies>
        <!-- Include Core Module -->
        <dependency>
          <groupId>me.gamercoder215.socketmc</groupId>
          <artifactId>socketmc-core</artifactId>
          <version>[VERSION]</version>
        </dependency>
        
        <dependency>
            <groupId>me.gamercoder215.socketmc</groupId>
            <artifactId>socketmc-spigot</artifactId>
            <version>[VERSION]</version>
        </dependency>
        
        <!-- Alternatively, use the Paper Build instead of Spigot -->
        <dependency>
            <groupId>me.gamercoder215.socketmc</groupId>
            <artifactId>socketmc-paper</artifactId>
            <version>[VERSION]</version>
        </dependency>
    </dependencies>
    
</project>
Gradle (Groovy)
repositories {
    maven { url 'https://repo.codemc.io/repository/maven-releases/' }
}

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

dependencies {
    // Include Core Module
    implementation("me.gamercoder215.socketmc:socketmc-core:[VERSION]")
    implementation("me.gamercoder215.socketmc:socketmc-spigot:[VERSION]")
    
    // Alternatively, use the Paper Build
    implementation("me.gamercoder215.socketmc:socketmc-paper:[VERSION]")
}

πŸ“Ί Example

Java

import me.gamercoder215.socketmc.spigot.SocketPlayer;
import me.gamercoder215.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 me.gamercoder215.socketmc.spigot.SocketPlayer
import me.gamercoder215.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