Reputation: 21
How can I limit a boolean to one server?
If I use a normal boolean to create a command that can be disabled: Boolean b = true
and make it changeable with a text command:
if (event.getMessage().getContentStripped().equalsIgnoreCase("message")) {
if (event.getMember().getPermissions().contains(Permission.ADMINISTRATOR)) {
if (b) {
b = false;
event.getChannel().sendMessage("Successfully disabled the command.").queue();
} else if (!b) {
event.getChannel().sendMessage("The command is already disabled.").queue();
}
it gets disabled/enabled for all servers the bot is in. I want people to only disable it for their own server though. How can I do this?
Sry if it's easy. I haven't found anything on Google. I'm not so experienced with coding yet. I'm here to learn :)
Upvotes: 0
Views: 43
Reputation: 6131
To keep track of state per-guild you can use a map datastructure, with the guild's ID as key.
private final Map<Long, Boolean> map = new HashMap<>();
You can then store the boolean using map.put(guild.getIdLong(), false)
and later load using map.get(guild.getIdLong())
. Note however, that this will not persist between program restarts, since it is only stored in memory. To persist this state, you have to use a database, such as SQLite or similar.
Upvotes: 1