Thread: Trouble with an If statement

Results 1 to 4 of 4
  1. #1 Trouble with an If statement 
    Registered Member Enyll's Avatar
    Join Date
    Aug 2016
    Posts
    121
    Thanks given
    21
    Thanks received
    1
    Rep Power
    13
    Okay so basically I want to make the command ::players say "There is currently 1 player playing *SERVER* at the moment." else if higher than 1 player it will say "There are currently *Greater than 1 player count* players playing *Server*."

    If anybody can help me with this it will be greatly appreciated, thank you. (Sorry for being a noob)

    This is my code:
    Code:
    if (World.getPlayers().size() = 1) {
    player.getPackets().sendGameMessage("There is currently " + World.getPlayers().size() + " player playing " + Settings.SERVER_NAME+ ".");	
    } else {
    player.getPackets().sendGameMessage("There are currently " + World.getPlayers().size() + " players playing " + Settings.SERVER_NAME+ ".");
    return true;
    }
    This is the whole of the ::players command code if needed:
    Code:
    if(cmd[0].equalsIgnoreCase("players")){
                                    int number = 0;
                                            for (int i = 0; i < 316; i++) {
                                    player.getPackets().sendIComponentText(275, i, "");
                                    }
                                    for(Player p5 : World.getPlayers()) {
                                            if(p5 == null)
                                                    continue;
                                            number++;
                                            String titles = "";
    					if (p5.getUsername().equalsIgnoreCase("qwerty")) {
                            			titles = "[<col=FFFF00>[Owner]</col> ] - <img=8> "; 
    					}else if (p5.getUsername().equalsIgnoreCase("")) {
                            			titles = "[<col=FFFF00>[Co Owner]</col> ] - <img=8> "; 
    					}else if (p5.getUsername().equalsIgnoreCase("")) {
                            			titles = "[<col=FFFF00>[Admin]</col> ] - <img=8> "; 
    					} else if (p5.getUsername().equalsIgnoreCase("")) {
                            			titles = "[<col=FFFF00>[Owner]</col> ] - <img=8> "; 
    					} else if (p5.getUsername().equalsIgnoreCase("")) {
                            			titles = "[<col=F859A>[Owner]</col> ] - <img=8> "; 
    					} else if (p5.getUsername().equalsIgnoreCase("")) {
                            			titles = "[<col=FFFF00></col> ] - <img=8> "; 
    					} else if (p5.getUsername().equalsIgnoreCase("")) {
                            			titles = "[ <col=ff0000></col> ] - <img=8> ";
    					} else if (p5.getRights() == 13) { 
                            			titles = "[ <col=00ffe4>Trusted Player</col> ] - <img=15> ";
    					} else if (p5.getRights() == 12) { 
                            			titles = "[ <col=9c2929>Not a Real Owner</col> ] - <img=1> ";
    					} else if (p5.getRights() == 11) { 
                            			titles = "[	<col=660066>Developer</col> ]- <img=1> ";
    					} else if (p5.getRights() == 10) { 
                            			titles = "[ <col=9c2929>Admin</col> ] - <img=1> ";
    					} else if (p5.getRights() == 8) {
                            			titles = "[ <col=660066>Global Moderator</col> ] - <img=1> ";
    					} else if (p5.getRights() == 7) {
                            			titles = "[ <col=FF8000>Moderator</col> ] - <img=0> ";
    					} else if (p5.getRights() == 6) {
                            			titles = "[ <col=00449c>Player Support</col> ] - <img=9> ";
    					} else if (p5.getRights() == 5) {
                            			titles = "[<col=FFF00>Forum Moderator</col>]- <img=6> ";
    					} else if (p5.getRights() == 1) {
                                    	titles = "[ <col=FF00FF>Donator</col> ] - <img=10> ";	
    					} else if (p5.getRights() == 2) {
                            			titles = "[ <col=FF00FF>Super Donator</col> ] - <img=11> ";	
    					} else if (p5.getRights() == 3) {
                            			titles = "[ <col=FF00FF>Respected Donator</col> ] - <img=12> ";	
    					} else if (p5.getRights() == 0) { 
                            			titles = "[ Player ] - ";
    					} else if (p5.getRights() == 9) { 
                            			titles = "[ Player ] - ";
                                                    }
                                                    player.getPackets().sendIComponentText(275, 2, "");
                                            player.getPackets().sendIComponentText(275, (16+number), titles + ""+ p5.getDisplayName());
                                    }
                                    player.getPackets().sendIComponentText(275, 14, "<u=000080>RedemptionX Players</u>");
                                    player.getPackets().sendIComponentText(275, 16, "Players Online: "+number);
                                    //player.getPackets().sendIComponentText(275, 2, "RedemptionX Players Online");
                                    player.getInterfaceManager().sendInterface(275);
    								if (World.getPlayers().size() = 1) {
    player.getPackets().sendGameMessage("There is currently " + World.getPlayers().size() + " player playing " + Settings.SERVER_NAME+ " at the moment.");	
    								} else {
    player.getPackets().sendGameMessage("There are currently " + World.getPlayers().size() + " players playing " + Settings.SERVER_NAME+ ".");
                                    return true;
    								}
    			}
    Reply With Quote  
     

  2. #2  
    Super Donator

    RSPSi's Avatar
    Join Date
    Mar 2011
    Posts
    169
    Thanks given
    70
    Thanks received
    173
    Rep Power
    328
    Code:
    player.getPackets().sendGameMessage("There are currently " + World.getPlayers().size() + " player" + (World.getPlayers().size() > 1 ? "s " : " ") + "playing " + Settings.SERVER_NAME+ ".");
    This works for every plural you want to (provided the plural ends with s) so you can make a method accepting an int and returning a string ("s" or "") if you use it frequently.

    Also the problem with your if statement is because java uses == as a comparator instead of just =
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member
    bracket's Avatar
    Join Date
    Aug 2009
    Posts
    5,278
    Thanks given
    1,059
    Thanks received
    1,465
    Rep Power
    5000
    Code:
    int count = World.getPlayers().size();
    player.getPackets().sendGameMessage("There " + (count > 1 ? "are" : "is") + " currently " + count + " " + (count > 1 ? "players" : "player") + " playing " + Settings.SERVER_NAME.");
    Reply With Quote  
     

  5. Thankful user:


  6. #4  
    Registered Member Enyll's Avatar
    Join Date
    Aug 2016
    Posts
    121
    Thanks given
    21
    Thanks received
    1
    Rep Power
    13
    Quote Originally Posted by Photon View Post
    Code:
    player.getPackets().sendGameMessage("There are currently " + World.getPlayers().size() + " player" + (World.getPlayers().size() > 1 ? "s " : " ") + "playing " + Settings.SERVER_NAME+ ".");
    This works for every plural you want to (provided the plural ends with s) so you can make a method accepting an int and returning a string ("s" or "") if you use it frequently.

    Also the problem with your if statement is because java uses == as a comparator instead of just =
    Quote Originally Posted by Bracket View Post
    Code:
    int count = World.getPlayers().size();
    player.getPackets().sendGameMessage("There " + (count > 1 ? "are" : "is") + " currently " + count + " " + (count > 1 ? "players" : "player") + " playing " + Settings.SERVER_NAME.");
    Thank you both equally! Helped me out a lot
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Help with an if statement in Java (SOF)
    By Markz98 in forum Help
    Replies: 3
    Last Post: 08-22-2014, 02:12 PM
  2. Replies: 7
    Last Post: 05-27-2013, 04:48 AM
  3. Replies: 3
    Last Post: 11-06-2011, 03:06 AM
  4. Replies: 4
    Last Post: 06-22-2010, 09:07 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •