fix: make players disguise on join
This commit is contained in:
parent
4f8c3c9eec
commit
99e7dd439a
2 changed files with 25 additions and 5 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
final AppearanceManager appearanceManager = new AppearanceManager(online);
|
||||
appearanceManager.updateForOthers();
|
||||
// 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);
|
||||
final boolean needsASkinChange = profile.getSkin() != null && !profile.getSkin().equals(online.getName());
|
||||
appearanceManager.updateForOthers(needsASkinChange, false);
|
||||
});
|
||||
}
|
||||
}, 20L);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue