Solved While loop causing server to crash

Discussion in 'Plugin Development' started by kameronn, Aug 22, 2016.

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

    kameronn

    Oddly, my while loop is causing the server to crash. This hasnt been a problem since I've made this system but now when I run the command (the command that triggers the while loop) my server stops responding and crashes, the error points to the while loop. Also, the ItemReader class it a class that converts a config string list to a item with custom stuff I need for my plugin

    Error:
    http://pastebin.com/qESj7FFv (too long to put into a thread)
    Code:
    Code:
        public static ItemReader gettingItemStack() {
    
    
            boolean chosen = false; 
           
            Random random = new Random();
            double luck = 100.0;
            while (!chosen) // line 114
                for (String prizestring : prizes) {
    
                    ItemReader ir = new ItemReader(prizestring);
                    luck = (random.nextDouble()) * 700;
                    if (luck <= ir.getPercentage()) {
                        chosen = true;
                        is = ir;
    
                    }
    
                }
            return is;
        }
     
  2. Offline

    PhantomUnicorns

    Am not seeing the class ItemReader, is this Spigot/bukkit/or what ever you use or is it a variable you made. If so can you please post it. This is because the percentage of ir is more then 700 (approximately) I also don't see a variable called is
     
  3. Offline

    kameronn

    Well its not bukkit or spigot and the variable called is, is a public ItemReader. I dont want to post the full itemreader class since its a personal api, but it converts a string list in a config to use in code. For example,

    Material:Gold_Block Name:&cName_Here
    itemreader.toItem();
    Then it would make a gold block with the name given in the config.

    Code:
        public double getPercentage() {
            if (itemString.contains("Percent:")) {
                for (String s : itemString.split(" ")) {
                    if (s.contains("Percent:")) {
                        s = s.replace("Percent:", "");
                        return Double.parseDouble(s);
                    }
                }
            }
            return 100;
        }
    I know the this part is working because the system had been working before it randomly started causing errors at the while loop
     
  4. Offline

    PhantomUnicorns

    It is possible that that is returning 0 which means it will never even be lower then zero, since I don't have the full code could you please send the console or yourself a message right before it test the percentage and have it send you the percentage.
     
Thread Status:
Not open for further replies.

Share This Page