Last active
December 14, 2015 02:29
-
-
Save roblabla/5013688 to your computer and use it in GitHub Desktop.
Example of how to use plugin channel for bukkit-bungee communication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayOutputStream; | |
import java.io.DataOutputStream; | |
import org.bukkit.Bukkit; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import org.bukkit.scheduler.BukkitRunnable; | |
import org.bukkit.scheduler.BukkitTask; | |
public class BukkitPlug extends JavaPlugin { | |
BukkitTask task; | |
@Override | |
public void onEnable() { | |
task = new RunStuff().runTaskTimer(this, 0l, 120L); | |
} | |
@Override | |
public void onDisable() { | |
task.cancel(); | |
} | |
public class RunStuff extends BukkitRunnable { | |
Plugin plug; | |
public RunStuff(Plugin sender) { | |
plug = sender; | |
} | |
public void run() { | |
ByteArrayOutputStream outbytes = new ByteArrayOutputStream(); | |
DataOutputStream out = new DataOutputStream(outbytes); | |
out.writeUTF("Stuff"); | |
if (Bukkit.getOnlinePlayers().length != 0) | |
Bukkit.getOnlinePlayers()[0].sendPluginMessage(plug, "BungeePlug", outbytes.getBytes()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.eventbus.Subscribe; | |
import net.md_5.bungee.api.plugin.Plugin; | |
import net.md_5.bungee.api.plugin.Listener; | |
import net.md_5.bungee.api.ProxyServer; | |
import net.md_5.bungee.api.event.PluginMessageEvent; | |
public class BungeePlug extends Plugin implements Listener { | |
public void onEnable() { | |
ProxyServer.getInstance().getPluginManager().registerListener(this); | |
} | |
public void onDisable() { | |
// Do nothing | |
} | |
@Subscribe | |
public void onPluginMessage(PluginMessageEvent e) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment