fix: make players disguise on join

This commit is contained in:
ineanto 2023-12-06 22:35:31 +01:00
parent 4f8c3c9eec
commit 99e7dd439a
2 changed files with 25 additions and 5 deletions

View file

@ -58,7 +58,20 @@ public class AppearanceManager {
updateMetadata();
updateTabList(gameProfile, displayName);
respawnPlayer();
updateForOthers();
respawnEntityForOthers();
}
return result;
}
public ActionResult updateForOthers(boolean skinChange, boolean reset) {
final NickoProfile profile = getNickoProfile();
final String displayName = profile.getName() == null ? player.getName() : profile.getName();
final WrappedGameProfile gameProfile = WrappedGameProfile.fromPlayer(player).withName(displayName);
final ActionResult result = updateGameProfileSkin(gameProfile, skinChange, reset);
if (!result.isError()) {
updateMetadata();
updateTabList(gameProfile, displayName);
respawnEntityForOthers();
}
return result;
}
@ -68,7 +81,7 @@ public class AppearanceManager {
return optionalProfile.orElse(NickoProfile.EMPTY_PROFILE.clone());
}
public void updateForOthers() {
public void respawnEntityForOthers() {
final NickoProfile nickoProfile = getNickoProfile();
if (!nickoProfile.hasData()) return;

View file

@ -16,6 +16,7 @@ import xyz.ineanto.nicko.storage.PlayerDataStore;
import xyz.ineanto.nicko.storage.name.PlayerNameStore;
import java.util.Optional;
import java.util.stream.Collectors;
public class PlayerJoinListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@ -43,9 +44,15 @@ public class PlayerJoinListener implements Listener {
}
});
for (Player online : Bukkit.getOnlinePlayers()) {
// TODO (Ineanto, 12/6/23): Make this cleaner.
for (Player online : Bukkit.getOnlinePlayers().stream().filter(op -> op.getUniqueId() != player.getUniqueId()).collect(Collectors.toList())) {
final Optional<NickoProfile> optionalOnlinePlayerProfile = dataStore.getData(online.getUniqueId());
optionalOnlinePlayerProfile.ifPresent(profile -> {
final AppearanceManager appearanceManager = new AppearanceManager(online);
appearanceManager.updateForOthers();
final boolean needsASkinChange = profile.getSkin() != null && !profile.getSkin().equals(online.getName());
appearanceManager.updateForOthers(needsASkinChange, false);
});
}
}, 20L);
}