BungeeCord send player to another server

Discussion in 'BungeeCord Plugin Development' started by NICEXDD, Feb 6, 2014.

  1. Hi!
    Its first time when i use BungeeCord so i have got some problems..

    It's a part of my menu-gui plugin.

    Code (Text):
    @EventHandler
    public void onInventoryClick(InventoryClickEvent e) {
    if (!e.getInventory().getName().equalsIgnoreCase(this.inv.getName())) return;
    if (e.getCurrentItem().getItemMeta() == null) return;

    // Nowy serwer
    if (e.getCurrentItem().getItemMeta().getDisplayName().contains("SkyBlock")) {
    e.setCancelled(true);
    String server = e.getCurrentItem().getItemMeta().getDisplayName(); // server - name of server to connect
    Player player = (Player)e.getWhoClicked();
    //
    // BungeeCord teleporting(...)
    //
    e.getWhoClicked().closeInventory();
    player.sendMessage(this.prefix + "Trwa laczenie z serwerem " + e.getCurrentItem().getItemMeta().getDisplayName() + ChatColor.MAGIC + " ||||||||");
    }


    How to teleport player to server onInventoryClick ? I found many theads on this forum about this, but
    i don't understand it yet. Please show me some examples on this code.

    PS: Sorry for my english but i am from Poland.

    I Greet.
     
  2. @NICEXDD
    Hello,
    There are a couple of plugins that I use for this. It is very simple to setup. The list is:
    -CreateYourOwnMenus (http://dev.bukkit.org/bukkit-plugins/createyourownmenus/)
    -MicroJump(http://dev.bukkit.org/bukkit-plugins/microjump/)
    -Skript(http://dev.bukkit.org/bukkit-plugins/skript/)

    That is how my stuff is setup, The player joins and gets a menu to open from CreateYourOwnMenus (The join event is coded through Skript) and when the player choses the item that is scripted to go to a server, MicroJump plugin is used.

    If you have questions, I could show you my setup through my server or help you configure it on yours.

    TekeDome
     
    • Funny Funny x 6
    • Agree Agree x 2
    • Disagree Disagree x 2
    • Optimistic Optimistic x 1
  3. Hes asking for the code.

    See: http://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/
     
    • Agree Agree x 6
    • Useful Useful x 3
  4. What do you think about this part of code ? Should it works ? I dont have installed BungeeCord on my server yet, so i cant test it ;p

    Code (Text):

      @EventHandler
      public void onInventoryClick(InventoryClickEvent e) {
        if (!e.getInventory().getName().equalsIgnoreCase(this.inv.getName())) return;
        if (e.getCurrentItem().getItemMeta() == null) return;
     
        // Nowy serwer
        if (e.getCurrentItem().getItemMeta().getDisplayName().contains("SkyBlock")) {      
          e.setCancelled(true);
          String server = e.getCurrentItem().getItemMeta().getDisplayName(); // Deklaracja nazwy serwera w BungeeCord
          Player player = (Player)e.getWhoClicked();
          //
            // BungeeCord teleport to (server) TEST!!!!!!!!!!!!!
                  ByteArrayDataOutput out = ByteStreams.newDataOutput();
                  out.writeUTF("Connect");
                  out.writeUTF("skyblock"); // = nazwa serwera dla BungeeCord
                player.sendPluginMessage((Plugin) this, "BungeeCord", out.toByteArray());
                e.getWhoClicked().closeInventory();
                player.sendMessage(this.prefix + "Trwa laczenie z serwerem " + e.getCurrentItem().getItemMeta().getDisplayName() + ChatColor.MAGIC + " ||||||||");
          }
          //
    Code (Text):
      public void onEnable() {
          //BungeeCord
          getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    }
    This would teleport to server named "skyblock" in BungeeCord config ?
     
  5. Tux

    Tux

    Well, you are never ever supposed to close the inventory during the InventoryClickEvent.

    Your BungeeCord-related code is correct, however.
     
  6. Wait do you import org.bukkit.plugin.Plugin for the (Plugin) bit?
     
    • Optimistic Optimistic x 1
  7. How do I edit /server name? Ie. /server OPFactions
     
  8. In bungee config, the list of servers. You name the seerver then assign the ips...
     
  9. I realize this is old, and I apologize for the necro. But I think this could be a confusing point for some people, as I have many, many times closed the inventory on the click event, and nothing harmful has ever come from it. What's wrong with it?