Send Message To Specified Player

Discussion in 'Plugin Development' started by morha13, Jul 1, 2013.

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

    morha13

    hello,
    I am developing a HorseRace plugin.
    i want to make that the man that created the race will get message.

    exmple: i am "Morha13" creating a race.
    The player "Dan1301" is typing the command: /rjoin and now he in the race.
    i want that "Morha13" will get message that says that "Dan1301" has joined the race.

    some script...
    when player create a race its saving his name:
    Code:
    settings.getData().set("events." + args[0] + ".p", player.getName());
    i have try to do that and i have some errors:
    Code:java
    1. } else if (pCounter == 3) {
    2. World w = Bukkit.getServer().getWorld("world");
    3. double x = -51;
    4. double y = 64;
    5. double z = 32;
    6. player.teleport(new Location (w, x, y, z));
    7. settings.getData().set("events." + args[0] + ".n3", player.getName());
    8. settings.saveData();
    9. player.sendMessage(ChatColor.DARK_RED + "You Are Number 3");
    10. Player hey= settings.getData().("events." + args[0] + ".p");
    11. hey.sendMessage("hey");


    how can i do it?



    ********Sorry for my English.

    a little update: my settings manager: http://pastebin.com/MpNKV3A2

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

    callum.thepro

    Store the name of the race in a hashmap with a string value of the person who created the race, then when someone uses the command to join the race get the value of the race string and use the getServer().getPlayer("player") method to be able to send the message to the player who created the race.

    Code:java
    1. double x = -51;
    2. double y = 64;
    3. double z = 32;


    Just curious as to why you used double for a int data type?
     
  3. Offline

    morha13

    i am new in bukkit development..
    i saw few tutorials and they are put the numbers in duble and not int...
    i am now still learning java in course in real so...

    ok so i did what you said and still error..
    now its version of the plugin to my server so no config files..
    when is done it to my server i will make a version with config file and staff.. and i post it.
     
  4. Offline

    Ibix13

    put this in: for(Player players : Bukkit.getOnlinePlayers()){
    players.sendMessage(player.getName() + "Has joined the race!");
    }
    I'm issuming that the player is the player who sent the command, if not. Send me your full code.
     
  5. Offline

    morha13

    i am now not in house so i cant check... i will send you in private to full code more few moments...
     
  6. Offline

    callum.thepro

    That is not what he is after i believe, He wants the person who created the race to know who joined and not anyone else.
     
  7. Offline

    morha13

  8. Offline

    callum.thepro

    Okay, What you need to do is store the race as a string in a hashmap and then store the player as the value.
    Example:

    Code:
    HashMap<String, String> races = new HashMap<String, String>();
    Now you need to make sure when the player uses the command you want the players name to be added to the hashmap so to do this you can put

    Code:
    races.put(ARG FOR RACE NAME, PLAYER OBJECT.getName());
    Now what you need to do is when the player executes the command to send a message to the person who created the race.

    You can do this by the following code

    Code:
    Player creator = getServer().getPlayer(races.get(COMMAND ARG FOR RACE NAME));
    creator.sendMessage(ChatColor.GOLD + PLAYEROBJECT.getName() + "has joined the race!");
     
  9. Offline

    Ibix13

    there is a problem with hashmaps, they get reset every time the server is reloaded or restarted. You could use config possibly? morha13 if you want to use config, just ask xD
     
Thread Status:
Not open for further replies.

Share This Page