Java Code Examples for org.bukkit.entity.Player#setExp()

The following examples show how to use org.bukkit.entity.Player#setExp() . 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: PlayerDeathListener.java    From PerWorldInventory with GNU General Public License v3.0 8 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent event) {
    Player player = event.getEntity();
    Group group = groupManager.getGroupFromWorld(player.getLocation().getWorld().getName());

    if (!event.getKeepInventory()) {
        player.getInventory().clear();
    }

    if (!event.getKeepLevel()) {
        player.setExp(event.getNewExp());
        player.setLevel(event.getNewLevel());
    }

    player.setFoodLevel(20);
    player.setSaturation(5f);
    player.setExhaustion(0f);
    player.setFallDistance(0f);
    player.setFireTicks(0);
    for (PotionEffect effect : player.getActivePotionEffects()) {
        player.removePotionEffect(effect.getType());
    }

    playerManager.addPlayer(player, group);
}
 
Example 2
Source File: DoubleJumpKit.java    From CardinalPGM with MIT License 6 votes vote down vote up
private void update() {
    int diff = (int) (System.currentTimeMillis() - lastUpdate);
    lastUpdate = System.currentTimeMillis();
    float toAddExp = rechargeTime > 0 ? (float) (diff / (rechargeTime * 1000)) : 1.0f;
    for(UUID uuid : players) {
        Player player = Bukkit.getPlayer(uuid);
        if(player.getExp() < 1.0f && (rechargeBeforeLanding || landed.contains(uuid))) {
            player.setExp(player.getExp() + toAddExp > 1.0f ? 1.0f : player.getExp() + toAddExp);
        } else if(player.getExp() > 1.0f) {
            player.setExp(1.0f);
        }
        if(player.getExp() >= 1.0f) {
            player.setAllowFlight(true);
        }
    }
}
 
Example 3
Source File: SetExpFix.java    From PlayerSQL with GNU General Public License v2.0 6 votes vote down vote up
public static void setTotalExperience(final Player player, final int exp) {
    if (exp < 0) {
        throw new IllegalArgumentException("Experience is negative!");
    }
    player.setExp(0);
    player.setLevel(0);
    player.setTotalExperience(0);

    //This following code is technically redundant now, as bukkit now calulcates levels more or less correctly
    //At larger numbers however... player.getExp(3000), only seems to give 2999, putting the below calculations off.
    int amount = exp;
    while (amount > 0) {
        final int expToLevel = getExpAtLevel(player);
        amount -= expToLevel;
        if (amount >= 0) {
            // give until next level
            player.giveExp(expToLevel);
        } else {
            // give the rest
            amount += expToLevel;
            player.giveExp(amount);
            amount = 0;
        }
    }
}
 
Example 4
Source File: DoubleJumpKit.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler
public void onPlayerToggleFly(PlayerToggleFlightEvent event) {
    if (!enabled) return;
    Player player = event.getPlayer();
    if (!players.contains(player.getUniqueId()) || player.getExp() > 1.0f || !event.isFlying()) return;
    player.setAllowFlight(false);
    player.setExp(0.0f);
    event.setCancelled(true);

    Vector normal = player.getEyeLocation().getDirection();
    normal.setY(0.75 + Math.max(normal.getY() * 0.5, 0));
    normal.multiply(power / 2);
    event.getPlayer().setVelocity(normal);

    player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ZOMBIE_INFECT, 0.5f, 1.8f);

    update();
}
 
Example 5
Source File: CronusUtils.java    From TabooLib with MIT License 6 votes vote down vote up
public static void setTotalExperience(Player player, int exp) {
    player.setExp(0);
    player.setLevel(0);
    player.setTotalExperience(0);
    int amount = exp;
    while (amount > 0) {
        int expToLevel = getExpAtLevel(player);
        amount -= expToLevel;
        if (amount >= 0) {
            player.giveExp(expToLevel);
        } else {
            amount += expToLevel;
            player.giveExp(amount);
            amount = 0;
        }
    }
}
 
