I am stuck (Please Help)

Discussion in 'Resources' started by Jonix55, Aug 20, 2011.

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

    Jonix55

    I am editing some code my friend made for a plugin that sells you who is sleeping and who isn't, the thing is that it only says who is sleeping and doesn't say who isn't. Here is the code:

    package me.Jonix55.BedWarn;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerBedEnterEvent;
    import org.bukkit.event.player.PlayerListener;

    public class BedWarnPlayerListener extends PlayerListener{

    public static BedWarn plugin; public BedWarnPlayerListener(BedWarn instance) {
    plugin = instance;
    }

    public void onPlayerBedEnter(PlayerBedEnterEvent event)
    {
    Player enteredPlayer = event.getPlayer();
    Bukkit.getServer().broadcastMessage(ChatColor.BLUE + "[BedWarn] " + ChatColor.GREEN + enteredPlayer.getDisplayName() + " Is sleeping.");
    Player[] players = Bukkit.getServer().getOnlinePlayers();
    String[] AwakePlayers = null;
    for(int i = 0; i<= players.length; i++)
    {
    if(enteredPlayer.isSleeping())
    {
    }
    else
    {
    AwakePlayers = players.getDisplayName();
    }
    }
    Bukkit.getServer().broadcastMessage(ChatColor.BLUE + "[BedWarn] " + ChatColor.RED + " These players aren't sleeping: " + AwakePlayers);
    }
    }

    Red = Red underline on Eclipse | Yellow=Yellow underline on Eclipse

    Where AwakePlayers is underlined in Eclipse it says: "Null pointer access: The variable AwakePlayers can only be null at this location"


    Please someone help me I would really appreciate.
    This is my first plugin and my friend's first plugin too.

    PS: I didn't made the plugin code a "code" in the thread so you can see the colors
     
  2. Offline

    Slash1987

    1) When you would to get the message displayed?
    If you want to tell who is in bed everytime someone enters in a bed, then the code is this:

    Code:
    package me.Jonix55.BedWarn;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerBedEnterEvent;
    import org.bukkit.event.player.PlayerListener;
    
    public class BedWarnPlayerListener extends PlayerListener{
    
    public static BedWarn plugin; public BedWarnPlayerListener(BedWarn instance) {
    plugin = instance;
    }
    
    public void onPlayerBedEnter(PlayerBedEnterEvent event)
    {
    Player enteredPlayer = event.getPlayer();
    Bukkit.getServer().broadcastMessage(ChatColor.BLUE + "[BedWarn] " + ChatColor.GREEN + enteredPlayer.getDisplayName() + " Is sleeping.");
    Player[] players = Bukkit.getServer().getOnlinePlayers();
    String playerAwake="";
    for(Player player : players){
        if(!player.isSleeping())
            playerAwake+=player.getName()+", ";
    }
    Bukkit.getServer().broadcastMessage(ChatColor.BLUE + "[BedWarn] " + ChatColor.RED + " These players aren't sleeping: " + playerAwake);
    }
    }
     
  3. Offline

    Jonix55

    Both messages would be displayed when someone enters a bed
    Thank you for the help : D I will try it now

    Yes, it works.
    Thank you very much!

    Just one more thing, I want a message with the online players list how do I do that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  4. Offline

    TexasGamer

    You would use the for loop like how the users in bed message is done. For each run of the loop, you would get Player p's username and display it. You can figure it out. ;)

    Not to rain on your friend's parade, but one of my plugins, Bedtime, has a command which shows which users are not already in bed (or idle). In addition, there are plenty of online user plugins. I would recommend you try to innovate in one or both of those areas and make a new plugin or fork the appropriate plugin to contribute to it (and still get credit). (relevant thread)
     
  5. Offline

    Jonix55

    I get it, thank you : )
    By the way, I love your plugins I use 2 of them in my server : )
     
  6. Offline

    TexasGamer

    Glad to help! If you need any help, just let me know.
     
Thread Status:
Not open for further replies.

Share This Page