{Help} If's not running!

Discussion in 'Plugin Development' started by VinexAx789, Jan 22, 2016.

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

    VinexAx789

    Problem: The method works other than the bottom if's any idea how to fix this or maybe some pointers?

    Things that I've tried: I've done debugging.

    Code:

    Code:
    public void updatescoreonQuit(Player p) {
            // RAN DEBUG = Working
            Bukkit.broadcastMessage(String.valueOf(teamsleft.size()));
    
            Bukkit.getScheduler().runTaskLater(this, new Runnable() {
    
                public void run() {
    
                    if (attackers.contains(p.getUniqueId())) {
                        attackersleft = attackersleft - 1;
                        attackers.remove(p.getUniqueId());
                        attackerScore.setScore(attackers.size());
    
                    }
                    if (defenders.contains(p.getUniqueId())) {
                        defendersleft = defendersleft - 1;
                        defenders.remove(p.getUniqueId());
                        defenderScore.setScore(defenders.size());
                    }
                    if (attackers.size() == 0) {
                        Bukkit.broadcastMessage("DEBUG REMOVED Attackers");
                        teamsleft.remove("attackers");
                    }
                    if (defenders.size() == 0) {
                        Bukkit.broadcastMessage("DEBUG REMOVED Defenders");
                        teamsleft.remove("defenders");
                    } // END OF WORKING DEBUGS
    
                    Bukkit.broadcastMessage(String.valueOf(teamsleft.size()));
                    // START OF DEBUGS NOT RUNNING
                    if (teamsleft.size() == 1) {
                        Bukkit.broadcastMessage("DEBUG == 1");
                        if (teamsleft.get(0).equalsIgnoreCase("attackers")) {
                            Bukkit.broadcastMessage("DEBUG Attackers");
                            endGame.gameOver(0);
                            endTimer.cancel();
                        }
                        if (teamsleft.get(0).equalsIgnoreCase("defenders")) {
                            Bukkit.broadcastMessage("DEBUG Defenders");
                            endGame.gameOver(1);
                            endTimer.cancel();
                        }
                    } // END OF STOP WORKING IF's
                }
    
            }, 10);
            Bukkit.getScheduler().runTaskLater(this, new Runnable() {
    
                public void run() {
    
                    attackerScore.setScore(attackers.size());
                    defenderScore.setScore(defenders.size());
    
                }
            }, 20);
    
        }
    If that doesn't help: I can provide more code if you ask if that isn't enough. I've also provided comments within the code.

    Thanks again,

    - Vine
     
  2. Offline

    Evonoucono

    Any errors? Did you check to see if this line of code meets it's conditions? Try adding an else to this if statement and get the size of teamleft to see if it's the size you think it is.
    Code:
    if (teamsleft.size() == 1) {
     
  3. Offline

    VinexAx789

    @Evonoucono No errors. Thing is it was working before. But now it's not so I must of done something. Add an else and check the size? Because after the fact of the debugging when it hits that if, teamsleft = 0.
     
  4. Offline

    Evonoucono

    if teamleft.size is 0 on that if statement which is checking for a size of 1, the code would not be run though...
     
  5. Offline

    VinexAx789

    Let me screenshot you some of my debug messages.

    Screenshot:

    [​IMG]

    1 = Before the method:

    Code:
    // RAN DEBUG = Working
            Bukkit.broadcastMessage(String.valueOf(teamsleft.size()));
    DEBUG REMOVED Attackers and Defenders = Before the if's do not run:
    Code:
    if (attackers.size() == 0) {
                        Bukkit.broadcastMessage("DEBUG REMOVED Attackers");
                        teamsleft.remove("attackers");
                    }
                    if (defenders.size() == 0) {
                        Bukkit.broadcastMessage("DEBUG REMOVED Defenders");
                        teamsleft.remove("defenders");
                    } // END OF WORKING DEBUGS
    0 = Before the if's do not run:
    Code:
    Bukkit.broadcastMessage(String.valueOf(teamsleft.size()));
                    // START OF DEBUGS NOT RUNNING
    I'm thinking it's the last part '0' and I need to find out what is making it zero.
     
  6. Offline

    Zombie_Striker

    @VinexAx789
    I think your problem is that attackers/teamsleft/defenders does not contain anything. Have you every added anything to those collections?
     
  7. Offline

    VinexAx789

    @Zombie_Striker Yes I have.


    For an example I've done this for teamsleft.

    Code:
    if (plugin.attackers.size() > 0) {
                            if (!plugin.teamsleft.contains("attackers")) {
                                plugin.teamsleft.add("attackers");
                            }
                        }
                        if (plugin.defenders.size() > 0) {
                            if (!plugin.teamsleft.contains("defenders")) {
                                plugin.teamsleft.add("defenders");
                            }
                        }
    The thing is it all worked before so I must of done something to frig around with the if's.
     
  8. Offline

    Evonoucono

    @VinexAx789
    Your debugging messages state that teamsleft has a size of one before your delayed task counts 10 ticks
    Code:
    // RAN DEBUG = Working
            Bukkit.broadcastMessage(String.valueOf(teamsleft.size()));
            Bukkit.getScheduler().runTaskLater(this, new Runnable() {
                public void run() {
    and then inside that delayed task you have this:
    Code:
     if (attackers.size() == 0) {
                        Bukkit.broadcastMessage("DEBUG REMOVED Attackers");
                        teamsleft.remove("attackers");
                    }
                    if (defenders.size() == 0) {
                        Bukkit.broadcastMessage("DEBUG REMOVED Defenders");
                        teamsleft.remove("defenders");
                    }
    which removes values from teamsleft making it's size 0, does it not?
    Then your next if statement is:
    Code:
     // START OF DEBUGS NOT RUNNING
                    if (teamsleft.size() == 1) {
    which checks if the the size of teamsleft is 1, which it was until you removed "attackers" from it which was initially the only thing in the list of teamsleft.
    Check the value of teamsleft right before you remove "attackers" and then check it right after you remove it too.
     
  9. Offline

    VinexAx789

    @Evonoucono Still isn't working is there any other way I can do this? Would you like to see my starting timer? I just really need help fixing this thanks for trying.
     
  10. Offline

    Evonoucono

    @VinexAx789
    Showing as much code as possible makes it much easier to solve. From what you gave the problem is not very clear. After every single if statement (and I do mean everything) you should have a debugging message showing what the size of teamsleft is. From there you should be able to pinpoint the exact location teamsleft loses all of it's contents. If that does not work, post more of your code with a picture of the new debugging messages.
     
    VinexAx789 likes this.
Thread Status:
Not open for further replies.

Share This Page