Creating a Delay between If Statements (After the player leaves).

Discussion in 'Plugin Development' started by kayc01, Dec 2, 2014.

Thread Status:
Not open for further replies.
  1. teej107 Are you just trying to troll me... lol
    Using that would exit the whole plugin.

    Also, mythbusterma thank you, i will give it a test.

    Ok so, almost works but not quite..
    I tested with the one you gave me, however that didn't work. (It closed the gym no matter what)

    So i changed it to this:

    Code:java
    1. if(!p.getPlayer().hasPermission("pixelgym.gym1")) {
    2. return;
    3. }
    4.  
    5. boolean toClose = false;
    6.  
    7. for (Player player: Bukkit.getOnlinePlayers()) {
    8. if(player.equals(p.getPlayer())) {
    9. continue;
    10. }
    11. if (!player.hasPermission("pixelgym.gym1")) {
    12. toClose = true;
    13. break;
    14. }
    15. }
    16. if(toClose) {
    17. Bukkit.broadcastMessage(ChatColor.DARK_GRAY
    18. + "["
    19. + ChatColor.AQUA
    20. + getConfig().getString("config.title")
    21. + ChatColor.DARK_GRAY
    22. + "] "
    23. + ChatColor.translateAlternateColorCodes('&',
    24. getConfig().getString("config.gym1colour"))
    25. + "The " + getConfig().getString("config.gym1")
    26. + "Gym is now " + ChatColor.RED + "Closed");
    27. getConfig().set("config.gym1stat", "Closed");
    28. board.resetScores(Bukkit.getOfflinePlayer(ChatColor
    29. .translateAlternateColorCodes('&', getConfig()
    30. .getString("config.gym1colour"))
    31. + getConfig().getString("config.gym1")));
    32. }
    33. }
    34.  


    So then the default is false and it does not close it every time. However, it still does.
    But the good news is, it is not spamming chat.. lol

    Any idea's? Does not need to be exact code, but like... tell me where to put an exact line of code or something.
    Thanks :)

    Oh wait, mythbusterma
    Would this work:

    Code:java
    1. boolean toClose = true;
    2. //default to close gym
    3.  
    4. for (Player player: Bukkit.getOnlinePlayers()) {
    5. if(player.equals(p.getPlayer())) {
    6. continue;
    7. }
    8. if (player.hasPermission("pixelgym.gym1")) {
    9. //if anyone else does have the permission, set it to false and break out of the for.
    10. toClose = false;
    11. break;
    12. }
    13. }

    Because when you gave me it, in the:


    Code:java
    1. if (player.hasPermission("pixelgym.gym1")) {
    2.  
    3. //if anyone else does have the permission, set it to false and break out of the for.
    4.  
    5. toClose = false;
    6.  
    7. break;
    8.  
    9. }
    10.  
    11. }


    The "toClose" was = true.

    ?

    Thanks

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

    teej107

    No. I am just against giving code out like that to be spoonfed. mythbusterma already pointed out to you how to achieve this before he gave up! At least try and understand the code before you copy and paste it because having somebody else do the thinking for you is only going to hurt yourself.
     
  3. I have been figuring lots of shit out.
    People like you just are trying to delay things.

    Also, the code he gave me is a good start. However, some things do not do what i need. So i was asking him if those above corrects would work.

    I would test it myself all the time, but its not that easy having a popular public server as your test...
    When Cauldron does not support /reload...
     
  4. Offline

    Skionz

    kayc01 He is not trying to delay things. Everyone in this thread simply want you to learn Java before an API written in Java. If the code he gave you does not do what you need why not write your own code?
    Java before Bukkit. Can you really learn to ride a bike before learning to walk?
     
  5. Offline

    mythbusterma

    kayc01

    Yes I wasn't thinking, that's correct.
     
  6. Skionz Understood.
    mythbusterma The 2nd reply's code right? :)
    I put two reply's.

    The reply starting with:

    "Oh wait, @mythbusterma
    Would this work:"
    ?

    Thanks
     
  7. Offline

    mythbusterma

  8. That still does not work ;(

    It is still closing the gym no matter what. (I give another online player the permission "pixelgym.gym1")
    And its not finding him or something...

    Any idea's??
     
  9. Bump:


    Code:
    //So, the problem is, that it needs to check if the player exiting is the last player on the server to have a certain permission. If they are the last person then close the gym. If not, do nothing. However it is closing the gym no matter what. Even if someone else on the server has the permission.
    //this first part is fine (up to the two }'s)       
    @EventHandler
            public void onPlayerQuit(PlayerQuitEvent b) {
                    Player p = b.getPlayer();
                    //player leaving minecraft server (player is called by "p")
                    String enable1 = getConfig().getString("config.gym1enabled");
                    String enable2 = getConfig().getString("config.gym2enabled");
                    //Looks in config.yml to see if the gym is enabled.
                  
                    if (p.hasPermission("pixelgym.gym1")) {
                       //If the player that is leaving has the permission "pixelgym.gym1" then...
                            if (enable1.equalsIgnoreCase("true")) {
                               //if the gym is enabled (the strings), then do:
                                    Bukkit.broadcastMessage(ChatColor.DARK_GRAY
                                                    + "["
                                                    + ChatColor.AQUA
                                                    + getConfig().getString("config.title")
                                                    + ChatColor.DARK_GRAY
                                                    + "] "
                                                    + ChatColor.translateAlternateColorCodes('&',
                                                                    getConfig().getString("config.gym1colour"))
                                                    + "A " + getConfig().getString("config.gym1")
                                                    + " Gym Leader has gone Offline!" + " ("
                                                    + p.getDisplayName() + ")");
                                          //broadcasts closing gym (closes gym)
                            }
                    }
                 //this is where the problem is...
                            if(!p.getPlayer().hasPermission("pixelgym.gym1"))  {
                                //if the player that is leaving the server does not have the permission, do nothing.
                                  return;
                              }
                          
                              boolean toClose = true;
                              //to check if we should close the gym
                            
                              for (Player player: Bukkit.getOnlinePlayers()) {
                                //get all online players on the server
                                  if(player.equals(p.getPlayer())) {
                                      //if the player being checked is the player leaving then skip them.
                                      continue;
                                  }
                                  if (player.hasPermission("pixelgym.gym1")) {
                                     //if anyone else on the server (all online players) has the permission "pixelgym.gym1" then don't      close the gym and break out of the loop.
                                      toClose = false;
                                      break;
                                  }
                                }
                                if(toClose & ((getConfig().getString("config.gym1stat").equals("Open")))) {
                                     //but if the toClose = true, then close the gym. (Meaning no one else on the server has the permission)
                                    Bukkit.broadcastMessage(ChatColor.DARK_GRAY
                                                   + "["
                                                   + ChatColor.AQUA
                                                   + getConfig().getString("config.title")
                                                   + ChatColor.DARK_GRAY
                                                   + "] "
                                                   + ChatColor.translateAlternateColorCodes('&',
                                                               getConfig().getString("config.gym1colour"))
                                                               + "The " + getConfig().getString("config.gym1")
                                                               + "Gym is now " + ChatColor.RED + "Closed");
                                                   getConfig().set("config.gym1stat", "Closed");
                                                   board.resetScores(Bukkit.getOfflinePlayer(ChatColor
                                                               .translateAlternateColorCodes('&', getConfig()
                                                                               .getString("config.gym1colour"))
                                                                               + getConfig().getString("config.gym1")));
                                }
                            }
    
     
Thread Status:
Not open for further replies.

Share This Page