mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-09 03:42:57 +08:00
Fix Mail SendToAll Freeze (#1913)
* Avoid iterating over every offline player * getAllPlayers by stream * Use the new method without changing the old signature * Annotate deprecated `getAllPlayers`
This commit is contained in:
parent
855d3182ab
commit
47911aa16e
@ -9,6 +9,7 @@ import emu.grasscutter.game.player.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
@ -78,9 +79,10 @@ public final class SendMailCommand implements CommandHandler {
|
||||
Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail);
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.send_done", mailBuilder.recipient));
|
||||
} else {
|
||||
for (Player player : DatabaseHelper.getAllPlayers()) {
|
||||
Grasscutter.getGameServer().getPlayerByUid(player.getUid(), true).sendMail(mailBuilder.mail);
|
||||
}
|
||||
DatabaseHelper.getByGameClass(Player.class).forEach(player -> {
|
||||
var onlinePlayer = Grasscutter.getGameServer().getPlayerByUid(player.getUid(), false);
|
||||
Objects.requireNonNullElse(onlinePlayer, player).sendMail(mailBuilder.mail);
|
||||
});
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.send_all_done"));
|
||||
}
|
||||
mailBeingConstructed.remove(senderId);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package emu.grasscutter.database;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.mongodb.client.result.DeleteResult;
|
||||
|
||||
@ -154,6 +155,11 @@ public final class DatabaseHelper {
|
||||
DatabaseManager.getAccountDatastore().find(Account.class).filter(Filters.eq("id", target.getId())).delete();
|
||||
}
|
||||
|
||||
public static <T> Stream<T> getByGameClass(Class<T> classType) {
|
||||
return DatabaseManager.getGameDatastore().find(classType).stream();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public static List<Player> getAllPlayers() {
|
||||
return DatabaseManager.getGameDatastore().find(Player.class).stream().toList();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user