Solved [Unexpected Result]: Simple "messaging" plugin

Discussion in 'Plugin Development' started by PoisonMondo, Dec 8, 2013.

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

    PoisonMondo

    So I've been creating a plugin with a friend and its has all worked so far except the output. While its meant to say the player name, it says "CraftPlayer{name = <playername> }". This may be a nooby question but how can you make it say just the name?

    Code:java
    1.  
    2. package com.zanescode.facepalmer;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. public final class FacePalmer extends JavaPlugin {
    10.  
    11. @Override
    12. public void onEnable(){
    13. getLogger().info("Facepalmer 1.0.1 PLugin is starting up");
    14. }
    15.  
    16. @Override
    17. public void onDisable() {
    18.  
    19. getLogger().info("Facepalmer 1.0.1 plugin is shutting down");
    20. }
    21.  
    22.  
    23. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    24. if(cmd.getName().equalsIgnoreCase("facepalm")){
    25. Player target = (Bukkit.getServer().getPlayer(args[0]));
    26.  
    27. target.sendMessage("Your have been facepalmed by" + sender);
    28. return true;
    29. }
    30. return false;
    31. }
    32. }
    33.  


    here's a picture of the output:

    [​IMG]
     
  2. Use player.getName() to get the name
     
  3. Offline

    samosaara

    Easy lad. The Sender is a object who extends CraftPlayer and the object CraftPlayer is NOT what you looking for Try this (line 27 of your code):
    Code:java
    1. target.sendMessage("Your have been facepalmed by" + sender.getDisplayName());

    EDIT: getDisplayName() is better cuz got the player name plus the other kind of thing like prefix color and blah blah blah.But you can propositionally want just the getName() thing.
     
  4. Offline

    PoisonMondo

    Thank you, but it was solved with the answer

    instead of target.sendMessage("You have been facepalmed by" + sender);
    it sohuld have been: target.sendMessage("You have been facepalmed by" + sender.getName());

    sorry you guys/girls had already replied while i was in the middle of typing my reply

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page