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


Java Player.getHealth方法代码示例

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


在下文中一共展示了Player.getHealth方法的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: call

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@Override
public void call(Event event) {
	if (event instanceof EntityDamageEvent) {
		final EntityDamageEvent ede = (EntityDamageEvent) event;
		final DamageCause cause = ede.getCause();

		if (cause == DamageCause.FIRE || cause == DamageCause.CONTACT) {
			final Player player = profile.getPlayer();

			if (cause == DamageCause.FIRE && player.getFoodLevel() < 20) {
				// The AntiFire cheat only works when the hunger bar is
				// full.
				return;
			}

			final double previousHealth = player.getHealth();

			// Check a little later.
			Bukkit.getScheduler().runTaskLater(Crescent.getInstance(), () -> {
				if (player.getHealth() > previousHealth - ede.getDamage()) {
					callback(true);
				}
			}, 2L);
		}
	}
}
 
开发者ID:davidm98,项目名称:Crescent,代码行数:27,代码来源:AntiDamageA.java

示例3: onEntityDamage

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
    if(event.getCause() == EntityDamageEvent.DamageCause.CUSTOM) return;
    if(Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().getGameState() != GameState.INGAME) {
        event.setCancelled(true);
    } else {
        if(!Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().getCurrentGame().allowPVP) event.setCancelled(true);
    }
    if(!event.isCancelled() && event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();
        if((player.getHealth()-event.getDamage()) <= 0) {
            event.setDamage(0);
            if(Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().isAlive(player)) {
                Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().setAlive(player, false);
            }
        }
    }
}
 
开发者ID:ArcadiaPlugins,项目名称:Arcadia-Spigot,代码行数:19,代码来源:DamageListener.java

示例4: checkRegen

import org.bukkit.entity.Player; //导入方法依赖的package包/类
public boolean checkRegen(Player player) {
    long l = lastHeal.containsKey(player)?lastHeal.get(player):System.currentTimeMillis() - (MagicNumbers
            .HEAL_TIME_MIN + 10);
    if(System.currentTimeMillis() - l >= MagicNumbers.HEAL_RESET) {
        lastHeal.remove(player);
        l = System.currentTimeMillis() - (MagicNumbers.HEAL_TIME_MIN + 10);
    }
    if (((System.currentTimeMillis() - l) < MagicNumbers.HEAL_TIME_MIN) && player.getWorld().getDifficulty() !=
            Difficulty.PEACEFUL) {
        for(Player pla : DynamicAC.instance.onlinestaff) {
            pla.sendMessage(DynamicAC.prefix + player.getName() + " failed Regen check!");
        }
        for(double i = player.getHealth(); i < player.getMaxHealth() && player.isOnline(); i += 1) {
            DACManager.getUserManager().incrementUser(DACManager.getUserManager().getUser(player.getName()),
                    "Regen");
        }
        player.damage(1.0);
        return true;
    }
    logHeal(player);
    return false;
}
 
开发者ID:Notoh,项目名称:DynamicAC,代码行数:23,代码来源:BackendChecks.java

示例5: onPlayerKillsPlayer

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler
public void onPlayerKillsPlayer(EntityDamageByEntityEvent e) {
	if (!(e.getDamager() instanceof Player) || !(e.getEntity() instanceof Player))
		return;

	Player killer = (Player) e.getDamager();
	Player target = (Player) e.getEntity();

	// Check if the target is dead
	if (target.getHealth() - e.getDamage() <= 0) {
		PlayerObject killerObject = main.getPlayerManager().getMortuusPlayer(killer.getUniqueId());

		// Sets the time in SECONDS.
		killerObject.setLastPlayerKillTime(System.currentTimeMillis() / 1000);
		killerObject.addPlayerKills(1);

		for (PKStates state : PKStates.values()) {
			if (killerObject.getPlayerKills() == state.getRequiredKills()) {
				killerObject.setPkState(state);
				main.getScoreboards().switchTeam(killer, state.name());
				break;
			}
		}
	}
}
 
开发者ID:kadeska,项目名称:MT_Core,代码行数:26,代码来源:PlayerListener.java

示例6: 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

示例7: run

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@Override
public void run() {
    if(ConfigPatch.noFakedeath){
        List<Player> players = AzurePlayerList.players();
        int ps = players.size();
        for(int i = 0;i<ps;i++){
            Player player = players.get(i);
            if(player.getHealth() <= 0 && !player.isDead()){
                player.setHealth(0.0);
                player.kickPlayer(ConfigPatch.messageFakedeath);
            }
        }
    }
}
 
开发者ID:GelandiAssociation,项目名称:EscapeLag,代码行数:15,代码来源:AntiFakeDeath.java