Example 6
Source File: Players.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static void resetPlayer(Player player, boolean heal) {
    if (heal) player.setHealth(player.getMaxHealth());
    player.setFoodLevel(20);
    player.setSaturation(20);
    player.getInventory().clear();
    player.getInventory().setArmorContents(new ItemStack[]{new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR)});
    for (PotionEffect effect : player.getActivePotionEffects()) {
        try {
            player.removePotionEffect(effect.getType());
        } catch (NullPointerException ignored) {
        }
    }
    player.setTotalExperience(0);
    player.setExp(0);
    player.setLevel(0);
    player.setPotionParticles(false);
    player.setWalkSpeed(0.2F);
    player.setFlySpeed(0.1F);
    player.setKnockbackReduction(0);
    player.setArrowsStuck(0);

    player.hideTitle();

    player.setFastNaturalRegeneration(false);

    for (Attribute attribute : Attribute.values()) {
        if (player.getAttribute(attribute) == null) continue;
        for (AttributeModifier modifier : player.getAttribute(attribute).getModifiers()) {
            player.getAttribute(attribute).removeModifier(modifier);
        }
    }
    player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).addModifier(new AttributeModifier(UUID.randomUUID(), "generic.attackSpeed", 4.001D, AttributeModifier.Operation.ADD_SCALAR));
    player.getAttribute(Attribute.ARROW_ACCURACY).addModifier(new AttributeModifier(UUID.randomUUID(), "sportbukkit.arrowAccuracy", -1D, AttributeModifier.Operation.ADD_NUMBER));
    player.getAttribute(Attribute.ARROW_VELOCITY_TRANSFER).addModifier(new AttributeModifier(UUID.randomUUID(), "sportbukkit.arrowVelocityTransfer", -1D, AttributeModifier.Operation.ADD_NUMBER));
}
 
Example 7
Source File: DoubleJumpKit.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onMatchEnd(MatchEndEvent event) {
    enabled = false;
    for(UUID uuid : players) {
        Player player = Bukkit.getPlayer(uuid);
        player.setExp(0.0f);
        player.setAllowFlight(false);
    }
    landed.clear();
    players.clear();
}
 
Example 8
Source File: PlayerManager.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public static void reset(Player p) {
	p.setGameMode(GameMode.SURVIVAL);
	p.setHealth(20);
	p.setFoodLevel(20);
	
	clearEffects(p);
	p.setExp(0);
	p.setLevel(0);
	
	p.getInventory().clear();
	p.getInventory().setArmorContents(null);
	
	PlayerInventory.update(p);
}
 
Example 9
Source File: TutorialPlayer.java    From ServerTutorial with MIT License 5 votes vote down vote up
public void clearPlayer(Player player) {
    player.getInventory().clear();
    player.setAllowFlight(true);
    player.setFlying(true);

    player.setExp(1.0f);
    player.setLevel(0);
    player.setFoodLevel(20);
    player.setHealth(player.getMaxHealth());

    for (Player online : Bukkit.getServer().getOnlinePlayers()) {
        online.hidePlayer(player);
        player.hidePlayer(online);
    }
}
 
Example 10
Source File: Utils.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set a player's stats to defaults, and optionally clear their inventory.
 *
 * @param plugin {@link PerWorldInventory} for econ.
 * @param player The player to zero.
 * @param clearInventory Clear the player's inventory.
 */
public static void zeroPlayer(PerWorldInventory plugin, Player player, boolean clearInventory) {
    if (clearInventory) {
        player.getInventory().clear();
        player.getEnderChest().clear();
    }

    player.setExp(0f);
    player.setFoodLevel(20);

    if (checkServerVersion(Bukkit.getVersion(), 1, 9, 0)) {
        player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
    } else {
        player.setHealth(player.getMaxHealth());
    }

    player.setLevel(0);
    for (PotionEffect effect : player.getActivePotionEffects()) {
        player.removePotionEffect(effect.getType());
    }
    player.setSaturation(5f);
    player.setFallDistance(0f);
    player.setFireTicks(0);

    if (plugin.isEconEnabled()) {
        Economy econ = plugin.getEconomy();
        econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount);
        econ.withdrawPlayer(player, econ.getBalance(player));
    }
}
 
Example 11
Source File: DoubleJumpKit.java    From CardinalPGM with MIT License 5 votes vote down vote up
@Override
public void remove(Player player) {
    if (!players.contains(player.getUniqueId())) return;
    players.remove(player.getUniqueId());
    player.setExp(0.0f);
    player.setAllowFlight(false);
}
 
Example 12
Source File: ClearXPAction.java    From UHC with MIT License 5 votes vote down vote up
@Override
protected void run(Player player) {
    exp = player.getExp();
    level = player.getLevel();
    total = player.getTotalExperience();

    player.setExp(0F);
    player.setLevel(0);
    player.setTotalExperience(0);
}
 
