Solved Removing value from config list

Discussion in 'Plugin Development' started by MasterDoctor, Nov 1, 2015.

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

    MasterDoctor

    Code:
    @EventHandler
        public void blockBreak(BlockBreakEvent event){
            if(event.getBlock().getType() == Material.CHEST){
                event.getPlayer().sendMessage("BROKEN CHEST");
                List<String> locationList = plugin.getConfig().getStringList("chest-data.locations");
                Location location = event.getBlock().getLocation();
                String locationString = location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ();
                event.getPlayer().sendMessage("PRE LOCATIONLIST DATA");
                if(locationList.contains(locationString)){
                    event.getPlayer().sendMessage(locationList.toString());
                    event.getPlayer().sendMessage(locationString);
                    event.getPlayer().sendMessage(locationList.toString());
                    locationList.remove(locationString);
                    event.getPlayer().sendMessage("LOCATIONSTRING REMOVED");
                }
              
              
            }
    [​IMG]

    Yeah, When I run this code, you can see in the game, it even says "LOCATIONSTRING REMOVED" but as you can also see it is not removed.

    EDIT: BEFORE IT WAS JUST 7 LINES, NOW IT IS 8 LINES.
    A VALUE IS ADDED TO THE HASHMAP WHEN A CHEST IS PLACED.
     
  2. Offline

    SuperSniper

    @MasterDoctor It's because you're sending the message of the strings before it's actually removed, so it's still inside of the list. You need to put the line of code

    Code:
     locationList.remove(locationString);
    
    before

    Code:
     
    event.getPlayer().sendMessage(locationList.toString());
                    event.getPlayer().sendMessage(locationString);
                    event.getPlayer().sendMessage(locationList.toString());
    
     
  3. Offline

    MasterDoctor

    I didn't even see that! lol :p But I check the config and it still isn't there
    BRAIN DERP: I forgot to
    Code:
    plugin.getConfig().set("chest-data.locations", locationList);
    plugin.saveConfig();
     
Thread Status:
Not open for further replies.

Share This Page