Random motd every time you refresh?

Discussion in 'Plugin Development' started by flyingtacoz, Oct 29, 2012.

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

    flyingtacoz

    Hello how can I make it so everytime you refresh the server list, the motd changes to something else?
    I have this, but it is only for one. Is there a way to add multiple others and make it pick a random one?
    Code:
        @EventHandler
        public void onPing(ServerListPingEvent event) {
        event.setMotd("Updated to 1.4");
        }
     
  2. Offline

    Deleted user

    Code:java
    1.  
    2. public String a = "1";
    3. public String b = "2";
    4. public String c = "3";
    5. public String d = "4";
    6.  
    7. @EventHandler
    8. public void onPing(ServerListPingEvent event) {
    9. int ran = new Random().nextInt(0 - 4);
    10.  
    11. if (ran == 0) {
    12. event.setMotd(a);
    13. } else if (ran == 1) {
    14. event.setMotd(a);
    15. } else if (ran == 2) {
    16. event.setMotd(b);
    17. } else if (ran == 3) {
    18. event.setMotd(c);
    19. } else if (ran == 4) {
    20. event.setMotd(d);
    21. }
    22. }
    23.  
     
  3. Offline

    GodzOfMadness

    this doesnt not work it gives an error on int ran =newRandom().nextInt(0-4);
     
  4. Offline

    skore87

    Import Random and you should be golden.
     
  5. Offline

    GodzOfMadness

    try the code for yourself it doesnt work

    EDIT:
    Gives console errors
     
  6. Offline

    skore87

    Can you be more vague?
     
  7. Offline

    GodzOfMadness

    i already explained it in the first explanation of the random and then saying to test the code yourself
    and you tell me im vague? your doing nothing dont be sounding sarcastic if you dont do anything
     
  8. Offline

    skore87

    How about you stop thinking everyone can read your mind and just GIVE THE ERROR? Try using some common sense? For instance your RANDOM object needs to have the int 5 as the constructor, not 0-4.
     
  9. Offline

    GodzOfMadness

    I did give you THE ERROR didnt you recall when i said int ran = new Random().nextInt(0 -4);
     
  10. Offline

    skore87

    No you didn't.... You only said you had an error and you did not post the stack trace. THink about it man... We're trying to help you and you're being as vague as you can about it.
     
  11. Offline

    ThatBox

  12. Offline

    GodzOfMadness

    You got a point but i did specify that int ran was the error but i didnt say that was in the console :p
    i was alittle vague in my defense but not so much to have "words of skore87: common sense"
     
  13. Offline

    ZeusAllMighty11

    int ran = new Random().nextInt(amount of terms);
     
  14. Offline

    skore87

    nextInt(int n)
    Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
     
  15. Offline

    flyingtacoz

    Sweet! Thanks! Its working! :D
    Had to change
    int ran =newRandom().nextInt(0-4);
    to
    int ran =newRandom().nextInt(5);
    (should it be 4 though?)
     
  16. Offline

    skore87

    No, I mentioned why in my previous post. At least if you consider the supplied code from earlier.
     
Thread Status:
Not open for further replies.

Share This Page