Problem/Bug Array out of bounds and something with world...

Discussion in 'Plugin Help/Development/Requests' started by Scorpionvssub, Sep 4, 2015.

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

    Scorpionvssub

    I made a multi chest storage system with alot of help from ruptur meaning, u can make multiple types of crates which each has its own key and own folder for their own type of reward system using commands like 30% pex user %player%..... and 70% give %speler% something.,..

    The issues i got atm is when i use the key on a chest it throws a massive array out of bounds usuallly with a -2147483648 behind it.

    Like:
    Code:
    [03-09 06:35:45 ] [Server] [Informatie] Caused by: java.lang.ArrayIndexOutOfBoundsException: -2147483648
    [03-09 06:35:45 ] [Server] [Informatie] at java.util.ArrayList.elementData(ArrayList.java:400) ~[?:1.7.0_65]
    [03-09 06:35:45 ] [Server] [Informatie] at java.util.ArrayList.get(ArrayList.java:413) ~[?:1.7.0_65]
    [03-09 06:35:45 ] [Server] [Informatie
    http://pastebin.com/Dxp5Pinm


    Stack trace: http://pastebin.com/ZS7xruKj *This stack is when i got several commands added into the crates file*

    Also on stop and start/reload it has some kind of world issue saying unknown world

    Code:
    [03-09 06:41:59 ] [Server] [Informatie] java.lang.IllegalArgumentException: unknown world
    [03-09 06:41:59 ] [Server] [Informatie] at org.bukkit.Location.deserialize(Location.java:595) ~[spigot1.8.7.jar:git-Spigot-6d16e64-09ddd9b]
    Stacktrace on loadup: http://pastebin.com/zX6vTHbd *Loading the plugin after a reload/stop/start

    Default on creation config (open)

    Code:
    chestname: DP
    key: DP's Key
    location:
      yaw: 0.0
      pitch: 0.0
      z: -613.0
      y: 34.0
      world: PrisonMines
      x: -329.0
    opened: 0
    Rewards:
    - 50% give %player% 57 1
    - 50% give %player% 133 1
    


    After adding several more commands (open)

    Code:
    chestname: DP
    key: DP's Key
    location:
      yaw: 0.0
      pitch: 0.0
      z: -613.0
      y: 34.0
      world: PrisonMines
      x: -329.0
    opened: 1
    Rewards:
    - 30% give %player% 57 1
    - 30% give %player% 133 1
    - 5% give %player% 278 1 fortune:15 efficiency:15 durability:1337 name:&f&l<&8&lCoal&f&l> Lore:&8Alright
    - 3% give %player% 278 1 fortune:20 efficiency:20 durability:1337 name:&f&l<&7&lIron&f&l> Lore:&7Good_Enough
    - 2% give %player% 278 1 fortune:25 efficiency:25 durability:1337 name:&f&l<&6&lGold&f&l> Lore:&6Getting_There
    - 5% give %player% 276 1 name:&f&l<&5&lPVPSword&f&l> lore:&5&lGood_Nuff
    - 5% give %player% 138 1
    - 5% give %player% 261 1 unbreaking:3 flame:1 punch:2 infinity:1 power:5 name:&e&lVoteBow Lore:Voting.
    - 5% crate key %player% DP 1
    - 5% give %player% 116 1
    - 5% give %player% 47 16


    after creating a chest loading server back up again. (open)

    Code:
            //noinspection ConstantConditions
            for (File file : getCrateFolder().listFiles()) {
                FileConfiguration crateconfig = YamlConfiguration.loadConfiguration(file);
                Location loc = Location.deserialize(crateconfig.getConfigurationSection("location").getValues(false));
                String name = crateconfig.getString("chestname");
                int open = crateconfig.getInt("opened");
                Crate crate = new Crate(name, loc);
                crate.setOpened(open);
                crates.put(name, crate);
            }
    


    Code:
            if (totalPercent < 100)
                totalPercent += (100 - totalPercent);
    
            genNumber = new Random().nextInt(totalPercent - 1);
            int n = 0;
            int timesLooped = 0;
    
            int lastPercent = 0;
    
            while (n <= genNumber) {
                if (timesLooped < listOfPercent.size()) {
    #line 365 ->                lastPercent = toList(listOfPercent.keySet()).get(timesLooped);
                    n = n + lastPercent;
                } else
                    lastPercent = -1;
    
                timesLooped++;
            }

     
  2. Offline

    Boomer

    Your error says its due to the index out of bounds at line 400... so why focus on the other lines that aren't that?
    What does your code look like that includes the error line at 400?
     
  3. Offline

    Scorpionvssub

    @Boomer
    400 is a } believe it or not :/ (open)

    Code:
        private void openCrate(Player whoOpened, Crate crateOpened) {
            FileConfiguration crateConfig = getCrateConfig(crateOpened.getName());
    
            if (crateConfig == null) return;
    
            List<String> rewards = crateConfig.getStringList("Rewards");
            Map<Integer, String> listOfPercent = new HashMap<>();
            int genNumber;
            int totalPercent = 0;
    
            if (rewards.size() == 0) return;
    
            for (String line : rewards) {
    
                String[] words = line.split(" ");
                String percent = words[0];
                int numPercent;
    
                if (!percent.contains("%")) continue;
    
                while (percent.endsWith("%")) {
    
                    percent = percent.substring(0, percent.length() - 1);
                }
    
                try {
                    numPercent = Integer.valueOf(percent);
                } catch (NumberFormatException e) {
                    getLogger().log(Level.WARNING, "Was unable to parse percent at line '" + line + "' in " + crateOpened.getName() + ".yml");
    
                    continue;
                }
    
    
                StringBuilder command = new StringBuilder();
    
                for (int i = 1; i < words.length; i++)
                    command.append(words[i]).append(" ");
    
    
                totalPercent += numPercent;
                listOfPercent.put(numPercent, command.substring(0, command.length() - 1));
    
            }
            if (totalPercent < 100)
                totalPercent += (100 - totalPercent);
    
            genNumber = new Random().nextInt(totalPercent - 1);
            int n = 0;
            int timesLooped = 0;
    
            int lastPercent = 0;
    
            while (n <= genNumber) {
                if (timesLooped < listOfPercent.size()) {
                    lastPercent = toList(listOfPercent.keySet()).get(timesLooped);
                    n = n + lastPercent;
                } else
                    lastPercent = -1;
    
                timesLooped++;
            }
    
            if (lastPercent != -1) {
    
    
                String command = listOfPercent.get(lastPercent);
                getServer().dispatchCommand(getServer().getConsoleSender(), command.replaceAll("%player%", whoOpened.getName()));
            }
    
            crateOpened.setOpened(crateOpened.getOpened() + 1);
        }
    
        private FileConfiguration getCrateConfig(String name) {
            File cFile = new File(getCrateFolder(), name + ".yml");
    
            return cFile.exists() ? YamlConfiguration.loadConfiguration(cFile) : null;
        }
    
        private <T> List<T> toList(Set<T> set) {
    
    
            List<T> list = new ArrayList<>();
    
            for (T x : set) {
                list.add(x);
                System.out.println(x);
            }
            System.out.println(list);
            return list;
        } <------------ this is line 400
     
  4. Offline

    Boomer

    Yeah, actually that was my mistake, thats the line 400 in the java library.
    Your own error message wasn't complete enough to identify where the error is. Can you please post the entire, full error.
     
  5. Offline

    Scorpionvssub

    @Boomer Stack trace: http://pastebin.com/ZS7xruKj *This stack is when i got several commands added into the crates file* Line 365
    lastPercent = toList(listOfPercent.keySet()).get(timesLooped);
     
  6. Offline

    Scorpionvssub

    Fixed that and now im stuck on 1 issue, that isnt the biggest burden but...still confuses me, the plugin works 100% in a world named world...but not in worlds called prisonmines or something like that
     
Thread Status:
Not open for further replies.

Share This Page