feat(disguise): update others when joining

This commit is contained in:
ineanto 2023-12-03 22:46:59 +01:00
parent d673d34a51
commit d75aad6596
2 changed files with 12 additions and 3 deletions

View file

@ -58,7 +58,7 @@ public class AppearanceManager {
updateMetadata(); updateMetadata();
updateTabList(gameProfile, displayName); updateTabList(gameProfile, displayName);
respawnPlayer(); respawnPlayer();
updateOthers(); updateForOthers();
} }
return result; return result;
} }
@ -68,7 +68,10 @@ public class AppearanceManager {
return optionalProfile.orElse(NickoProfile.EMPTY_PROFILE.clone()); return optionalProfile.orElse(NickoProfile.EMPTY_PROFILE.clone());
} }
public void updateOthers() { public void updateForOthers() {
final NickoProfile nickoProfile = getNickoProfile();
if (!nickoProfile.hasData()) return;
final WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); final WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
final WrapperPlayServerSpawnEntity spawn = new WrapperPlayServerSpawnEntity(); final WrapperPlayServerSpawnEntity spawn = new WrapperPlayServerSpawnEntity();
destroy.setEntityIds(IntList.of(player.getEntityId())); destroy.setEntityIds(IntList.of(player.getEntityId()));

View file

@ -3,6 +3,7 @@ package xyz.atnrch.nicko.event;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import xyz.atnrch.nicko.NickoBukkit; import xyz.atnrch.nicko.NickoBukkit;
@ -17,7 +18,7 @@ import xyz.atnrch.nicko.storage.name.PlayerNameStore;
import java.util.Optional; import java.util.Optional;
public class PlayerJoinListener implements Listener { public class PlayerJoinListener implements Listener {
@EventHandler @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final NickoBukkit instance = NickoBukkit.getInstance(); final NickoBukkit instance = NickoBukkit.getInstance();
@ -41,6 +42,11 @@ public class PlayerJoinListener implements Listener {
} }
} }
}); });
for (Player online : Bukkit.getOnlinePlayers()) {
final AppearanceManager appearanceManager = new AppearanceManager(online);
appearanceManager.updateForOthers();
}
}, 20L); }, 20L);
} }
} }