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
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); } }
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.
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)