Solved Help! How to broadcast player name

Discussion in 'Plugin Development' started by Just_Niico, Apr 28, 2015.

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

    Just_Niico

    Code:
    package com.nico.marsragequit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin{
            public void onEnable(){
                    getLogger().info("Plugin Enabled!");
            }
          
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
                    if(cmd.getName().equalsIgnoreCase("ragequit")){
                            if(sender instanceof Player){
                                Player p = (Player) sender;
                                p.kickPlayer(ChatColor.DARK_RED + "RAGE" + ChatColor.RED + "QUIT");
                                getServer( ).broadcastMessage(ChatColor.DARK_RED + "playername" + ChatColor.RED + "has ragequit!");
                            }else{
                                    sender.sendMessage(ChatColor.GREEN + "This is the console.");
                            }
                    }
                  
                    return false;
            }
    }
    I want the playername to be where it says "playername"
    What is the code to get senders name?

    P.S. I'm still a noob at this
     
  2. Offline

    VictoryShot

    Well you should do p.getPlayer().getName()

    Code:
    getServer( ).broadcastMessage(ChatColor.DARK_RED + "" + p.getPlayer().getName() + "" + ChatColor.RED + "has ragequit!");
     
  3. to get a players name, use p.getName()
    @VictoryShot why p.getPlayer()? p is already a player.

    @Just_Niico Your code looks pretty good. The only things you may change are:
    • remove the logging message in onEnable, Bukkit does this already for every plugin.
    • put return true; in the onCommand method to avoid the usage message to be sent (return false).
     
    Last edited: Apr 28, 2015
  4. Offline

    Just_Niico

    @VictoryShot Thanks, I'll try the code out now.

    @FisheyLP Thanks for the feedback, I'll edit the code now :)
     
Thread Status:
Not open for further replies.

Share This Page