示例8: LoggerEntity

import org.bukkit.entity.Player; //导入方法依赖的package包/类
public LoggerEntity(Plugin plugin, Player player) {
    this.plugin = plugin;
    this.uuid = player.getUniqueId();
    this.name = player.getName();
    this.health = player.getHealth();
    this.contents = player.getInventory().getContents();
    this.armour = player.getInventory().getArmorContents();
    this.world = player.getWorld();

    this.villager = (Villager) this.world.spawnEntity(player.getLocation(), EntityType.VILLAGER);
    this.villager.setCustomName(this.name);
    this.villager.setHealth(this.health);

    this.resetTimer();
}
 
开发者ID:ijoeleoli,项目名称:LoggerAPI,代码行数:16,代码来源:LoggerEntity.java

示例9: updateMonitoredHealth

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void updateMonitoredHealth(final EntityRegainHealthEvent event) {
    if(event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();
        if(player.getHealth() == player.getMaxHealth()) return;
        this.scheduleCheck((Player) event.getEntity());
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:9,代码来源:ViewInventoryMatchModule.java

示例10: customDeathNonPlayerFallback

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.LOWEST)
public void customDeathNonPlayerFallback(EntityDamageEvent e){
	if(e.getCause().equals(DamageCause.FALL)) return;
	if(e.getEntity() instanceof Player){
		Player p = (Player) e.getEntity();
		if(e.getCause().equals(DamageCause.ENTITY_ATTACK)){
			// no need to do anything here, this part is controlled in the customDeath method
		}else{
			if(e.getFinalDamage() >= p.getHealth()){
				e.setCancelled(true);
				Bukkit.getServer().broadcastMessage(ChatColor.GRAY + p.getName() + " died");
				// Set statistics
				//p.setStatistic(Statistic.DEATHS, p.getStatistic(Statistic.DEATHS) + 1);
				// Reset health, so they dont die
				p.setHealth(p.getMaxHealth());
				// Inventory clearing
				p.getInventory().clear();
				ItemStack air = new ItemStack(Material.AIR);
				p.getInventory().setHelmet(air);
				p.getInventory().setChestplate(air);
				p.getInventory().setLeggings(air);
				p.getInventory().setBoots(air);
				// Clear potion effects
				for(PotionEffect pe : p.getActivePotionEffects()){
					p.removePotionEffect(pe.getType());
				}
				// Stop infinite kill glitch
				p.setGameMode(GameMode.SPECTATOR);
				p.setGameMode(GameMode.ADVENTURE);
				// send them to the SPAWN of the world
				p.teleport(p.getWorld().getSpawnLocation());
				p.setFireTicks(0);
			}
		}
	}
}
 
开发者ID:OverloadedCore,项目名称:kaosEssentials,代码行数:37,代码来源:Core.java

示例11: storeTemporaryInventory

import org.bukkit.entity.Player; //导入方法依赖的package包/类
void storeTemporaryInventory(Player player) {
    final TemporaryPlayerStorage storage = new TemporaryPlayerStorage();
    storage.armorContent = player.getInventory().getArmorContents().clone();
    storage.isFlying = player.getAllowFlight();
    storage.inventory = player.getInventory().getContents().clone();
    storage.gameMode = player.getGameMode();
    storage.level = player.getLevel();
    storage.exp = player.getExp();
    storage.health = player.getHealth();
    storage.foodLevel = player.getFoodLevel();
    storage.scoreboard = player.getScoreboard();
    this.temporaryStorage.put(player, storage);
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:14,代码来源:HelperGameEntity.java

示例12: 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

示例13: updatePlayerScoreboard

import org.bukkit.entity.Player; //导入方法依赖的package包/类
public static void updatePlayerScoreboard(Player player){
//        Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
//        Objective o = scoreboard.registerNewObjective("status","");
//        o.setDisplaySlot(DisplaySlot.SIDEBAR);
//        o.setDisplayName(ChatColor.GREEN + "状态");
//
//        //血量显示
//        Score healthScore = o.getScore(ChatColor.RED + "血量:");
//        healthScore.setScore((int) (player.getHealth() + 0.5));
//
//        //升级所需经验显示
//        Score expToLevelScore = o.getScore(ChatColor.GREEN + "升级所需经验:");
//        expToLevelScore.setScore((int) (player.getExpToLevel() - player.getExp()));
//
//
//        //用户到服务器ping值
//        Score pingScore = o.getScore(ChatColor.AQUA + "延迟(ms):");
//        pingScore.setScore(((CraftPlayer)player).getHandle().ping);
//
//
//        player.setScoreboard(scoreboard);
        String[] scoresLayout = new String[6];
        scoresLayout[0] = ChatColor.GREEN + "状态";
        scoresLayout[1] = "";
        scoresLayout[2] = ChatColor.RED + "血量: " + (int) (player.getHealth() + 0.5);
        scoresLayout[3] = ChatColor.GREEN + "升级所需经验: " + (int) (player.getExpToLevel() - player.getExp());
        scoresLayout[4] = ChatColor.AQUA + "延迟: " + ((CraftPlayer)player).getHandle().ping + "ms";
        scoresLayout[5] = "";
        ScoreboardUtil.unrankedSidebarDisplay(player,scoresLayout);
    }
 
开发者ID:kncxstudio,项目名称:BasicSurvivalPlus,代码行数:31,代码来源:ScoreboardHelper.java

示例14: show

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static void show(VPPlayer player) {
	Player p = player.getPlayer();
	Object nmsPlay = getNMSPlayer(p);
	Object arrayPlayer = ReflectionUtils.getArrayOf(nmsPlayer, nmsPlay);
	final ReflectionObject add = PacketUtils.craftPacket(PacketPlayOutPlayerInfo, addPlayerEnum.getClass(), arrayPlayer.getClass())
			.instance(addPlayerEnum, arrayPlayer);
	Object difficulty = ReflectionUtils.invoke(getDifficulty, enumDifficulty, player.getLocation().getWorld().getDifficulty().getValue());
	Object type = ReflectionUtils.invoke("getType", worldType, player.getLocation().getWorld().getWorldType().getName());
	Object gamemode = ReflectionUtils.invoke(getGamemode, enumGamemode, player.getGameMode().getValue());
	final ReflectionObject respawn = PacketUtils.craftPacket(PacketPlayOutRespawn, int.class, difficulty.getClass(), type.getClass(), gamemode.getClass())
			.instance(0, difficulty, type, gamemode);
	boolean flying = p.isFlying();
	Location location = player.getLocation();
	int level = player.getLevel();
	float xp = p.getExp();
	double maxHealth = p.getMaxHealth();
	double health = p.getHealth();
	PacketUtils.sendPacket(respawn, player);        
	p.setFlying(flying);
	player.teleport(location);
	p.updateInventory();
	player.setLevel(level);
	p.setExp(xp);
	p.setMaxHealth(maxHealth);
	p.setHealth(health);
	for(VPPlayer vp : VanillaPlusCore.getPlayerManager().getOnlinePlayers())
		PacketUtils.sendPacket(add, vp);
}
 
开发者ID:dracnis,项目名称:VanillaPlus,代码行数:30,代码来源:CraftPlayerUtils.java

示例15: updateSelf

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static void updateSelf(VPPlayer player){
	Player p = player.getPlayer();
	Object nmsPlay = getNMSPlayer(p);
	Object arrayPlayer = ReflectionUtils.getArrayOf(nmsPlayer, nmsPlay);
	ReflectionObject del = PacketUtils.craftPacket(PacketPlayOutPlayerInfo, removePlayerEnum.getClass(), arrayPlayer.getClass())
			.instance(removePlayerEnum, arrayPlayer);
	final ReflectionObject add = PacketUtils.craftPacket(PacketPlayOutPlayerInfo, addPlayerEnum.getClass(), arrayPlayer.getClass())
			.instance(addPlayerEnum, arrayPlayer);
	Object difficulty = ReflectionUtils.invoke(getDifficulty, enumDifficulty, player.getLocation().getWorld().getDifficulty().getValue());
	Object type = ReflectionUtils.invoke("getType", worldType, player.getLocation().getWorld().getWorldType().getName());
	Object gamemode = ReflectionUtils.invoke(getGamemode, enumGamemode, player.getGameMode().getValue());
	final ReflectionObject respawn = PacketUtils.craftPacket(PacketPlayOutRespawn, int.class, difficulty.getClass(), type.getClass(), gamemode.getClass())
			.instance(0, difficulty, type, gamemode);
	PacketUtils.sendPacket(del, player);
	boolean flying = p.isFlying();
	Location location = player.getLocation();
	int level = player.getLevel();
	float xp = p.getExp();
	double maxHealth = p.getMaxHealth();
	double health = p.getHealth();
	PacketUtils.sendPacket(respawn, player);        
	p.setFlying(flying);
	player.teleport(location);
	p.updateInventory();
	player.setLevel(level);
	p.setExp(xp);
	p.setMaxHealth(maxHealth);
	p.setHealth(health);
	PacketUtils.sendPacket(add, player);
}
 
开发者ID:dracnis,项目名称:VanillaPlus,代码行数:32,代码来源:CraftPlayerUtils.java


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