Help with ArrayList , .contains will not work

Discussion in 'Plugin Development' started by Eistee², Aug 6, 2012.

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

    Eistee²

    Hello ,
    Currently I rewrite my plugin and now I have a problem.

    I need to check if the breaked / placed block is in the config.
    It read the file and split them into an ArrayLists (expBreak, expPlace, expSlainEntity) this works without problems, now I want to check if the breaked block is in my config (I break a Dirt block) and check if he is in my Config with expBreak.contains("ItemID;"+id) and it says it dosent exist but with expBreak.get(2) it return "ItemID;DIRT:10:1"

    Can some one helpe me? it worked in my old version :/

    Block Break event:
    Code:
        private void PlayerBlockBreak(BlockBreakEvent event)
        {
            int blockID = event.getBlock().getTypeId();
            String blockName = event.getBlock().getType().toString();
            String blockInfo = info.checkID(1, blockID, blockName);
            System.out.println(blockInfo);
        }

    ID Check:
    (And it choose the right Case)
    Code:
        public String checkID(int which,int id,String name)
        {
            switch(which)
            {
            case 1:
                if(expBreak.contains("ItemID;"+id))
                {
                    return expBreak.get(expBreak.indexOf("ItemID;"+id));
                }else if(expBreak.contains("ItemID;"+name))
                {           
                    return expBreak.get(expBreak.indexOf("ItemID;"+name));
                }
            case 2:
                if(expPlace.contains("ItemID;"+id))
                {
                    return expPlace.get(expPlace.indexOf("ItemID;"+id));
                }else if(expPlace.contains("ItemID;"+name))
                {
                    return expPlace.get(expPlace.indexOf("ItemID;"+name));
                }
            case 3:
                if(expSlainEntity.contains("ItemID;"+id))
                {
                    return expSlainEntity.get(expSlainEntity.indexOf("ItemID;"+id));
                }else if(expSlainEntity.contains("ItemID;"+name))
                {
                    return expSlainEntity.get(expSlainEntity.indexOf("ItemID;"+name));
                }
            case 4:
                if(expFish.contains("ItemID;"+id))
                {
                    return expFish;
                }else if(expFish.contains("ItemID;"+name))
                {
                    return expFish;
                }
            case 5:
                if(expRandoms.contains(name))
                {
                    return expRandoms.get(expRandoms.indexOf(name));
                }
            }
           
            return null;
        }

    Here I split the config

    Code:
        private    String maxLvl = "";
        private    Boolean useLvl = false;
       
       
        private    ArrayList<String> expLevels = new ArrayList<String>();
       
        private    ArrayList<String> expRandoms = new ArrayList<String>();
        private    ArrayList<String> expBreak = new ArrayList<String>();
        private    ArrayList<String> expPlace = new ArrayList<String>();
        private    ArrayList<String> expSlainEntity = new ArrayList<String>();
        private    String expFish = "";
       
        //Reads the Exp Config and split it into an ArrayList
        private void ReadExpConfig()
        {
            String ExpContent = ExpConfig.fileGetContent();
            String[] ExpContentSplit = ExpContent.split("\n");
           
            for(int x = 0; x < ExpContentSplit.length; x++)
            {
               
                if(ExpContentSplit[x].equalsIgnoreCase("Levels:"))
                {
                    x += 2;
                    for(int levels = x;levels < ExpContentSplit.length; levels++)
                    {
                        if(ExpContentSplit[levels].equalsIgnoreCase("Randoms:"))
                        {
                            x = levels;
                            break;
                        }
                        if(ExpContentSplit[levels].equalsIgnoreCase("Use Level:true"))
                        {
                            useLvl = true;
                        }
                        else if(ExpContentSplit[levels].contains("MAXlvl:"))
                        {
                            maxLvl = ExpContentSplit[levels];
                        }
                        else
                        {
                            expLevels.add(ExpContentSplit[levels]);
                        }
                    }
                }
                if(ExpContentSplit[x].equalsIgnoreCase("Randoms:"))
                {
                    x += 2;
                    for(int randoms = x; randoms < ExpContentSplit.length; randoms++)
                    {
                        if(ExpContentSplit[randoms].equalsIgnoreCase("Break BLock:"))
                        {
                            x = randoms;
                            break;
                        }
                        expRandoms.add(ExpContentSplit[randoms]);                   
                    }
                }
                   
                if(ExpContentSplit[x].equalsIgnoreCase("Break Block:"))
                {
                    x+=2;
                    for(int breakBlock = x; breakBlock < ExpContentSplit.length; breakBlock++)
                    {
                        if(ExpContentSplit[breakBlock].equalsIgnoreCase("Place Block:"))
                        {
                            x = breakBlock;
                            break;
                        }
                        expBreak.add(ExpContentSplit[breakBlock]);
                    }
                }
           
                if(ExpContentSplit[x].equalsIgnoreCase("Place Block:"))
                {
                    x+=2;
                    for(int placeBlock = x; placeBlock < ExpContentSplit.length; placeBlock++)
                    {
                        if(ExpContentSplit[placeBlock].equalsIgnoreCase("Slain Mobs:"))
                        {
                            x = placeBlock;
                            break;
                        }
                        expPlace.add(ExpContentSplit[placeBlock]);
                    }
                }
               
                if(ExpContentSplit[x].equalsIgnoreCase("Slain Mobs:"))
                {
                    x+=2;
                    for(int slain = x; slain < ExpContentSplit.length; slain++)
                    {
                        if(ExpContentSplit[slain].equalsIgnoreCase("Fishing:"))
                        {
                            x = slain;
                            break;
                        }
                        expSlainEntity.add(ExpContentSplit[slain]);
                    }
                }   
                if(ExpContentSplit[x].equalsIgnoreCase("Fishing:"))
                {
                    x+=2;
                    for(int slain = x; slain < ExpContentSplit.length; slain++)
                    {
                        expFish = ExpContentSplit[slain];
                    }
                }
               
            }
        }
    


    Eistee² sorry for my bad english
     
  2. Offline

    Courier

    "id" is an int. You are checking a list of Strings formatted like "ItemID;DIRT:10:1" for a String formatted like "ItemID;3"
     
  3. Offline

    Eistee²

    I check the ids and the names :p

    Code:
        if(expBreak.contains("ItemID;"+id))
                {
                    return expBreak.get(expBreak.indexOf("ItemID;"+id));
                }else if(expBreak.contains("ItemID;"+name))
                {       
                    return expBreak.get(expBreak.indexOf("ItemID;"+name));
                }
    and it dosent work to with the ids too.... tested with stone("ItemID;1:10:10") and nothing :(
     
  4. Offline

    pzxc

    Contains checks for an exact match. ItemID;DIRT is not the same as ItemID;DIRT:10:1
     
  5. Offline

    Eistee²

    Thank you for this post :D now I know what I have done wrong :3 but is it possible to do this with out split everything again?
     
  6. Offline

    pzxc

    for (String x : expBreak) {
    if (x.indexOf("ItemID;"+name) > -1 || x.indexOf("ItemID;"+id) > -1) {
    doSomething();
    }
    }
     
    Eistee² likes this.
  7. Offline

    Eistee²

    Thank you ! :)
     
Thread Status:
Not open for further replies.

Share This Page