BungeeCord Switch Servers

Discussion in 'Spigot Plugin Development' started by FloThePony, Jun 17, 2015.

  1. Hai,
    I have been trying to make a GUI for switching servers.
    The event gets fired, because I changed it to Bukkit.broadcastMessage("blah blah");
    and it worked.

    This is my code:

    http://hastebin.com/peyeqicapo.avrasm
    or
    Code (Text):
    @EventHandler
        public void guiUse(InventoryClickEvent e) {
         if (e.getWhoClicked() instanceof Player) {
          Player p = (Player) e.getWhoClicked();
         if (e.getInventory() != null) {
          // e.setCancelled(true);
           if (e.getCurrentItem() != null) {
           if (e.getCurrentItem().hasItemMeta()) {
           if (e.getCurrentItem().getItemMeta().getDisplayName()
             .contains("UHC")) {
               ByteArrayDataOutput out = ByteStreams.newDataOutput();
               out.writeUTF("Connect");
               out.writeUTF("uhc-1");
               p.sendPluginMessage(this, "BungeeCord", out.toByteArray());
           }
           else if (e.getCurrentItem().getItemMeta().getDisplayName()
                   .contains("KitPvP")) {
               ByteArrayDataOutput out = ByteStreams.newDataOutput();
               out.writeUTF("Connect");
               out.writeUTF("kitpvp");
               p.sendPluginMessage(this, "BungeeCord", out.toByteArray());  
                  }
           else if (e.getCurrentItem().getItemMeta().getDisplayName()
                   .contains("Prison")) {
               ByteArrayDataOutput out = ByteStreams.newDataOutput();
               out.writeUTF("Connect");
               out.writeUTF("prison");
               p.sendPluginMessage(this, "BungeeCord", out.toByteArray());
           }
           else if (e.getCurrentItem().getItemMeta().getDisplayName()
                   .contains("Creative")) {
               ByteArrayDataOutput out = ByteStreams.newDataOutput();
               out.writeUTF("Connect");
               out.writeUTF("creative");
               p.sendPluginMessage(this, "BungeeCord", out.toByteArray());
           }
           }
           }
          }
         }
        }
    }

    Thanks bae,
    - Flo
     
  2. Have you registered the outgoing Plugin channel?
     
    • Agree Agree x 1
  3. I am a 100% nub at BungeeCord in plugins.
    But thanks
     
  4. You need to put this on your "onEnable":
    this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
     
    • Agree Agree x 2
    • Useful Useful x 1
  5. Thank you!
     
  6. But be sure to add
    Code (Text):

    implements PluginMessageListener
     
    next to your

    Code (Text):

    public class YourMain extends JavaPlugin {
     
    so it looks like this:

    Code (Text):

    public class YourMain extends JavaPlugin implements PluginMessageListener {
     
    The Class Name "YourMain" needs to be replaced with the name of your class file tho.