当前位置: 首页>>代码示例>>Java>>正文


Java Player.setHealth方法代码示例

本文整理汇总了Java中org.bukkit.entity.Player.setHealth方法的典型用法代码示例。如果您正苦于以下问题:Java Player.setHealth方法的具体用法?Java Player.setHealth怎么用?Java Player.setHealth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.entity.Player的用法示例。


在下文中一共展示了Player.setHealth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onRegen

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler
public void onRegen(EntityRegainHealthEvent event) {
    if (event.getEntityType() != EntityType.PLAYER || event.getRegainReason() != EntityRegainHealthEvent.RegainReason.SATIATED) return;
    event.setCancelled(true);

    Player player = (Player) event.getEntity();
    long currentTime = System.currentTimeMillis() / 1000;

    if (currentTime - getLastHealTime(player) < 3)
        return;

    double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();

    if (player.getHealth() < maxHealth) {
        player.setHealth(clamp(player.getHealth() + 1, 0.0, maxHealth));
        healTimes.put(player.getUniqueId(), currentTime);
    }

    float exhToApply = (float) 3;

    Bukkit.getScheduler().runTaskLater(TGM.get(), () -> {
        //This is because bukkit doesn't stop the exhaustion change when cancelling the event
        player.setExhaustion(player.getExhaustion() + exhToApply);
        //debug("Exhaustion before: " + previousExh + " Now: " + p.getExhaustion() + "Saturation: " + p.getSaturation(), p);
    }, 1L);
}
 
开发者ID:WarzoneMC,项目名称:Warzone,代码行数:27,代码来源:RegenModule.java

示例2: resetPlayer

import org.bukkit.entity.Player; //导入方法依赖的package包/类
public static void resetPlayer(Player player) {
    player.setLevel(0);
    player.setExp(0);
    player.setFoodLevel(20);
    player.setHealth(20);
    player.setHealthScale(20);
    player.setExhaustion(0);
    player.getInventory().clear();
    ItemStack blankItem = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 15);
    ItemMeta blankMeta = blankItem.getItemMeta();
    blankMeta.setDisplayName("" + ChatColor.RED);
    blankItem.setItemMeta(blankMeta);
    for(int i=9; i<=35; i++) {
        player.getInventory().setItem(i, blankItem);
    }
    player.getInventory().setHelmet(new ItemStack(Material.AIR, 1));
    player.getInventory().setChestplate(new ItemStack(Material.AIR, 1));
    player.getInventory().setLeggings(new ItemStack(Material.AIR, 1));
    player.getInventory().setBoots(new ItemStack(Material.AIR, 1));
    for(PotionEffect potionEffect : player.getActivePotionEffects()) {
        player.removePotionEffect(potionEffect.getType());
    }
    player.setFireTicks(0);
}
 
开发者ID:ArcadiaPlugins,项目名称:Arcadia-Spigot,代码行数:25,代码来源:Utils.java

示例3: handleDetonate

import org.bukkit.entity.Player; //导入方法依赖的package包/类
private void handleDetonate(Player player, Rune rune) {
	player.spawnParticle(Particle.EXPLOSION_HUGE, player.getLocation(), 1);
	player.playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
	for(Entity entity : player.getNearbyEntities(3D, 3D, 3D)) {
		if(!(entity instanceof Player)) {
			continue;
		}
		Player target = (Player) entity;
		
		if(Utility.canAttack(player, target)) {
			if(target.getHealth() > 6) {
				target.setHealth(target.getHealth() - 6);
			}
			else {
				target.damage(1000000D, player);
			}
		}
	}
	finish(player, false);
}
 
开发者ID:benNek,项目名称:AsgardAscension,代码行数:21,代码来源:RuneManager.java

示例4: onGameStart

import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
 * Give effects to all players
 *
 * @param game Game instance
 */
@Override
public void onGameStart(SurvivalGame game)
{
    for (SurvivalPlayer player : (Collection<SurvivalPlayer>)game.getInGamePlayers().values())
    {
        Player p = player.getPlayerIfOnline();

        if (p == null)
            continue;

        p.addPotionEffect(PotionEffectType.SPEED.createEffect(Integer.MAX_VALUE, 1));
        p.addPotionEffect(PotionEffectType.INCREASE_DAMAGE.createEffect(Integer.MAX_VALUE, 1));
        p.addPotionEffect(PotionEffectType.DAMAGE_RESISTANCE.createEffect(Integer.MAX_VALUE, 1));
        p.addPotionEffect(PotionEffectType.JUMP.createEffect(Integer.MAX_VALUE, 4));
        p.setMaxHealth(32D);
        p.setHealth(32D);
    }
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:24,代码来源:SuperheroesModule.java

示例5: onJoin

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler
public void onJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();

    event.setJoinMessage(null);

    if (!Skywars.getInstance().isSingleServerMode()) {
        player.setGameMode(GameMode.ADVENTURE);
        player.getInventory().clear();
        player.setMaxHealth(20);
        player.setHealth(player.getMaxHealth());
        player.setFoodLevel(25);

        player.teleport(Skywars.getInstance().getLobbyPoint());
    }
}
 
