Solved Sending a Player to A different server using BungeeCord

Discussion in 'Plugin Development' started by BENCLABSTER, Jun 13, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    BENCLABSTER

    So I have been making a private plugin for a server that spawns you in with a few items, a book with info in it, a compass (transporter), and a feather that when you right click it gives you speed. When you right click the compass, it opens a chest gui with items in it, and when you click them it cancels the inventory click event and runs something. This specific server has md_5 's bungee, and I have been trying to make it so when you click an item it sends you to another server on the bungee proxy. Since bungee isn't a plugin, this is pretty hard to do. You cant do player.performCommand("server sg") for instance. If anyone could help it would be much appreciated! This is the code I have, but it isnt working. I get errors on registerOutgoingPluginChannel and p.sendPluginMessage(this, "BungeeCord", b.toByteArray()); I am pretty sure that the errors are happening because this is in an eventhandler, but I have seen other servers do it so I know it is possible.

    Code:java
    1.  
    2. Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    3.  
    4.  
    5. try {
    6. out.writeUTF("Connect");
    7. out.writeUTF(this.plugin.getConfig().getString(slot + ".server"));
    8. } catch (IOException ex) {
    9.  
    10. }
    11. p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
    12. break;
    13.  
     
  2. Offline

    Nitnelave

    What are the errors you're getting?
     
  3. You might want to post this on the spiggot forums, since this is not part of the bukkit project.
     
  4. Offline

    BENCLABSTER

    On the two things, it tells me to cast plugin to them and when I do, it doesnt work. Also, it makes me surround the out.writeutf with try and catch.
    this is a bukkit plugin, Im trying to get it to speak to bungee, which is possible.
     
  5. Offline

    Nitnelave

    The try catch block is normal, as there are some unhandled exception that needs to be handled (i.e. there's a problem while writing, what do you do?).
    As for the first error, what class are you writing this code in? If it doesn't extend JavaPlugin, you will get an error when writing "this". You need to give them a Plugin (or JavaPlugin).
     
  6. Offline

    BENCLABSTER

    the class is an event listener, I made it extend javaplugin, and it still will not work, although I did not have to bind player anymore.
     
  7. Offline

    Nitnelave

    You don't just take any class and make it extend JavaPlugin! You take your main class, which ALREADY extends JavaPlugin, and you pass the instance to the Listener (usually in the constructor), and then you can use it in the method.
     
  8. Offline

    BENCLABSTER

    How would I do that? Also, this is the error I get in my test server's console [​IMG]
     
  9. Offline

    sheigutn

    you have to write out.writeUTF("Connect to"); instead of out.writeUTF("Connect");
     
  10. Offline

    BENCLABSTER

    that didnt work either, and on all bungee things it says connect [​IMG]

    I suppose a more practical approach to this is to make it so on a command instead of an inventory click event, it sends you to another server, and make it so on an inventory click event it runs said command? The inventory click event has to be in a separate file than main, but the commands for this plugin are in main.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  11. Offline

    sheigutn

    make a constructor with your main class as a parameter in your listener class, rmove the extends Javaplugin in your listener class, save the parameters value in a field, and replace the "this" in reigsterOutgoingPluginChannel and sendPluginMessage with the fields name.
     
  12. Offline

    LaxWasHere

  13. Offline

    BENCLABSTER

    Actually Im not, how would I incorporate that into a different thing?

    EDIT: I included this, but I get an error on the line

    Code:java
    1. getCommand("servers").setExecutor(new Server(this));


    And the error is on setExecutor and Server(this)

    everything else works
     
  14. Offline

    sheigutn

    read my 2nd post it says everything to get it working :)
     
  15. Offline

    BENCLABSTER

    Could you providecode/give screenshots? Im still a semi-noob at java
     
  16. Offline

    sheigutn

    whats the name of your main class and your listener class? :)
     
  17. Offline

    BENCLABSTER

    The Main Class's name is Main and the listener is EventListener
     
  18. Offline

    chasechocolate

    BENCLABSTER that is not necessary. I'm assuming Lax made a /servers command to open the menu, but you can remove it.
     
  19. Offline

    BENCLABSTER

    removed it, still doesnt work.
     
  20. Offline

    nitrousspark

    couldn't you put bungee cord in the server then force the player to run the /server pvp command?
     
  21. Offline

    BENCLABSTER

    No. Bungee is a proxy, not a plugin.
     
  22. Offline

    Deckerz

    doesn't bungee have a api and for this to work the plugin would need to be in the bungee plugins folder not the server
     
  23. Offline

    BENCLABSTER

    Im not sure, but it seems like it has been done with out it.

    Solved! Thank you all for the help, especially LaxWasHere !

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  24. Offline

    Deckerz

    how did you do it?
     
  25. Offline

    BENCLABSTER

    I used this several times and made it so on the inventory click it ran them
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. if (!(sender instanceof Player)) {
    3. sender.sendMessage("You can't teleport to other servers, console!");
    4. return false;
    5. }
    6. Player p = (Player)sender;
    7. if (commandLabel.equalsIgnoreCase("game")) {
    8. ByteArrayDataOutput out = ByteStreams.newDataOutput();
    9. out.writeUTF("Connect");
    10. out.writeUTF("game");
    11. p.sendPluginMessage(this, "BungeeCord", out.toByteArray());
    12. }
     
Thread Status:
Not open for further replies.

Share This Page