Java Code Examples for org.bukkit.entity.Player#setDisplayName()
The following examples show how to use
org.bukkit.entity.Player#setDisplayName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrefixRegistryImpl.java From PGM with GNU Affero General Public License v3.0 | 8 votes |
@Override @EventHandler public void onPrefixChange(PrefixChangeEvent event) { if (event.getUUID() == null) { return; } final Player player = Bukkit.getPlayer(event.getUUID()); final MatchPlayer matchPlayer = PGM.get().getMatchManager().getPlayer(player); if (matchPlayer == null) { return; } player.setDisplayName(getPrefixedName(player, matchPlayer.getParty())); final MatchTabManager tabManager = PGM.get().getMatchTabManager(); if (tabManager != null) { final PlayerTabEntry tabEntry = (PlayerTabEntry) tabManager.getPlayerEntryOrNull(player); if (tabEntry != null) { tabEntry.invalidate(); tabEntry.refresh(); } } }
Example 2
Source File: PlayerAppearanceChanger.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
/** * Refresh the given player's appearance for all viewers, assuming the given identity is their current one. * * This is necessary if the player's identity changes, or if their current identity's name is invalidated. */ public void refreshPlayer(final Player player, final Identity identity) { player.setDisplayName(nameRenderer.getLegacyName(identity, REAL_NAME_TYPE)); final String legacyNickname = renderLegacyNickname(identity); for(Player viewer : player.getServer().getOnlinePlayers()) { refreshFakeNameAndSkin(player, identity, legacyNickname, viewer); } if(config.overheadFlair()) { String prefix = usernameRenderer.getColor(identity, REAL_NAME_TYPE).toString(); if(identity.getNickname() == null) { prefix = flairRenderer.getLegacyName(identity, REAL_NAME_TYPE) + prefix; } setOverheadNamePrefix(player, prefix); } }
Example 3
Source File: Team.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") public void removePlayer(Player player) { if (BedwarsRel.getInstance().isSpigot()) { if (this.getScoreboardTeam().hasEntry(player.getName())) { this.getScoreboardTeam().removeEntry(player.getName()); } } else { if (this.getScoreboardTeam().hasPlayer(player)) { this.getScoreboardTeam().removePlayer(player); } } if (BedwarsRel.getInstance().getBooleanConfig("overwrite-names", false) && player.isOnline()) { player.setDisplayName(ChatColor.RESET + ChatColor.stripColor(player.getName())); player.setPlayerListName(ChatColor.RESET + player.getPlayer().getName()); } }
Example 4
Source File: RankModule.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onPlayerNameUpdate(PlayerNameUpdateEvent event) { Player player = event.getPlayer(); String prefix = Rank.getPrefix(player.getUniqueId()); player.setDisplayName(prefix + Teams.getTeamColorByPlayer(player) + player.getName()); if (GameHandler.getGameHandler().getMatch().getModules().getModule(TitleRespawn.class).isDeadUUID(event.getPlayer().getUniqueId())) { player.setPlayerListName(prefix + ChatColor.DARK_GRAY + player.getName()); } else { player.setPlayerListName(prefix + Teams.getTeamColorByPlayer(player) + player.getName()); } }
Example 5
Source File: PrefixRegistryImpl.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler public void onJoinMatch(PlayerJoinMatchEvent event) { Player player = event.getPlayer().getBukkit(); player.setDisplayName(getPrefixedName(player, event.getNewParty())); }
Example 6
Source File: PrefixRegistryImpl.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler public void onPartyChange(PlayerPartyChangeEvent event) { Player player = event.getPlayer().getBukkit(); player.setDisplayName(getPrefixedName(player, event.getNewParty())); }
Example 7
Source File: CloudServer.java From CloudNet with Apache License 2.0 | 4 votes |
private void addTeamEntry(Player target, Player all, PermissionGroup permissionGroup) { String teamName = permissionGroup.getTagId() + permissionGroup.getName(); if (teamName.length() > 16) { teamName = teamName.substring(0, 16); CloudAPI.getInstance() .dispatchConsoleMessage("In order to prevent issues, the name (+ tagID) of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!"); CloudAPI.getInstance().dispatchConsoleMessage("Please fix this issue by changing the name of the group in your perms.yml"); Bukkit.broadcast("In order to prevent issues, the name (+ tagID) of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!", "cloudnet.notify"); Bukkit.broadcast("Please fix this issue by changing the name of the group in your perms.yml", "cloudnet.notify"); } Team team = all.getScoreboard().getTeam(teamName); if (team == null) { team = all.getScoreboard().registerNewTeam(teamName); } if (permissionGroup.getPrefix().length() > 16) { permissionGroup.setPrefix(permissionGroup.getPrefix().substring(0, 16)); CloudAPI.getInstance() .dispatchConsoleMessage("In order to prevent issues, the prefix of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!"); CloudAPI.getInstance().dispatchConsoleMessage("Please fix this issue by changing the prefix in your perms.yml"); Bukkit.broadcast("In order to prevent issues, the prefix of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!", "cloudnet.notify"); Bukkit.broadcast("Please fix this issue by changing the prefix in your perms.yml", "cloudnet.notify"); } if (permissionGroup.getSuffix().length() > 16) { permissionGroup.setSuffix(permissionGroup.getSuffix().substring(0, 16)); CloudAPI.getInstance() .dispatchConsoleMessage("In order to prevent issues, the suffix of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!"); CloudAPI.getInstance().dispatchConsoleMessage("Please fix this issue by changing the suffix in your perms.yml"); Bukkit.broadcast("In order to prevent issues, the suffix of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!", "cloudnet.notify"); Bukkit.broadcast("Please fix this issue by changing the suffix in your perms.yml", "cloudnet.notify"); } try { Method setColor = team.getClass().getDeclaredMethod("setColor", ChatColor.class); setColor.setAccessible(true); if (permissionGroup.getColor().length() != 0) { setColor.invoke(team, ChatColor.getByChar(permissionGroup.getColor().replaceAll("&", "").replaceAll("§", ""))); } else { setColor.invoke(team, ChatColor.getByChar(ChatColor.getLastColors(permissionGroup.getPrefix().replace('&', '§')) .replaceAll("&", "") .replaceAll("§", ""))); } } catch (NoSuchMethodException ignored) { } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } team.setPrefix(ChatColor.translateAlternateColorCodes('&', permissionGroup.getPrefix())); team.setSuffix(ChatColor.translateAlternateColorCodes('&', permissionGroup.getSuffix())); team.addEntry(target.getName()); target.setDisplayName(ChatColor.translateAlternateColorCodes('&', permissionGroup.getDisplay() + target.getName())); }
Example 8
Source File: PWIPlayerManager.java From PerWorldInventory with GNU General Public License v3.0 | 4 votes |
/** * Get a player from the cache, and apply the cached inventories and stats * to the actual player. If no matching player is found in the cache, nothing * happens and this method simply returns. * * @param group The {@link Group} the cached player was in. * @param gamemode The GameMode the cached player was in. * @param player The current actual player to apply the data to. * @param cause What triggered the inventory switch; passed on for post-processing. */ private void getDataFromCache(Group group, GameMode gamemode, Player player, DeserializeCause cause) { PWIPlayer cachedPlayer = getCachedPlayer(group, gamemode, player.getUniqueId()); if (cachedPlayer == null) { ConsoleLogger.debug("No data for player '" + player.getName() + "' found in cache"); return; } ConsoleLogger.debug("Player '" + player.getName() + "' found in cache! Setting their data"); if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS)) player.getEnderChest().setContents(cachedPlayer.getEnderChest()); if (settings.getProperty(PwiProperties.LOAD_INVENTORY)) { player.getInventory().setContents(cachedPlayer.getInventory()); player.getInventory().setArmorContents(cachedPlayer.getArmor()); } if (settings.getProperty(PwiProperties.LOAD_CAN_FLY)) player.setAllowFlight(cachedPlayer.getCanFly()); if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME)) player.setDisplayName(cachedPlayer.getDisplayName()); if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION)) player.setExhaustion(cachedPlayer.getExhaustion()); if (settings.getProperty(PwiProperties.LOAD_EXP)) player.setExp(cachedPlayer.getExperience()); if (settings.getProperty(PwiProperties.LOAD_FLYING) && player.getAllowFlight()) player.setFlying(cachedPlayer.isFlying()); if (settings.getProperty(PwiProperties.LOAD_HUNGER)) player.setFoodLevel(cachedPlayer.getFoodLevel()); if (settings.getProperty(PwiProperties.LOAD_HEALTH)) { if (bukkitService.shouldUseAttributes()) { player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(cachedPlayer.getMaxHealth()); } else { player.setMaxHealth(cachedPlayer.getMaxHealth()); } if (cachedPlayer.getHealth() > 0 && cachedPlayer.getHealth() <= cachedPlayer.getMaxHealth()) { player.setHealth(cachedPlayer.getHealth()); } else { player.setHealth(cachedPlayer.getMaxHealth()); } } if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES))) player.setGameMode(cachedPlayer.getGamemode()); if (settings.getProperty(PwiProperties.LOAD_LEVEL)) player.setLevel(cachedPlayer.getLevel()); if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS)) { for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } player.addPotionEffects(cachedPlayer.getPotionEffects()); } if (settings.getProperty(PwiProperties.LOAD_SATURATION)) player.setSaturation(cachedPlayer.getSaturationLevel()); if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE)) player.setFallDistance(cachedPlayer.getFallDistance()); if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS)) player.setFireTicks(cachedPlayer.getFireTicks()); if (settings.getProperty(PwiProperties.LOAD_MAX_AIR)) player.setMaximumAir(cachedPlayer.getMaxAir()); if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR)) player.setRemainingAir(cachedPlayer.getRemainingAir()); if (settings.getProperty(PwiProperties.USE_ECONOMY)) { Economy econ = plugin.getEconomy(); if (econ == null) { ConsoleLogger.warning("Economy saving is turned on, but no economy found!"); return; } EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player)); if (er.transactionSuccess()) { econ.depositPlayer(player, cachedPlayer.getBalance()); } else { ConsoleLogger.warning("[ECON] Unable to withdraw currency from '" + player.getName() + "': " + er.errorMessage); } EconomyResponse bankER = econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount); if (bankER.transactionSuccess()) { econ.bankDeposit(player.getName(), cachedPlayer.getBankBalance()); } else { ConsoleLogger.warning("[ECON] Unable to withdraw currency from bank of '" + player.getName() + "': " + er.errorMessage); } } InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause); Bukkit.getPluginManager().callEvent(event); }
Example 9
Source File: StatSerializer.java From PerWorldInventory with GNU General Public License v3.0 | 4 votes |
/** * Apply stats to a player. * * @param player The Player to apply the stats to. * @param stats The stats to apply. * @param dataFormat See {@link PlayerSerializer#serialize(PWIPlayer)}. */ public void deserialize(Player player,JsonObject stats, int dataFormat) { if (settings.getProperty(PwiProperties.LOAD_CAN_FLY) && stats.has("can-fly")) player.setAllowFlight(stats.get("can-fly").getAsBoolean()); if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME) && stats.has("display-name")) player.setDisplayName(stats.get("display-name").getAsString()); if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION) && stats.has("exhaustion")) player.setExhaustion((float) stats.get("exhaustion").getAsDouble()); if (settings.getProperty(PwiProperties.LOAD_EXP) && stats.has("exp")) player.setExp((float) stats.get("exp").getAsDouble()); if (settings.getProperty(PwiProperties.LOAD_FLYING) && stats.has("flying") && player.getAllowFlight()) player.setFlying(stats.get("flying").getAsBoolean()); if (settings.getProperty(PwiProperties.LOAD_HUNGER) && stats.has("food")) player.setFoodLevel(stats.get("food").getAsInt()); if (settings.getProperty(PwiProperties.LOAD_HEALTH) && stats.has("max-health") && stats.has("health")) { double maxHealth = stats.get("max-health").getAsDouble(); if (bukkitService.shouldUseAttributes()) { player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth); } else { player.setMaxHealth(maxHealth); } double health = stats.get("health").getAsDouble(); if (health > 0 && health <= maxHealth) { player.setHealth(health); } else { player.setHealth(maxHealth); } } if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)) && stats.has("gamemode")) { if (stats.get("gamemode").getAsString().length() > 1) { player.setGameMode(GameMode.valueOf(stats.get("gamemode").getAsString())); } else { int gm = stats.get("gamemode").getAsInt(); switch (gm) { case 0: player.setGameMode(GameMode.CREATIVE); break; case 1: player.setGameMode(GameMode.SURVIVAL); break; case 2: player.setGameMode(GameMode.ADVENTURE); break; case 3: player.setGameMode(GameMode.SPECTATOR); break; } } } if (settings.getProperty(PwiProperties.LOAD_LEVEL) && stats.has("level")) player.setLevel(stats.get("level").getAsInt()); if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS) && stats.has("potion-effects")) { if (dataFormat < 2) { PotionEffectSerializer.setPotionEffects(stats.get("potion-effects").getAsString(), player); } else { PotionEffectSerializer.setPotionEffects(stats.getAsJsonArray("potion-effects"), player); } } if (settings.getProperty(PwiProperties.LOAD_SATURATION) && stats.has("saturation")) player.setSaturation((float) stats.get("saturation").getAsDouble()); if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE) && stats.has("fallDistance")) player.setFallDistance(stats.get("fallDistance").getAsFloat()); if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS) && stats.has("fireTicks")) player.setFireTicks(stats.get("fireTicks").getAsInt()); if (settings.getProperty(PwiProperties.LOAD_MAX_AIR) && stats.has("maxAir")) player.setMaximumAir(stats.get("maxAir").getAsInt()); if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR) && stats.has("remainingAir")) player.setRemainingAir(stats.get("remainingAir").getAsInt()); }
Example 10
Source File: Team.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") public boolean addPlayer(Player player) { BedwarsPlayerJoinTeamEvent playerJoinTeamEvent = new BedwarsPlayerJoinTeamEvent(this, player); BedwarsRel.getInstance().getServer().getPluginManager().callEvent(playerJoinTeamEvent); if (playerJoinTeamEvent.isCancelled()) { return false; } if (BedwarsRel.getInstance().isSpigot()) { if (this.getScoreboardTeam().getEntries().size() >= this.getMaxPlayers()) { return false; } } else { if (this.getScoreboardTeam().getPlayers().size() >= this.getMaxPlayers()) { return false; } } String displayName = player.getDisplayName(); String playerListName = player.getPlayerListName(); if (BedwarsRel.getInstance().getBooleanConfig("overwrite-names", false)) { displayName = this.getChatColor() + ChatColor.stripColor(player.getName()); playerListName = this.getChatColor() + ChatColor.stripColor(player.getName()); } if (BedwarsRel.getInstance().getBooleanConfig("teamname-on-tab", true)) { playerListName = this.getChatColor() + this.getName() + ChatColor.WHITE + " | " + this.getChatColor() + ChatColor.stripColor(player.getDisplayName()); } BedwarsPlayerSetNameEvent playerSetNameEvent = new BedwarsPlayerSetNameEvent(this, displayName, playerListName, player); BedwarsRel.getInstance().getServer().getPluginManager().callEvent(playerSetNameEvent); if (!playerSetNameEvent.isCancelled()) { player.setDisplayName(playerSetNameEvent.getDisplayName()); player.setPlayerListName(playerSetNameEvent.getPlayerListName()); } if (BedwarsRel.getInstance().isSpigot()) { this.getScoreboardTeam().addEntry(player.getName()); } else { this.getScoreboardTeam().addPlayer(player); } this.equipPlayerWithLeather(player); return true; }
Example 11
Source File: PWIPlayerManager.java From PerWorldInventory with GNU General Public License v3.0 | 4 votes |
/** * Get a player from the cache, and apply the cached inventories and stats * to the actual player. If no matching player is found in the cache, nothing * happens and this method simply returns. * * @param group The {@link Group} the cached player was in. * @param gamemode The GameMode the cached player was in. * @param player The current actual player to apply the data to. * @param cause What triggered the inventory switch; passed on for post-processing. */ private void getDataFromCache(Group group, GameMode gamemode, Player player, DeserializeCause cause) { PWIPlayer cachedPlayer = getCachedPlayer(group, gamemode, player.getUniqueId()); if (cachedPlayer == null) { ConsoleLogger.debug("No data for player '" + player.getName() + "' found in cache"); return; } ConsoleLogger.debug("Player '" + player.getName() + "' found in cache! Setting their data"); if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS)) player.getEnderChest().setContents(cachedPlayer.getEnderChest()); if (settings.getProperty(PwiProperties.LOAD_INVENTORY)) { player.getInventory().setContents(cachedPlayer.getInventory()); player.getInventory().setArmorContents(cachedPlayer.getArmor()); } if (settings.getProperty(PwiProperties.LOAD_CAN_FLY)) player.setAllowFlight(cachedPlayer.getCanFly()); if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME)) player.setDisplayName(cachedPlayer.getDisplayName()); if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION)) player.setExhaustion(cachedPlayer.getExhaustion()); if (settings.getProperty(PwiProperties.LOAD_EXP)) player.setExp(cachedPlayer.getExperience()); if (settings.getProperty(PwiProperties.LOAD_FLYING) && player.getAllowFlight()) player.setFlying(cachedPlayer.isFlying()); if (settings.getProperty(PwiProperties.LOAD_HUNGER)) player.setFoodLevel(cachedPlayer.getFoodLevel()); if (settings.getProperty(PwiProperties.LOAD_HEALTH)) { if (bukkitService.shouldUseAttributes()) { player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(cachedPlayer.getMaxHealth()); } else { player.setMaxHealth(cachedPlayer.getMaxHealth()); } if (cachedPlayer.getHealth() > 0 && cachedPlayer.getHealth() <= cachedPlayer.getMaxHealth()) { player.setHealth(cachedPlayer.getHealth()); } else { player.setHealth(cachedPlayer.getMaxHealth()); } } if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES))) player.setGameMode(cachedPlayer.getGamemode()); if (settings.getProperty(PwiProperties.LOAD_LEVEL)) player.setLevel(cachedPlayer.getLevel()); if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS)) { for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } player.addPotionEffects(cachedPlayer.getPotionEffects()); } if (settings.getProperty(PwiProperties.LOAD_SATURATION)) player.setSaturation(cachedPlayer.getSaturationLevel()); if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE)) player.setFallDistance(cachedPlayer.getFallDistance()); if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS)) player.setFireTicks(cachedPlayer.getFireTicks()); if (settings.getProperty(PwiProperties.LOAD_MAX_AIR)) player.setMaximumAir(cachedPlayer.getMaxAir()); if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR)) player.setRemainingAir(cachedPlayer.getRemainingAir()); if (settings.getProperty(PwiProperties.USE_ECONOMY)) { Economy econ = plugin.getEconomy(); if (econ == null) { ConsoleLogger.warning("Economy saving is turned on, but no economy found!"); return; } EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player)); if (er.transactionSuccess()) { econ.depositPlayer(player, cachedPlayer.getBalance()); } else { ConsoleLogger.warning("[ECON] Unable to withdraw currency from '" + player.getName() + "': " + er.errorMessage); } EconomyResponse bankER = econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount); if (bankER.transactionSuccess()) { econ.bankDeposit(player.getName(), cachedPlayer.getBankBalance()); } else { ConsoleLogger.warning("[ECON] Unable to withdraw currency from bank of '" + player.getName() + "': " + er.errorMessage); } } InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause); Bukkit.getPluginManager().callEvent(event); }
Example 12
Source File: StatSerializer.java From PerWorldInventory with GNU General Public License v3.0 | 4 votes |
/** * Apply stats to a player. * * @param player The Player to apply the stats to. * @param stats The stats to apply. * @param dataFormat See {@link PlayerSerializer#serialize(PWIPlayer)}. */ public void deserialize(Player player,JsonObject stats, int dataFormat) { if (settings.getProperty(PwiProperties.LOAD_CAN_FLY) && stats.has("can-fly")) player.setAllowFlight(stats.get("can-fly").getAsBoolean()); if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME) && stats.has("display-name")) player.setDisplayName(stats.get("display-name").getAsString()); if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION) && stats.has("exhaustion")) player.setExhaustion((float) stats.get("exhaustion").getAsDouble()); if (settings.getProperty(PwiProperties.LOAD_EXP) && stats.has("exp")) player.setExp((float) stats.get("exp").getAsDouble()); if (settings.getProperty(PwiProperties.LOAD_FLYING) && stats.has("flying") && player.getAllowFlight()) player.setFlying(stats.get("flying").getAsBoolean()); if (settings.getProperty(PwiProperties.LOAD_HUNGER) && stats.has("food")) player.setFoodLevel(stats.get("food").getAsInt()); if (settings.getProperty(PwiProperties.LOAD_HEALTH) && stats.has("max-health") && stats.has("health")) { double maxHealth = stats.get("max-health").getAsDouble(); if (bukkitService.shouldUseAttributes()) { player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth); } else { player.setMaxHealth(maxHealth); } double health = stats.get("health").getAsDouble(); if (health > 0 && health <= maxHealth) { player.setHealth(health); } else { player.setHealth(maxHealth); } } if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)) && stats.has("gamemode")) { if (stats.get("gamemode").getAsString().length() > 1) { player.setGameMode(GameMode.valueOf(stats.get("gamemode").getAsString())); } else { int gm = stats.get("gamemode").getAsInt(); switch (gm) { case 0: player.setGameMode(GameMode.CREATIVE); break; case 1: player.setGameMode(GameMode.SURVIVAL); break; case 2: player.setGameMode(GameMode.ADVENTURE); break; case 3: player.setGameMode(GameMode.SPECTATOR); break; } } } if (settings.getProperty(PwiProperties.LOAD_LEVEL) && stats.has("level")) player.setLevel(stats.get("level").getAsInt()); if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS) && stats.has("potion-effects")) { if (dataFormat < 2) { PotionEffectSerializer.setPotionEffects(stats.get("potion-effects").getAsString(), player); } else { PotionEffectSerializer.setPotionEffects(stats.getAsJsonArray("potion-effects"), player); } } if (settings.getProperty(PwiProperties.LOAD_SATURATION) && stats.has("saturation")) player.setSaturation((float) stats.get("saturation").getAsDouble()); if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE) && stats.has("fallDistance")) player.setFallDistance(stats.get("fallDistance").getAsFloat()); if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS) && stats.has("fireTicks")) player.setFireTicks(stats.get("fireTicks").getAsInt()); if (settings.getProperty(PwiProperties.LOAD_MAX_AIR) && stats.has("maxAir")) player.setMaximumAir(stats.get("maxAir").getAsInt()); if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR) && stats.has("remainingAir")) player.setRemainingAir(stats.get("remainingAir").getAsInt()); }