Solved Join and leave events Showing null?

Discussion in 'Plugin Development' started by PolarCraft, Jan 4, 2014.

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

    PolarCraft

    Okay so I was trying to make a join and leave event that is supposed to display the players name but when I tried the way I am doing It shows null instead of the players name.

    Code:java
    1. @EventHandler
    2. public void joinEvent(PlayerJoinEvent e) {
    3. Player p = Bukkit.getPlayer(getName());
    4. e.setJoinMessage("");
    5. String JoinEvent = ChatColor.translateAlternateColorCodes('&', (String)Main.this.getConfig().getString("join-message"));
    6. Bukkit.broadcastMessage(JoinEvent + ChatColor.GREEN + p);
    7. }
    8.  
    9. @EventHandler
    10. public void leaveEvent(PlayerQuitEvent e) {
    11. Player p = Bukkit.getPlayer(getName());
    12. e.setQuitMessage("");
    13. String LeaveEvent = ChatColor.translateAlternateColorCodes('&', (String)Main.this.getConfig().getString("leave-message"));
    14. Bukkit.broadcastMessage(LeaveEvent + ChatColor.GREEN + p);
    15. }
    16. }
     
  2. Offline

    valon750

    PolarCraft

    Okay, for a start, you need to be doing...

    String pname = event.getPlayer().getName();
     
  3. Offline

    PolarCraft

    valon750 Already did that. Shows null aswell. That is why i am trying bukkit.getPlayer(getName())
     
  4. Offline

    valon750

    PolarCraft

    Code:
     @EventHandler
        public void joinEvent(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            String pname = p.getName();
            e.setJoinMessage("");
            String JoinEvent = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("join-message"));
            Bukkit.broadcastMessage(JoinEvent + ChatColor.GREEN + pname);
        }
    That would work, assuming the path in your config isn't null.

    It would help greatly if you could post the stack-trace, find the line where the error occurs, and let us know :)
     
  5. Offline

    PolarCraft

    valon750 No stack-trace. Their is no stack-trace. Loads fine but displays null instead of example [+] {PLAYER}.
     
  6. Offline

    valon750

    PolarCraft
    Then all I can assume is that the config is pointing to a null path.
     
  7. Offline

    HyrulesLegend

    PolarCraft
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e) {
    3. Player p = e.getPlayer();
    4. e.setJoinMessage(null);
    5. String JoinEvent = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("join-message"));
    6. Bukkit.broadcastMessage(JoinEvent + ChatColor.GREEN + p.getName());
    7. }
     
  8. Offline

    PolarCraft

  9. Offline

    HyrulesLegend

  10. Offline

    ImImprobable

    PolarCraft
    have you made an
    Code:java
    1. @Override
    2. public void onEnable()
    3. {
    4. getServer().getPluginManager().registerEvents(this, this);
    5. }

    Without that in your main or in the class any Events break!
    If that isnt your main change the main to
    Code:java
    1. @Override
    2. public void onEnable()
    3. {
    4. getServer().getPluginManager().registerEvents(this, Plugin);
    5. }

    ImIm
     
  11. ImImprobable Could you think about it for a second? He gets an output from an event handler and thus the event has to be registered already. Because of that, your statement doesn't affect the issue at all.

    PolarCraft When you do 'getName()' just like you did in your fist post, it won't point to the 'getName' of the player, but rather the 'getName' defined in the currently class it is in (which I assume is your main plugin class). Because of that, getting a player with the name of your plugin will almost all the time result in null because there'll be no such player (would be kinda weird having the same name as a plugin).
    Next, you cast to string is redundant because you already get a string back (since you're calling getString on the config).
     
  12. Offline

    ImImprobable

    kumpelblase2
    Didn't read full thread, the title i thought was saying that they were doing nothingno errors or anything.
    Sorry bout that
    ImIm
     
  13. Offline

    AoH_Ruthless

    PolarCraft
    Why don't you use e.setJoinMessage() instead of broadcasting? If you broadcast it will show the default join message as well as what you have set it.

    Your 'null' is coming from a null path. Post your config.
     
  14. Offline

    PolarCraft

    AoH_Ruthless As I said it is not my config -_- Please stop saying it is my config when it is not... And kumpelblase2 Lol my fist post.

    [Edit] Also this was solved long ago.
     
Thread Status:
Not open for further replies.

Share This Page