修复玩家数据同步问题
This commit is contained in:
parent
9ce26b0cb9
commit
505943621c
1 changed files with 27 additions and 0 deletions
|
@ -52,11 +52,38 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
|
|||
PacketDistributor.sendToPlayer(player, new PlayerVariablesSyncMessage(player.getId(), player.getData(ModAttachments.PLAYER_VARIABLE).compareAndUpdate()));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
|
||||
if (!(event.getEntity() instanceof ServerPlayer player)) return;
|
||||
|
||||
PacketDistributor.sendToPlayer(player, new PlayerVariablesSyncMessage(player.getId(), player.getData(ModAttachments.PLAYER_VARIABLE).compareAndUpdate()));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerChangeDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
|
||||
if (!(event.getEntity() instanceof ServerPlayer player)) return;
|
||||
|
||||
PacketDistributor.sendToPlayer(player, new PlayerVariablesSyncMessage(player.getId(), player.getData(ModAttachments.PLAYER_VARIABLE).forceUpdate()));
|
||||
}
|
||||
|
||||
public PlayerVariable watch() {
|
||||
this.old = this.copy();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<Byte, Integer> forceUpdate() {
|
||||
var map = new HashMap<Byte, Integer>();
|
||||
|
||||
for (var type : Ammo.values()) {
|
||||
map.put((byte) type.ordinal(), type.get(this));
|
||||
}
|
||||
|
||||
map.put((byte) -1, this.tacticalSprint ? 1 : 0);
|
||||
map.put((byte) -2, this.edit ? 1 : 0);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public Map<Byte, Integer> compareAndUpdate() {
|
||||
var map = new HashMap<Byte, Integer>();
|
||||
var old = this.old == null ? new PlayerVariable() : this.old;
|
||||
|
|
Loading…
Add table
Reference in a new issue