Have you ever had a problem with channels in plugins? (I had)
That's why I want to introduce you ForestChannelAPI.
For usage on larger projects, we recommend more using Redis together with our ForestRedisAPI instead.
Make sure you reloaded maven or gradle in your project.
The problem in channels at all is
we need some online player to send information to Bungee x Spigot or Spigot x Bungee
Our API for Redis ForestRedisAPI
You need to add this dependency into your plugin, then look at under the dependencies example
Maven
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.ForestTechMC</groupId>
<artifactId>ForestChannelAPI</artifactId>
<version>VERSION</version>
<scope>provided</scope>
</dependency>
</dependencies>
Gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.ForestTechMC:ForestChannelAPI:VERSION'
}
Example of events
// Bungee custom event
@EventHandler
public void onChannel(ChannelEvent event) {
ProxiedPlayer player = event.getSender();
String channel = event.getChannel();
String message = event.getMessage();
System.out.println("Our first sender: " + player.getName()); // The person we send from that information
System.out.println("Our first channel name: " + channel); // Channel name <plugin name>:<channel name>
System.out.println("Our first message from that channel: " + message); // Message "Omg its working!"
}
// Spigot custom event
@EventHandler
public void onChannel(ChannelEvent event) {
Player player = event.getPlayer();
String channel = event.getChannel();
String message = event.getMessage();
System.out.println("Our first sender: " + player.getName()); // The person we send from that information
System.out.println("Our first channel name: " + channel); // Channel name <plugin name>:<channel name>
System.out.println("Our first message from that channel: " + message); // Message "Omg its working!"
}
Using API
// Import for Bungee
import cz.foresttech.api.bungee.taker.ChannelAPI;
// Spigot instance
private static Bungee instance;
private ChannelAPI channelAPI;
@Override
public void onEnable() {
instance = this;
channelAPI = new ChannelAPI(this);
channelAPI.register("<channel name>");
}
// Import for Spigot
import cz.foresttech.api.spigot.taker.ChannelAPI;
// Bungee instance
private static Spigot instance;
private ChannelAPI channelAPI;
@Override
public void onEnable() {
instance = this;
channelAPI = new ChannelAPI(this);
channelAPI.register("<channel name>");
}
// GLOBAL (Bungee & Spigot)
// Send method
getChannelAPI().send(player, "<channel name>", "<message>");
getChannelAPI().registerEvent(this, new SuperEvent());
ForestChannelAPI is licensed under the permissive MIT license. Please see LICENSE.txt
for more information.