开发者ID:JordanOsterberg,项目名称:SkywarsSeries,代码行数:17,代码来源:PlayerJoin.java

示例6: cleanPlayer

import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
 * Clean player's inventory
 *
 * @param player Player
 */
public static void cleanPlayer(Player player)
{
    if(player != null && Bukkit.getPlayer(player.getUniqueId()) != null)
    {
        player.getInventory().clear();
        player.getInventory().setHelmet(null);
        player.getInventory().setChestplate(null);
        player.getInventory().setLeggings(null);
        player.getInventory().setBoots(null);

        player.setSaturation(20.0F);
        player.setHealth(player.getMaxHealth());
        player.setExp(0.0F);
        player.setLevel(0);

        for(PotionEffect potionEffect : player.getActivePotionEffects())
            player.removePotionEffect(potionEffect.getType());
    }
}
 
开发者ID:SamaGames,项目名称:SamaGamesAPI,代码行数:25,代码来源:InventoryUtils.java

示例7: onGameStart

import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
 * Give effects to all players
 *
 * @param game Game instance
 */
@Override
public void onGameStart(SurvivalGame game)
{
    for (SurvivalPlayer player : (Collection<SurvivalPlayer>)game.getInGamePlayers().values())
    {
        Player p = player.getPlayerIfOnline();

        if (p == null)
            continue;

        p.addPotionEffect(PotionEffectType.SPEED.createEffect(Integer.MAX_VALUE, 2));
        p.addPotionEffect(PotionEffectType.FAST_DIGGING.createEffect(Integer.MAX_VALUE, 2));
        p.addPotionEffect(PotionEffectType.SATURATION.createEffect(Integer.MAX_VALUE, 10));
        p.addPotionEffect(PotionEffectType.INCREASE_DAMAGE.createEffect(Integer.MAX_VALUE, 1));
        p.addPotionEffect(PotionEffectType.DAMAGE_RESISTANCE.createEffect(Integer.MAX_VALUE, 1));
        p.addPotionEffect(PotionEffectType.FIRE_RESISTANCE.createEffect(Integer.MAX_VALUE, 1));
        p.addPotionEffect(PotionEffectType.JUMP.createEffect(Integer.MAX_VALUE, 4));
        p.addPotionEffect(PotionEffectType.WATER_BREATHING.createEffect(Integer.MAX_VALUE, 1));
        p.setMaxHealth(40D);
        p.setHealth(40D);
    }
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:28,代码来源:SuperheroesPlusModule.java

示例8: joinLobby

import org.bukkit.entity.Player; //导入方法依赖的package包/类
public synchronized boolean joinLobby(Player player) {
    if (this.canJoinLobby(player)) {
        this.lobby.add(player);
        this.storeTemporaryInventory(player);
        player.getInventory().setArmorContents(new ItemStack[4]);
        player.getInventory().clear();
        player.updateInventory();
        player.setHealth(player.getMaxHealth());
        player.setFoodLevel(20);
        player.setExp(0);
        player.setLevel(0);
        player.setGameMode(GameMode.ADVENTURE);
        player.teleport(this.getArena().getLobbyMeta().getLobbySpawn());
        return true;
    }
    return false;
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:18,代码来源:HelperGameEntity.java

示例9: onEntityDamageByEntity

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    Entity entity = event.getEntity();
    Entity damager = event.getDamager();
    if (entity instanceof Player && damager instanceof Player) {
        Player attacker = (Player) damager;
        if (plugin.getPvpClassManager().getEquippedClass(attacker) == this) {
            ItemStack stack = attacker.getItemInHand();
            if (stack != null && stack.getType() == Material.GOLD_SWORD && stack.getEnchantments().isEmpty()) {
                Player player = (Player) entity;
                player.sendMessage(SettingsYML.ENEMY_COLOUR + attacker.getName() + ChatColor.YELLOW + " has backstabbed you.");
                player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);

                attacker.sendMessage(ChatColor.YELLOW + "You have backstabbed " + SettingsYML.ENEMY_COLOUR + player.getName() + ChatColor.YELLOW + '.');
                attacker.setItemInHand(new ItemStack(Material.AIR, 1));
                player.setHealth(12);
                attacker.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);

                event.setDamage(3.0);
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:24,代码来源:RogueClass.java

示例10: handleLightning

import org.bukkit.entity.Player; //导入方法依赖的package包/类
private void handleLightning(Player player, Rune rune) {
	@SuppressWarnings("deprecation")
	Block block = player.getTargetBlock((HashSet<Byte>) null, 15);
	if(!Utility.isPVPEnabled(block.getLocation())) {
		return;
	}
	
	block.getWorld().strikeLightning(block.getLocation());
	for(Entity e : block.getWorld().getEntities()) {
		if(!(e instanceof Player)) {
			continue;
		}
		Player target = (Player) e;
		if(!Utility.canAttack(player, target)) {
			continue;
		}
		double distance = target.getLocation().distance(block.getLocation());
		double damage = 0;
		if(distance < 1) {
			damage = 16;
		}
		else if(distance <= 3) {
			damage = 10;
		}
		
		if(damage < 1)
			continue;
		
		if(target.getHealth() > damage)
			target.setHealth(target.getHealth() - damage);
		else
			target.damage(1000000, player);
		target.sendMessage(Lang.HEADERS_TOKENS.toString() + Lang.TOKENS_LIGHTNING.toString()
			.replaceAll("%s", player.getName()));
	}
	finish(player, false);
}
 
开发者ID:benNek,项目名称:AsgardAscension,代码行数:38,代码来源:RuneManager.java

示例11: onRespawn

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler
public void onRespawn(PlayerRespawnEvent event) {
	Player player = event.getPlayer();
       player.setGameMode(GameMode.SURVIVAL);
       player.setHealth(20.0);
       player.setFoodLevel(20);
       player.setAllowFlight(false);
       player.setFlying(false);
       player.setFireTicks(0);
       player.getActivePotionEffects().forEach(potionEffect -> player.removePotionEffect(potionEffect.getType()));
}
 
开发者ID:HuliPvP,项目名称:Chambers,代码行数:12,代码来源:PlayerRespawnListener.java

示例12: onGameStart

import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
 * Double the health on game's start
 *
 * @param game Game
 */
@Override
public void onGameStart(SurvivalGame game)
{
    for (GamePlayer player : (Collection<GamePlayer>) game.getInGamePlayers().values())
    {
        Player p = player.getPlayerIfOnline();

        if (p == null)
            continue;

        p.setMaxHealth(40.0D);
        p.setHealth(40.0D);
    }
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:20,代码来源:DoubleHealthModule.java

示例13: onGameStart

import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
 * Multiply max health by 2
 *
 * @param game Game
 */
@Override
public void onGameStart(SurvivalGame game)
{
    for (GamePlayer player : (Collection<GamePlayer>) game.getInGamePlayers().values())
    {
        Player p = player.getPlayerIfOnline();

        if (p == null)
            continue;

        p.setMaxHealth(this.maxHealth);
        p.setHealth(this.maxHealth / 2);
    }
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:20,代码来源:PotentialHeartsModule.java

示例14: reset

import org.bukkit.entity.Player; //导入方法依赖的package包/类
private void reset(Player player) {
	Bukkit.getOnlinePlayers().stream().filter(other -> other != player).forEach(other -> other.hidePlayer(player));
	player.setGameMode(GameMode.CREATIVE);
       player.setHealth(20.0);
       player.setFoodLevel(20);
       player.getActivePotionEffects().forEach(potionEffect -> player.removePotionEffect(potionEffect.getType()));
       player.setAllowFlight(true);
       player.setFlying(true);
       player.setVelocity(player.getVelocity().setY(1.1));
       player.getInventory().clear();
       player.getInventory().setArmorContents(null);
}
 
开发者ID:HuliPvP,项目名称:Chambers,代码行数:13,代码来源:PlayerDeathListener.java

示例15: onLeave

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler
public void onLeave(PlayerQuitEvent event){
    Player p = event.getPlayer();
    SurvivalUser u = PASurvival.getPlayer(p);

    if(Files.user.contains("Users." + p.getName())){
        Files.saveFiles();
        if(manager.isInPvP(p)){
            p.setHealth(0D);
            Bukkit.broadcastMessage(Utils.colorize(PAData.SURVIVAL.getPrefix() + ChatColor.GRAY + " ¡" + ChatColor.GOLD + p.getName() + ChatColor.GREEN + " se ha desconectado en combate!"));
        }
    }
    PASurvival.players.remove(u);
}
 
开发者ID:cadox8,项目名称:PA,代码行数:15,代码来源:PlayerEvents.java


注:本文中的org.bukkit.entity.Player.setHealth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。