Plugin MessagingNot Working. - HELP

Discussion in 'Spigot Plugin Development' started by BURNED_ICEEE, May 28, 2015.

  1. So I have tried using Plugin Messaging channels, but am very new to them. I need to be able to send a player to a specified server, as well as get the name of the server from the plugin messaging "GetServer" But anything I di in plugin messaging doesnt seem to work? I have the outgoing channel labeled in my onEnable, its getting to the point where it needs to send the player to the proper server, but nothing happens? Any Help? heres some code:

    Code (Text):
    public class Messenger{
        public static HashMap<UUID, String> players = new HashMap<UUID, String>();
        static ReportPlugin plugin;
        public Messenger(ReportPlugin plugin) {Messenger.plugin = plugin;}
    //I have to make that static some the method below has to be static :/ Otherwise id remove the static modifier
     
        public static void sendPlayerToServer(String uid, String server, String location){
            SQLManager.createTpRequest(uid, server, location);
            ByteArrayDataOutput out = ByteStreams.newDataOutput();
            out.writeUTF("Connect");
            out.writeUTF(server);
            Bukkit.broadcastMessage("Teleporting to server " + server);
            Bukkit.getPlayer(UUID.fromString(uid)).sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
        }
     
    }

    After I have finished this, I need help with the "GetServer" method too :(
     
  2. @BURNED_ICEEE any errors in the console? (I wouldn't be surprised if you had any with the current design :p)
     
  3. @DarkSeraphim And thats the thing, there isnt a single error, and I have used this same method in another plugin before and It worked just fine :/ So I really have no clue...
     
  4. Did you checked that the method is even running?
     
  5. Exactly why does your field and method have to be static?
     
  6. Because they are targeted by other static methods. The Main class method is targeted by the "sendPlayerToServer", which is targeted by the Commands class which will not allow the sending method to not have a static modifier.
    Yes I did, because it prints out the server string I hard-coded into the plugin.
     
  7. Have you tried debugging?
     
  8. Yes .-. That is what "Bukkit.broadcastMessage("Teleporting to server " + server);" is for..... its right before the plugin message is sent. It prints out. The method is being runned. But my problem isnt that the method isnt being run... its that PluginMessaging isnt working at all.
     
  9. clip

    Benefactor

    Did you register onEnable?

    getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
     

  10. My onEnable():


    Code (Text):

        @Override
        public void onEnable(){
            instance = this;
            saveDefaultConfig();
            this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
            RegisterCommands();
            registerConfig();      
            Bukkit.getPluginManager().registerEvents(new Events(this), this);
        }
     
  11. The only thing I can think of then is when a player calls the command(s).