diff --git a/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java b/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java index 46bc0df92..22fbe2e67 100644 --- a/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java +++ b/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java @@ -52,11 +52,38 @@ public class PlayerVariable implements INBTSerializable { 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 forceUpdate() { + var map = new HashMap(); + + 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 compareAndUpdate() { var map = new HashMap(); var old = this.old == null ? new PlayerVariable() : this.old;