How to delete a single value of an List<String> (Config)?

Discussion in 'Plugin Development' started by RoflFrankoc, Dec 1, 2015.

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

    RoflFrankoc

    I want to remove only 1 value where it says
    Code:
    RoflFrankoc:12:DIAMOND_BLOCK:14:false"
    I have already tried this:
    Code:
      public static void remove(Player p, ItemStack item, int amount){
         List<String> s = new ArrayList<String>();
         s.addAll(config.getStringList("items"));
         int found=0;
         String whole = "";
         for (int i=0;i<s.size();i++){
           String[] a = s.get(i).split(":");
           Player pa = Bukkit.getPlayer(a[0]);
           ItemStack sa = new ItemStack(Material.getMaterial(a[2]));
           int ia = Integer.parseInt(a[3]);
           if (pa == p && item == sa && amount == ia){
             found = i;
             whole = s.get(i);
             break;
           }
         }
         if (found==0){
           return;
         }
         s.remove(found);
         s.remove(whole);
         config.set("items", "");
         config.set("items", s);
       }
    
     
  2. Offline

    Zombie_Striker

    What does this currently do? What does your expectation of what it should produce look like.
     
  3. Offline

    FabeGabeMC

  4. Offline

    RoflFrankoc

    @FabeGabeMC yes i did
    @Zombie_Striker This is gets a string list out of the config and deletes one this is used when a player clicks on that item in an inventory and buys the item
     
  5. Offline

    FabeGabeMC

    @RoflFrankoc
    Doesn't look like you did.
     
  6. Offline

    Zombie_Striker

    @RoflFrankoc
    Can you print out what "whole" is? Can you print out what the string you're looking for is? Can you tell us if they are EXACTLY the same? I don't know if you can remove an item by index.
     
  7. Offline

    Scimiguy

    ArrayList has a remove(int index) method, yes
     
  8. Offline

    RoflFrankoc

    @FabeGabeMC I saved it after i used the function
    @Zombie_Striker Im looking for this item:
    Code:
    RoflFrankoc:12:DIAMOND_BLOCK:14:false
    and the whole config is:
    Code:
    RoflFrankoc:12:DIAMOND_BLOCK:14:false
    RoflFrankoc:64:REDSTONE_LAMP:12:false
    
    @Scimiguy does not work though
     
  9. Offline

    FabeGabeMC

    @RoflFrankoc
    I suggest you should save it inside the method.
     
  10. Offline

    RoflFrankoc

  11. Offline

    Scimiguy

    Then post your new code so we can see why it doesn't work
     
Thread Status:
Not open for further replies.

Share This Page