Skip to content

Commit

Permalink
Removed ServerAuthorizer.java in favor of better system WhitelistBotC…
Browse files Browse the repository at this point in the history
…ommand which allows me to control what servers my bot are allowed in
  • Loading branch information
RealMangorage committed Sep 12, 2024
1 parent f12c11d commit 4520c9f
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.mangorage.mangobotapi.core.data.DataHandler;
import org.mangorage.mangobotapi.core.data.IEmptyFileNameResolver;
import org.mangorage.mangobotapi.core.plugin.api.CorePlugin;
import java.util.Collections;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -20,7 +20,7 @@ public class WhitelistBotCommand implements IBasicCommand {
private static final List<String> ALLOWED_USERS = List.of(
"194596094200643584"
);
private record SaveData(Set<String> serverIds, boolean whiteliston) implements IEmptyFileNameResolver {}
private record SaveData(HashSet<String> serverIds, boolean whiteliston) implements IEmptyFileNameResolver {}

private static final DataHandler<SaveData> WHITELIST_DATA = DataHandler.create()
.path("data/serverwl/data")
Expand Down Expand Up @@ -66,7 +66,7 @@ public CommandResult execute(Message message, Arguments arguments) {
if (arguments.hasArg("toggle")) {
whitelistOn = !whitelistOn;
message.reply("Set Server Whitelist to " + (whitelistOn ? "On" : "Off")).queue();
WHITELIST_DATA.save(plugin.getPluginDirectory(), new SaveData(SERVERS, whitelistOn));
WHITELIST_DATA.save(plugin.getPluginDirectory(), new SaveData(new HashSet<>(SERVERS), whitelistOn));
if (whitelistOn) runTask();
} else if (arguments.hasArg("add")) {
handle(true, arguments.findArg("add"), message);
Expand Down Expand Up @@ -102,7 +102,7 @@ private void handle(boolean add, String id, Message message) {
SERVERS.remove(id);
}

WHITELIST_DATA.save(plugin.getPluginDirectory(), new SaveData(SERVERS, whitelistOn));
WHITELIST_DATA.save(plugin.getPluginDirectory(), new SaveData(new HashSet<>(SERVERS), whitelistOn));
}

@Override
Expand Down

0 comments on commit 4520c9f

Please sign in to comment.