MessageChannel API for plugin messaging channels


#1

Download via Github: https://github.com/Crypnotic/MessageChannel/releases/tag/3.0.0

MessageChannel aims to add a common code base to interact with the plugin message channel. I created this utility for ease of life when I found myself writing a system that required interaction between a Spigot server and Bungeecord. Typically, the respective implementations wouldn’t be a problem to work with; however, I found it rather annoying to keep up with the ways in which each implementation had to be interacted with.

All interactions with MessageChannel will flow through your registered Pipeline, but you need to register your Pipeline before you can use it.

  1. First, you get an instance of the PipelineRegistry.
PipelineRegistry registry = MessageChannelAPI.getPipelineRegistry();
  1. Once you’ve gotten an instance of the PipelineRegistry, you need to register your pipeline with your specified channel.
Pipeline pipeline =  registry.register("YOUR CHANNEL HERE");
  1. Now that you’ve gotten your Pipeline registered, it is time to learn how to send information using it.
/* First, you have to craft your message */
PipelineMessage message = new PipelineMessage();

/* Now we right our data */
message.write("Crypnotic");
message.write(true);

/* All that is left to do is send the packet. The first argument is the UUID of the player you want to send the information to */
pipeline.send(uuid, message);
  1. Sweet, we’ve learned how to register our Pipeline and send packets using it. Now, we learn how to listen using our Pipeline.
/* It is really as simple as calling pipeline#addListener() */
pipeline.addListener((target, packet) -> {
	String name = packet.read(String.class);
	boolean awesome = packet.read(boolean.class);

	System.out.println(name + " - " + awesome);

	/* Output: Crypnotic - true */
});

# MessageChannel is hosted on Maven Central #

<dependencies>
	<dependency>
		<groupId>me.crypnotic.messagechannel</groupId>
		<artifactId>messagechannel-api</artifactId>
		<version>3.0.0</version>
		<type>jar</type>
		<scope>provided</scope>
	</dependency>
</dependencies>

If you like what I’m doing and would like to buy me dinner, any donation would be greatly appreciated. <3


#2

perhaps make this slightly more velocity related and less spigot/bungee. Alternatively you could just remove it from a method and leave it as just a code snippet.