Fix permissions not saving

This commit is contained in:
Melledy 2022-04-18 21:38:19 -07:00
parent 057f568a37
commit c65443f422
3 changed files with 21 additions and 7 deletions

View File

@ -138,7 +138,7 @@ public final class ServerCommands {
String username = args.get(1);
String permission = args.get(2);
Account account = DatabaseHelper.getAccountByName(username);
Account account = Grasscutter.getGameServer().getAccountByName(username);
if(account == null) {
CommandHandler.sendMessage(null, "Account not found."); return;
}
@ -146,18 +146,20 @@ public final class ServerCommands {
switch(action) {
default:
CommandHandler.sendMessage(null, "Usage: permission <add|remove> <username> <permission>");
return;
break;
case "add":
if(account.addPermission(permission)) {
CommandHandler.sendMessage(null, "Permission added."); return;
CommandHandler.sendMessage(null, "Permission added.");
} else CommandHandler.sendMessage(null, "They already have this permission!");
return;
break;
case "remove":
if(account.removePermission(permission)) {
CommandHandler.sendMessage(null, "Permission removed."); return;
CommandHandler.sendMessage(null, "Permission removed.");
} else CommandHandler.sendMessage(null, "They don't have this permission!");
return;
break;
}
account.save();
}
}

View File

@ -9,6 +9,7 @@ import emu.grasscutter.utils.Crypto;
import emu.grasscutter.utils.Utils;
import dev.morphia.annotations.IndexOptions;
import java.util.ArrayList;
import java.util.List;
@Entity(value = "accounts", noClassnameStored = true)
@ -28,7 +29,9 @@ public class Account {
private List<String> permissions;
@Deprecated
public Account() {}
public Account() {
this.permissions = new ArrayList<>();
}
public String getId() {
return id;

View File

@ -8,6 +8,7 @@ import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.commands.CommandMap;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.dungeons.DungeonManager;
import emu.grasscutter.game.gacha.GachaManager;
@ -138,6 +139,14 @@ public final class GameServer extends MihoyoKcpServer {
return player.getSocialDetail();
}
public Account getAccountByName(String username) {
Optional<GenshinPlayer> playerOpt = getPlayers().values().stream().filter(player -> player.getAccount().getUsername().equals(username)).findFirst();
if (playerOpt.get() != null) {
return playerOpt.get().getAccount();
}
return DatabaseHelper.getAccountByName(username);
}
public void onTick() throws Exception {
for (GenshinPlayer player : this.getPlayers().values()) {
player.onTick();