Get Player name?

Discussion in 'Plugin Development' started by shohouku, Feb 20, 2013.

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

    shohouku

    How can I get the player name?

    I want it to be added here:


    Code:
              bm.setPages(Arrays.asList("playername",
                      "lol!"));
    I want the player name to be where the "playername" is.

    Is it possible?
     
  2. Offline

    kreashenz

    event.getPlayer(); or if its a command, put Player player = (Player)sender;
     
  3. Offline

    microgeek

    I honestly hope that I misread that title.
     
  4. Offline

    shohouku

    The event could not be resolved,

    Any help? .





     
  5. Offline

    Cjreek

    Well.. Where are you?...
     
  6. Offline

    shohouku

    I want to display the players name in the book for example:

    If someone grabs the book their name will be automatically placed inside the book....

    So the book will get the players name and display it inside the book.




    I want the code to be in the book....


    Code:
    package journal;
     
    import java.util.Arrays;
     
     
     
     
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.event.Event;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.inventory.meta.BookMeta;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
     
    public class book extends JavaPlugin implements Listener {
     
     
      public boolean onCommand(CommandSender sender, Command command,
              String label, String[] args) {
     
        if (label.equalsIgnoreCase("test"));
          if (sender instanceof Player) {
     
              ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
              BookMeta bm = (BookMeta) book.getItemMeta();
              bm.setPages(Arrays.asList("I WANT THE PLAYERS NAME TO BE HERE",
                      "lol!"));
            bm.setAuthor("System");
            bm.setTitle("Character Book");
            book.setItemMeta(bm);
            ((Player) sender).getInventory().addItem(book);
     
     
          }else{
              sender.sendMessage("You have to be a player to use this command1");
     
          }
         
          return false;
              }
     
    public String getPlayer(String string) {
        // TODO Auto-generated method stub
        return null;
    }
    }
    
     
  7. Offline

    Cjreek

    Player player = (Player)sender;
    bm.setPages(Arrays.asList(player.getName(), "lol!"));
     
  8. Offline

    shohouku

    How do I get a name before "player.getName()" ?

    And thanks for the help! ^_^
     
  9. Offline

    Cjreek

    I don't understand what you want to say/ask...
     
  10. Offline

    shohouku


    Player player = (Player)sender;
    bm.setPages(Arrays.asList(player.getName(), "lol!"));

    I want a "name" before the players name, like "lol!")); but it is before the players name.

    For example: (INSIDE THE BOOK)

    this is my name: Test


    I don't want to just put my name I want to add more words so its not boring :)

    Does it help? :eek:
     
  11. Offline

    Cjreek

    You should seriously learn how to code with java...... Just do:

    "This is your name: " + player.getName()
     
    shohouku and stuntguy3000 like this.
  12. Offline

    shohouku

    Sorry yeah haha just started yesterday and thanks.
     
Thread Status:
Not open for further replies.

Share This Page