Getting players and worlds

Discussion in 'Plugin Development' started by josh12341, Nov 8, 2013.

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

    josh12341

    Just a quick one.
    I want, in my config, that when the person puts &p will equal the command sender and &w will equal the world.
    I've already tried this but it just comes up blank:
    Code:java
    1. .replace("&w", player.getWorld().getName()).replace("&p", player.getName()));

    BTW: if you have any more suggestions for me like player and world please tell me.
     
  2. Offline

    sd5

    josh12341 Can you show us some more code and is there any error? Because basically the code should work
     
  3. Offline

    Freelix2000

    .replaceAll, not replace.
     
  4. Offline

    josh12341

    It still doesn't work

    no error and this is my code for one of my commands:
    Code:java
    1. player.sendMessage(getConfig().getString("Info").replaceAll("&", "ยง").replaceAll("&w", player.getWorld().getName()).replaceAll("&p", player.getName()));


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

    NinjaWAffles

    You'll want to do something along the lines of:

    (This is pseudo code, don't copy & paste)
    Code:Java
    1.  
    2. String coloredMessage = config.getString("message");
    3. coloredMessage.replaceAll("&p", player.getName());
    4. coloredMessage.replaceAll("&w", player.getWorld().getName());
    5. player.sendMessage(coloredMessage);
    6.  
     
  6. Offline

    mazentheamazin

    josh12341
    EDIT: What NinjaWAffles said makes more sense. So for you it'll be something like this:
    Code:java
    1. String coloredMessage = config.getString("Info");
    2. coloredMessage.replaceAll("&p", player.getName());
    3. coloredMessage.repalceAll("&w", player.getWorld().getName());
    4. //Then use coloredMessage as a message or broadcast or however you feel so
    5. //You could do something like this:
    6. String coloredMessage = config.getString("Info");
    7. coloredMessage.replaceAll("&p", player.getName());
    8. //Sending it to a player:
    9. player.sendMessage(coloredMessage.replaceAll("&w", player.getWorld.getName()));
    10.  

    Code:java
    1. this.getConfig().getString("Info").replaceAll("&w", player.getWorld().getName()).replaceAll("&p", player.getName()));
     
Thread Status:
Not open for further replies.

Share This Page