下面列出了org.bukkit.entity.Player#getMaxHealth ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void damageHandler(EntityDamageByEntityEvent event)
{
if(event.getDamager().getType() == EntityType.PLAYER)
{
Player player = (Player)event.getDamager();
AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
if(p != null && p.getKit().equals(this))
{
if(rand.nextInt(3) == 1)
{
double health = player.getHealth()+1D;
if(health > player.getMaxHealth())
health = player.getMaxHealth();
player.setHealth(health);
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onRegainHealth(EntityRegainHealthEvent rhe) {
if (rhe.getEntityType() != EntityType.PLAYER) {
return;
}
Player player = (Player) rhe.getEntity();
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
if (game == null) {
return;
}
if (game.getState() != GameState.RUNNING) {
return;
}
if (player.getHealth() >= player.getMaxHealth()) {
game.setPlayerDamager(player, null);
}
}
@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());
}
}
@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());
}
}
@EventHandler (priority = EventPriority.HIGHEST)
public void onPlayerDamage(EntityDamageEvent e){
if (e.isCancelled()){
return;
}
if (e.getDamage() < 0.2){
return;
}
if (!(e.getEntity() instanceof Player)){
return;
}
Player p = (Player) e.getEntity();
UhcPlayer uhcPlayer = GameManager.getGameManager().getPlayersManager().getUhcPlayer(p);
if (!pveList.containsKey(uhcPlayer)){
return; // Only playing players on list
}
if (pveList.get(uhcPlayer)) {
pveList.put(uhcPlayer, false);
uhcPlayer.sendMessage(Lang.SCENARIO_BESTPVE_REMOVED);
}
if (p.getMaxHealth() > maxHealth){
double hp = p.getHealth();
if (hp < maxHealth){
p.setMaxHealth(maxHealth);
}else{
p.setMaxHealth(hp + 1);
}
}
}
@Override
public void run(){
for (UhcPlayer uhcPlayer : GameManager.getGameManager().getPlayersManager().getOnlinePlayingPlayers()){
Player player;
try{
player = uhcPlayer.getPlayer();
}catch (UhcPlayerNotOnlineException ex){
continue; // No hp for offline players
}
if (!pveList.containsKey(uhcPlayer)){
pveList.put(uhcPlayer,true); // Should never occur, playing players are always on list.
Bukkit.getLogger().warning("[UhcCore] " + player.getName() + " was not on best PvE list yet! Please contact a server administrator.");
}
if (player.getGameMode().equals(GameMode.SURVIVAL) && pveList.get(uhcPlayer)){
// heal player
if (player.getHealth() + 2 > player.getMaxHealth()){
player.setMaxHealth(player.getMaxHealth() + 2);
}
player.setHealth(player.getHealth() + 2);
}
}
taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(UhcCore.getPlugin(),this,delay*TimeUtils.SECOND_TICKS);
}
@EventHandler(priority = EventPriority.MONITOR)
public void damageListener(final EntityDamageByEntityEvent event)
{
if(event.getEntity().getType() == EntityType.PLAYER && event.getDamager().getType() == EntityType.PLAYER)
{
Player one = (Player)event.getDamager();
AnniPlayer p = AnniPlayer.getPlayer(one.getUniqueId());
if(p != null && p.getKit().equals(this))
{
if((one.getHealth() / one.getMaxHealth()) <= .42)
event.setDamage(event.getDamage()+1);
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void damageListener(final PlayerDeathEvent event)
{
Player killer = event.getEntity().getKiller();
if(killer != null)
{
AnniPlayer p = AnniPlayer.getPlayer(killer.getUniqueId());
if(p != null && p.getKit().equals(this))
{
if(killer.getMaxHealth() <= 24)
killer.setMaxHealth(killer.getMaxHealth()+2);
}
}
}
PWIPlayer(Player player, Group group, double bankBalance, double balance, boolean useAttributes) {
this.uuid = player.getUniqueId();
this.name = player.getName();
this.location = player.getLocation();
this.group = group;
this.saved = false;
this.armor = player.getInventory().getArmorContents();
this.enderChest = player.getEnderChest().getContents();
this.inventory = player.getInventory().getContents();
this.canFly = player.getAllowFlight();
this.displayName = player.getDisplayName();
this.exhaustion = player.getExhaustion();
this.experience = player.getExp();
this.isFlying = player.isFlying();
this.foodLevel = player.getFoodLevel();
if (useAttributes) {
this.maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
} else {
this.maxHealth = player.getMaxHealth();
}
this.health = player.getHealth();
this.gamemode = player.getGameMode();
this.level = player.getLevel();
this.saturationLevel = player.getSaturation();
this.potionEffects = player.getActivePotionEffects();
this.fallDistance = player.getFallDistance();
this.fireTicks = player.getFireTicks();
this.maxAir = player.getMaximumAir();
this.remainingAir = player.getRemainingAir();
this.bankBalance = bankBalance;
this.balance = balance;
}
PWIPlayer(Player player, Group group, double bankBalance, double balance, boolean useAttributes) {
this.uuid = player.getUniqueId();
this.name = player.getName();
this.location = player.getLocation();
this.group = group;
this.saved = false;
this.armor = player.getInventory().getArmorContents();
this.enderChest = player.getEnderChest().getContents();
this.inventory = player.getInventory().getContents();
this.canFly = player.getAllowFlight();
this.displayName = player.getDisplayName();
this.exhaustion = player.getExhaustion();
this.experience = player.getExp();
this.isFlying = player.isFlying();
this.foodLevel = player.getFoodLevel();
if (useAttributes) {
this.maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
} else {
this.maxHealth = player.getMaxHealth();
}
this.health = player.getHealth();
this.gamemode = player.getGameMode();
this.level = player.getLevel();
this.saturationLevel = player.getSaturation();
this.potionEffects = player.getActivePotionEffects();
this.fallDistance = player.getFallDistance();
this.fireTicks = player.getFireTicks();
this.maxAir = player.getMaximumAir();
this.remainingAir = player.getRemainingAir();
this.bankBalance = bankBalance;
this.balance = balance;
}
@Override
public void run() {
for (World world : Bukkit.getServer().getWorlds()) {
for (Player player : world.getPlayers()) {
if (player.isDead()) {
continue;
}
final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
// send queued visuals
int count = 0;
final Iterator<BlockSnapshot> iterator = playerData.queuedVisuals.iterator();
while (iterator.hasNext()) {
final BlockSnapshot snapshot = iterator.next();
if (count > GriefDefenderPlugin.getGlobalConfig().getConfig().visual.clientVisualsPerTick) {
break;
}
NMSUtil.getInstance().sendBlockChange(player, snapshot);
iterator.remove();
count++;
}
// chat capture
playerData.updateRecordChat();
// health regen
if (world.getFullTime() % 100 == 0L) {
final GameMode gameMode = player.getGameMode();
// Handle player health regen
if (gameMode != GameMode.CREATIVE && gameMode != GameMode.SPECTATOR && GDOptions.isOptionEnabled(Options.PLAYER_HEALTH_REGEN)) {
final double maxHealth = player.getMaxHealth();
if (player.getHealth() < maxHealth) {
final double regenAmount = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), playerData.getSubject(), Options.PLAYER_HEALTH_REGEN, claim);
if (regenAmount > 0) {
final double newHealth = player.getHealth() + regenAmount;
if (newHealth > maxHealth) {
player.setHealth(maxHealth);
} else {
player.setHealth(newHealth);
}
}
}
}
}
// teleport delay
if (world.getFullTime() % 20 == 0L) {
if (playerData.teleportDelay > 0) {
final int delay = playerData.teleportDelay - 1;
if (delay == 0) {
playerData.teleportDelay = 0;
player.teleport(playerData.teleportLocation);
playerData.teleportLocation = null;
playerData.teleportSourceLocation = null;
continue;
}
TextAdapter.sendComponent(player, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.TELEPORT_DELAY_NOTICE,
ImmutableMap.of("delay", TextComponent.of(delay, TextColor.GOLD))));
playerData.teleportDelay = delay;
}
}
}
}
}