【发布时间】:2018-09-02 08:12:43
【问题描述】:
我正在开发一个 Bukkit / Spigotplugin,它允许用户为事物投票。 该插件使用配置。我想删除一个条目,但它不起作用。 我在 Google 上找到的:
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)
也不行。
我做错了什么?
【问题讨论】:
-
我相信你得到了你想要的配置和实际的配置错误。他们没有什么不同
标签: java plugins config bukkit