mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-18 01:46:44 +01:00
Fix double adding of avatar entities
This commit is contained in:
@@ -9,7 +9,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class TeamInfo {
|
||||
public final class TeamInfo {
|
||||
private String name;
|
||||
private final List<Integer> avatars;
|
||||
|
||||
|
||||
@@ -131,6 +131,30 @@ public final class TeamManager extends BasePlayerDataManager {
|
||||
return avatars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the active team.
|
||||
* If there are errors with the team, they can be fixed.
|
||||
*
|
||||
* @param fix If true, the team will be fixed.
|
||||
* @return The active team.
|
||||
*/
|
||||
public List<EntityAvatar> getActiveTeam(boolean fix) {
|
||||
if (!fix) return this.getActiveTeam();
|
||||
|
||||
// Remove duplicate avatars.
|
||||
var avatars = this.getActiveTeam();
|
||||
var avatarIds = new HashSet<Long>();
|
||||
for (var entityAvatar : new ArrayList<>(avatars)) {
|
||||
if (avatarIds.contains(entityAvatar.getAvatar().getGuid())) {
|
||||
avatars.remove(entityAvatar);
|
||||
} else {
|
||||
avatarIds.add(entityAvatar.getAvatar().getGuid());
|
||||
}
|
||||
}
|
||||
|
||||
return avatars; // Return the fixed team.
|
||||
}
|
||||
|
||||
public EntityAvatar getCurrentAvatarEntity() {
|
||||
if (this.currentCharacterIndex >= this.getActiveTeam().size()) {
|
||||
this.currentCharacterIndex = 0; // Reset to the first character.
|
||||
@@ -557,8 +581,6 @@ public final class TeamManager extends BasePlayerDataManager {
|
||||
} else {
|
||||
// Restores all avatars from the player's avatar storage.
|
||||
// If the avatar is already in the team, it will not be added.
|
||||
// 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);
|
||||
@@ -804,7 +826,7 @@ public final class TeamManager extends BasePlayerDataManager {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
player
|
||||
this.getPlayer()
|
||||
.getStaminaManager()
|
||||
.stopSustainedStaminaHandler(); // prevent drowning immediately after respawn
|
||||
|
||||
@@ -813,7 +835,7 @@ public final class TeamManager extends BasePlayerDataManager {
|
||||
entity.setFightProperty(
|
||||
FightProperty.FIGHT_PROP_CUR_HP,
|
||||
entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) * .4f);
|
||||
player.getSatiationManager().removeSatiationDirectly(entity.getAvatar(), 15000);
|
||||
this.getPlayer().getSatiationManager().removeSatiationDirectly(entity.getAvatar(), 15000);
|
||||
this.getPlayer()
|
||||
.sendPacket(
|
||||
new PacketAvatarFightPropUpdateNotify(
|
||||
@@ -829,10 +851,10 @@ public final class TeamManager extends BasePlayerDataManager {
|
||||
this.getPlayer(),
|
||||
EnterType.ENTER_TYPE_SELF,
|
||||
EnterReason.Revival,
|
||||
player.getSceneId(),
|
||||
getRespawnPosition()));
|
||||
player.getPosition().set(getRespawnPosition());
|
||||
} catch (Exception e) {
|
||||
this.getPlayer().getSceneId(),
|
||||
this.getRespawnPosition()));
|
||||
this.getPlayer().getPosition().set(this.getRespawnPosition());
|
||||
} catch (Exception ignored) {
|
||||
this.getPlayer()
|
||||
.sendPacket(
|
||||
new PacketPlayerEnterSceneNotify(
|
||||
@@ -841,7 +863,7 @@ public final class TeamManager extends BasePlayerDataManager {
|
||||
EnterReason.Revival,
|
||||
3,
|
||||
GameConstants.START_POSITION));
|
||||
player
|
||||
this.getPlayer()
|
||||
.getPosition()
|
||||
.set(GameConstants.START_POSITION); // If something goes wrong, the resurrection is here
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import emu.grasscutter.net.proto.SceneTeamAvatarOuterClass.SceneTeamAvatar;
|
||||
import emu.grasscutter.net.proto.SceneTeamUpdateNotifyOuterClass.SceneTeamUpdateNotify;
|
||||
|
||||
public class PacketSceneTeamUpdateNotify extends BasePacket {
|
||||
|
||||
public PacketSceneTeamUpdateNotify(Player player) {
|
||||
super(PacketOpcodes.SceneTeamUpdateNotify);
|
||||
|
||||
@@ -16,7 +15,7 @@ public class PacketSceneTeamUpdateNotify extends BasePacket {
|
||||
.setIsInMp(player.getWorld().isMultiplayer());
|
||||
|
||||
for (var p : player.getWorld().getPlayers()) {
|
||||
for (var entityAvatar : p.getTeamManager().getActiveTeam()) {
|
||||
for (var entityAvatar : p.getTeamManager().getActiveTeam(true)) {
|
||||
var avatarProto =
|
||||
SceneTeamAvatar.newBuilder()
|
||||
.setPlayerUid(p.getUid())
|
||||
|
||||
Reference in New Issue
Block a user