Commit c65443f4 authored by Melledy's avatar Melledy
Browse files

Fix permissions not saving

parent 057f568a
...@@ -138,7 +138,7 @@ public final class ServerCommands { ...@@ -138,7 +138,7 @@ public final class ServerCommands {
String username = args.get(1); String username = args.get(1);
String permission = args.get(2); String permission = args.get(2);
Account account = DatabaseHelper.getAccountByName(username); Account account = Grasscutter.getGameServer().getAccountByName(username);
if(account == null) { if(account == null) {
CommandHandler.sendMessage(null, "Account not found."); return; CommandHandler.sendMessage(null, "Account not found."); return;
} }
...@@ -146,18 +146,20 @@ public final class ServerCommands { ...@@ -146,18 +146,20 @@ public final class ServerCommands {
switch(action) { switch(action) {
default: default:
CommandHandler.sendMessage(null, "Usage: permission <add|remove> <username> <permission>"); CommandHandler.sendMessage(null, "Usage: permission <add|remove> <username> <permission>");
return; break;
case "add": case "add":
if(account.addPermission(permission)) { if(account.addPermission(permission)) {
CommandHandler.sendMessage(null, "Permission added."); return; CommandHandler.sendMessage(null, "Permission added.");
} else CommandHandler.sendMessage(null, "They already have this permission!"); } else CommandHandler.sendMessage(null, "They already have this permission!");
return; break;
case "remove": case "remove":
if(account.removePermission(permission)) { 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!"); } else CommandHandler.sendMessage(null, "They don't have this permission!");
return; break;
} }
account.save();
} }
} }
......
...@@ -9,6 +9,7 @@ import emu.grasscutter.utils.Crypto; ...@@ -9,6 +9,7 @@ import emu.grasscutter.utils.Crypto;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import dev.morphia.annotations.IndexOptions; import dev.morphia.annotations.IndexOptions;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Entity(value = "accounts", noClassnameStored = true) @Entity(value = "accounts", noClassnameStored = true)
...@@ -28,7 +29,9 @@ public class Account { ...@@ -28,7 +29,9 @@ public class Account {
private List<String> permissions; private List<String> permissions;
@Deprecated @Deprecated
public Account() {} public Account() {
this.permissions = new ArrayList<>();
}
public String getId() { public String getId() {
return id; return id;
......
...@@ -8,6 +8,7 @@ import emu.grasscutter.GenshinConstants; ...@@ -8,6 +8,7 @@ import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.commands.CommandMap; import emu.grasscutter.commands.CommandMap;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.dungeons.DungeonManager; import emu.grasscutter.game.dungeons.DungeonManager;
import emu.grasscutter.game.gacha.GachaManager; import emu.grasscutter.game.gacha.GachaManager;
...@@ -138,6 +139,14 @@ public final class GameServer extends MihoyoKcpServer { ...@@ -138,6 +139,14 @@ public final class GameServer extends MihoyoKcpServer {
return player.getSocialDetail(); 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 { public void onTick() throws Exception {
for (GenshinPlayer player : this.getPlayers().values()) { for (GenshinPlayer player : this.getPlayers().values()) {
player.onTick(); player.onTick();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment