I'm working on a Bukkit / Spigotplugin which allows users to vote for things. The plugin uses a config. I want to remove an entry but it doesn't work. What I found on Google:
getConfig().set("your.value", null);
what I implemented:
int i = id;
while(getConfig().contains("ThingsYouCanVoteFor." + (i + 1)))
{
getConfig().set("ThingsYouCanVoteFor." + Integer.toString(i) + ".name", getConfig().getString("ThingsYouCanVoteFor." + Integer.toString(i + 1) + ".name"));
getConfig().set("ThingsYouCanVoteFor." + Integer.toString(i) + ".votes", getConfig().getInt("ThingsYouCanVoteFor." + Integer.toString(i + 1) + ".votes"));
i++;
}
getConfig().set("ThingsYouCanVoteFor." + Integer.toString(i + 1), null);
saveConfig();
sender.sendMessage("§aRemoved ID " + id);
how the config looks:
ThingsYouCanVoteFor:
0:
name: Build a bridge
votes: 0
1:
name: Kill the owner
votes: 2
2:
name: Vote for something other
votes: 1
3:
name: Remove all banned peoples inventory
votes: 0
4:
name: Teleport to others home
votes: 0
5:
name: Dig a hole in the air
votes: 0
6:
name: Shutdown the internet
votes: 0
PeopleWhoVoted:
- Gamingwelle
- BDevGWAdmin
- Sllikson
OpenForVoting: false
how it should look like when I use "/voteadmin remove 3":
ThingsYouCanVoteFor:
0:
name: Build a bridge
votes: 0
1:
name: Kill the owner
votes: 2
2:
name: Vote for something other
votes: 1
3:
name: Teleport to others home
votes: 0
4:
name: Dig a hole in the air
votes: 0
5:
name: Shutdown the internet
votes: 0
PeopleWhoVoted:
- Gamingwelle
- BDevGWAdmin
- Sllikson
OpenForVoting: false
how it looks:
ThingsYouCanVoteFor:
0:
name: Build a bridge
votes: 0
1:
name: Kill the owner
votes: 2
2:
name: Vote for something other
votes: 1
3:
name: Teleport to others home
votes: 0
4:
name: Dig a hole in the air
votes: 0
5:
name: Shutdown the internet
votes: 0
6:
name: Shutdown the internet
votes: 0
PeopleWhoVoted:
- Gamingwelle
- BDevGWAdmin
- Sllikson
OpenForVoting: false
using
getConfig().getConfigurationSection("ThingsYouCanVoteFor").getKeys(false).remove(i + 1)
doesn't work either.
What did I do wrong?
You can simply remove the value in a path using:
config.set(pathToRemove, null);