Example 13
Source File: TutorialListener.java    From ServerTutorial with MIT License 5 votes vote down vote up
@EventHandler
public void onViewSwitch(ViewSwitchEvent event) {
    Player player = event.getPlayer();
    if (TutorialManager.getManager().getConfigs().getExpCountdown()) {
        player.setExp(player.getExp() - 1f);
    }
    if (TutorialManager.getManager().getConfigs().getRewards()) {
        UUID uuid = Caching.getCaching().getUUID(player);
        if (!seenTutorial(uuid, event.getTutorial().getName())) {
            if (TutorialManager.getManager().getConfigs().getViewExp()) {
                player.setTotalExperience(player.getTotalExperience() + TutorialManager.getManager().getConfigs()
                        .getPerViewExp());
                player.sendMessage(ChatColor.BLUE + "You received " + TutorialManager.getManager().getConfigs()
                        .getViewExp());
            }
            if (TutorialManager.getManager().getConfigs().getViewMoney()) {
                if (TutorialEco.getTutorialEco().setupEconomy()) {
                    EconomyResponse ecoResponse = TutorialEco.getTutorialEco().getEcon().depositPlayer(player,
                            TutorialManager.getManager().getConfigs().getPerViewMoney());
                    if (ecoResponse.transactionSuccess()) {
                        player.sendMessage(ChatColor.BLUE + "You received " + ecoResponse.amount + " New Balance:" +
                                " " + ecoResponse.balance);
                    } else {
                        plugin.getLogger().log(Level.WARNING, "There was an error processing Economy for player: " +
                                "{0}", player.getName());
                    }
                }
            }
        }
    }
}
 
Example 14
Source File: Resident.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public void setSpyExposure(double spyExposure) {
	this.spyExposure = spyExposure;
	
	try {
		Player player = CivGlobal.getPlayer(this);
		double percentage = spyExposure / MAX_SPY_EXPOSURE;
		player.setExp((float)percentage);
	} catch (CivException e) {
	}
	
}
 
Example 15
Source File: FlagTimeout.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
	float exp = (float) secondsLeft / length;
	
	if (secondsLeft <= 0) {
		game.broadcast(getI18N().getString(Messages.Broadcast.GAME_TIMED_OUT));
		game.stop();
		game.flushQueue();
		task.cancel();
	} else if ((secondsLeft > 60 && secondsLeft % 60 == 0) || (secondsLeft <= 60 && secondsLeft % 30 == 0) || secondsLeft <= 5) {
		String message = getTimeString();
		
		game.broadcast(message);
	}
	
	String scoreboardString = getScoreboardTitle();
	FlagScoreboard.SetScoreboardDisplayNameEvent event = new FlagScoreboard.SetScoreboardDisplayNameEvent();
	event.setDisplayName(scoreboardString);
	game.getEventBus().callEvent(event);
	
	for (SpleefPlayer player : game.getPlayers()) {
		Player bukkitPlayer = player.getBukkitPlayer();
		bukkitPlayer.setExp(exp);
		bukkitPlayer.setLevel(secondsLeft);
	}
	
	secondsLeft--;
}
 
Example 16
Source File: PWIPlayerManager.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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 17
Source File: StatSerializer.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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 18
Source File: ClearXPAction.java    From UHC with MIT License 4 votes vote down vote up
@Override
protected void revert(Player player) {
    player.setExp(exp);
    player.setLevel(level);
    player.setTotalExperience(total);
}
 
