Solved For loop acting as return + Record end detection

Discussion in 'Spigot Plugin Development' started by SmokingIsBadMkay, May 5, 2017.

Thread Status:
Not open for further replies.
  1. Hi, so in the past 2 days I had a really strange problem where some of my for loops (which always worked fine) started acting like a return. All code that comes after it wasn't being executed. I fixed it by re-ordering my code but I'm really curious if there is a logical explanation for this. This was one of the two loops which was doing this.
    Code (Text):

                for(MurderPlayer mp : this.players.values()) {
                    mp.getPlayer().getInventory().clear();
                    mp.getPlayer().sendMessage(ChatColor.RED + murderer + ChatColor.YELLOW + " has ran out of time! The " + ChatColor.WHITE + "Innocents" + ChatColor.YELLOW + " win the match!");
                    PacketHelper.sendTitle(mp.getPlayer(), ChatColor.RED + "" + ChatColor.BOLD + "GAME OVER", ChatColor.YELLOW + "The" + ChatColor.WHITE +" Innocents "+ChatColor.YELLOW+" have won the game!", 100, 40);
                    mp.getPlayer().playSound(mp.getPlayer().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 1F);
                 
                    if(mp.role == Role.MURDERER) {
                        makeInspector(mp);
                    }
                }
     
    Another question I have is how do I detect it when a Record being played ends? I'm using this:
    Code (Text):
    player.playEffect(player.getLocation(), Effect.RECORD_PLAY, this.getSong());
    to play records for players in my waiting lobby and I would like to start the next song after the current one ends.

    Thank you!
     
  2. You need to post the full class / method (preferably the old one), since this doesn't even return early.
     
  3. I would if I was still having this problem, but I'm not going to post my whole custom Murder game class, I will just leave it be.

    Any idea how to detect it when a record ends?
     
  4. It's not possible since the music can be changed with resource packs. The only way I can see it working is to force them to download a resourcepack with the default music and then find the length of the songs manually by looking at the sound files.
     
  5. Choco

    Moderator

    You have your entire game in a single class? ._. That's generally a bad idea and an indication that you have a really poor design
     
    • Agree Agree x 1
  6. Obviously not.
     
  7. Was thinking about that, its probably the best solution. Thanks.
     
Thread Status:
Not open for further replies.