Fix trial avatar removal

it is still *sort of* broken when combined with early leaving a domain
This commit is contained in:
KingRainbow44 2023-04-29 21:21:58 -04:00
parent b77c75a296
commit ed3186a2b2
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 15 additions and 7 deletions

View File

@ -64,7 +64,7 @@ public final class TeamManager extends BasePlayerDataManager {
public TeamManager() {
this.mpTeam = new TeamInfo();
this.avatars = new ArrayList<>();
this.avatars = Collections.synchronizedList(new ArrayList<>());
this.gadgets = new HashSet<>();
this.teamResonances = new IntOpenHashSet();
this.teamResonancesConfig = new IntOpenHashSet();
@ -551,10 +551,13 @@ public final class TeamManager extends BasePlayerDataManager {
scene, player.getAvatars().getAvatarById(avatarId)
)));
} else {
var index = 0;
// Restores all avatars from the player's avatar storage.
// If the avatar is already in the team, it will not be added.
for (var avatar : this.getCurrentTeamInfo().getAvatars()) {
// TODO: Fix order in which avatars are added.
// Currently, they are added from last to first.
var avatars = this.getCurrentTeamInfo().getAvatars();
for (var index = 0; index < avatars.size(); index++) {
var avatar = avatars.get(index);
if (this.getActiveTeam().stream()
.map(entity -> entity.getAvatar().getAvatarId())
.toList()
@ -564,10 +567,7 @@ public final class TeamManager extends BasePlayerDataManager {
var avatarData = player.getAvatars().getAvatarById(avatar);
if (avatarData == null) continue;
this.getActiveTeam()
.add(
index++,
new EntityAvatar(scene, avatarData));
this.getActiveTeam().add(index, new EntityAvatar(scene, avatarData));
}
}
@ -1091,6 +1091,10 @@ public final class TeamManager extends BasePlayerDataManager {
* @param trialAvatarIds List of trial avatar IDs.
*/
public void removeTrialAvatar(List<Integer> trialAvatarIds) {
// Check if the player is using a trial team.
if (!this.isUsingTrialTeam())
throw new IllegalStateException("Player is not using trial team.");
this.getPlayer()
.sendPacket(
new PacketAvatarDelNotify(

View File

@ -16,6 +16,10 @@ public class ExecRemoveTrialAvatar extends QuestExecHandler {
Grasscutter.getLogger()
.debug("Removed trial avatar from team for quest {}", quest.getSubQuestId());
return true;
} catch (IllegalStateException ignored) {
// The player does not have any trial avatars equipped.
Grasscutter.getLogger().warn("Attempted to remove trial avatars from player with none equipped.");
return true;
} catch (RuntimeException exception) {
exception.printStackTrace();
return false;