Example 19
Source File: PlayerData.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
public void restore(boolean playerQuit) {
if (!beingRestored) {
	beingRestored = true;
       final Player player = this.getPlayer();
       if (player == null) {
           return;
       }
       
	if (SkyWarsReloaded.getCfg().debugEnabled()) {
       	Util.get().logToFile(ChatColor.RED + "[skywars] " + ChatColor.YELLOW + "Restoring " + player.getName());
   	}
   	PlayerStat pStats = PlayerStat.getPlayerStats(player);
       player.closeInventory();
       player.setGameMode(GameMode.SURVIVAL);
       if (SkyWarsReloaded.getCfg().displayPlayerExeperience()) {
       	if (pStats != null) { Util.get().setPlayerExperience(player, pStats.getXp()); }
       }
       Util.get().clear(player);
       player.getInventory().clear();
       player.getInventory().setContents(inv.getContents());
       SkyWarsReloaded.getNMS().setMaxHealth(player, 20);
       if (health <= 0 || health > 20) {
		player.setHealth(20);
	} else {
		player.setHealth(health);
	}
       player.setFoodLevel(food);
       player.setSaturation(sat);
       player.resetPlayerTime();
       player.resetPlayerWeather();
       player.setAllowFlight(false);
       player.setFlying(false);
	if (!SkyWarsReloaded.getCfg().displayPlayerExeperience()) {
		player.setExp(xp);
	}
       
       player.setFireTicks(0);
       player.setScoreboard(sb);
       if (SkyWarsReloaded.getCfg().lobbyBoardEnabled() && !SkyWarsReloaded.getCfg().bungeeMode()) {
        PlayerStat.updateScoreboard(player);
       }
       
       final Location respawn = SkyWarsReloaded.getCfg().getSpawn();
       if (SkyWarsReloaded.get().isEnabled()) {
           if (playerQuit) {
                     player.teleport(respawn, TeleportCause.END_PORTAL);
                 } else {
                     new BukkitRunnable() {
                         @Override
                         public void run() {
                             player.teleport(respawn, TeleportCause.END_PORTAL);
                         }
                     }.runTaskLater(SkyWarsReloaded.get(), 2);
                 }
	} else {
		player.teleport(respawn, TeleportCause.END_PORTAL);
	}

       
   	if (SkyWarsReloaded.getCfg().debugEnabled()) {
       	Util.get().logToFile(ChatColor.RED + "[skywars] " + ChatColor.YELLOW + "Finished restoring " + player.getName() + ". Teleporting to Spawn");
   	}
	if (SkyWarsReloaded.getCfg().bungeeMode()) {
		new BukkitRunnable() {
			@Override
			public void run() {
				String uuid = player.getUniqueId().toString();
				SkyWarsReloaded.get().sendBungeeMsg(player, "Connect", SkyWarsReloaded.getCfg().getBungeeLobby());
				PlayerStat remove = PlayerStat.getPlayerStats(uuid);
				PlayerStat.getPlayers().remove(remove);
			}
		}.runTaskLater(SkyWarsReloaded.get(), 5);
	}
}
  }
 
Example 20
Source File: PlayerStateHolder.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
public void apply(Player player, boolean teleport) {
	PlayerInventory playerInv = player.getInventory();
	boolean is1_9 = MinecraftVersion.getImplementationVersion().compareTo(MinecraftVersion.V1_9) >= 0;
       boolean isSimpleSize = playerInv.getContents().length <= SIMPLE_INVENTORY_SIZE;

       ItemStack[] inventoryContents = new ItemStack[is1_9 && !isSimpleSize ? playerInv.getSize() : SIMPLE_INVENTORY_SIZE];
       System.arraycopy(inventory, 0, inventoryContents, 0, inventoryContents.length);

       if (!is1_9 || isSimpleSize) {
           ItemStack[] armorContents = new ItemStack[ARMOR_INVENTORY_SIZE];
           System.arraycopy(inventory, inventory.length - ARMOR_INVENTORY_SIZE, armorContents, 0, armorContents.length);
           playerInv.setArmorContents(armorContents);
       }
	
	playerInv.setContents(inventoryContents);

	player.setItemOnCursor(null);
	Map<Integer, ItemStack> exceeded = playerInv.addItem(onCursor);
	for (ItemStack stack : exceeded.values()) {
           if (stack.getType() == Material.AIR) {
               continue;
           }
           
		player.getWorld().dropItem(player.getLocation(), stack);
	}
	
	player.updateInventory();

       player.setMaxHealth(maxHealth);
	player.setHealth(health);
	player.setFoodLevel(foodLevel);
	player.setLevel(level);
	player.setExp(experience);
	player.setAllowFlight(allowFlight);
	player.setFlying(isFlying);
	
	/* Remove current potion effects */
	Collection<PotionEffect> effects = player.getActivePotionEffects();
	for (PotionEffect effect : effects) {
		player.removePotionEffect(effect.getType());
	}
	player.addPotionEffects(activeEffects);
	
	player.setExhaustion(exhaustion);
	player.setSaturation(saturation);
	player.setFallDistance(fallDistance);
	player.setFireTicks(fireTicks);
	
	if (scoreboard != player.getScoreboard()) {
		Scoreboard showBoard = scoreboard;
		if (scoreboard == null) {
			showBoard = Bukkit.getScoreboardManager().getMainScoreboard();
		}
		
		player.setScoreboard(showBoard);
	}
	
	if (teleport) {
		player.teleport(location);
	}
	
	Location compassTarget = this.compassTarget;
	
	if (compassTarget == null) {
		compassTarget = player.getWorld().getSpawnLocation();
	}
	
	player.setCompassTarget(compassTarget);
	
	for (WeakReference<Player> ref : cantSee) {
		Player cantSeePlayer = ref.get();
		
		if (cantSeePlayer == null) {
			// Player object has been garbage-collected
			continue;
		}
		
		if (!cantSeePlayer.isOnline()) {
			continue;
		}
		
		player.hidePlayer(cantSeePlayer);
	}
	
	player.setGameMode(gamemode);
}