我正在开发一个 Bukkit / Spigotplugin,它允许用户对事物进行投票。该插件使用配置。我想删除一个条目,但它不起作用。我在谷歌上发现的:
getConfig().set("your.value", null);
我实施的:
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);
配置的外观:
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
当我使用“/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
它看起来如何:
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
使用
getConfig().getConfigurationSection("ThingsYouCanVoteFor").getKeys(false).remove(i + 1)
也不起作用。
我做错了什么?
德玛西亚99
慕神8447489
相关分类