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

The following examples show how to use org.bukkit.entity.Player#isDead() . 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: MatchImpl.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public MatchPlayer addPlayer(Player bukkit) {
  MatchPlayer player = players.get(bukkit.getUniqueId());
  if (player == null) {
    logger.fine("Adding player " + bukkit);

    // If the bukkit player is dead, force them back into the world
    if (bukkit.isDead()) {
      bukkit.leaveVehicle();
      bukkit.spigot().respawn();
    }

    player = new MatchPlayerImpl(this, bukkit);
    MatchPlayerAddEvent event = new MatchPlayerAddEvent(player, getDefaultParty());
    callEvent(event);

    setParty(player, event.getInitialParty());
  }
  return player;
}
 
Example 2
Source File: Autorepair.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
	PlayerMoveEvent event = (PlayerMoveEvent) e;
	Player owner = event.getPlayer();

	
	if(owner != null && owner.isOnline() && !owner.isDead()) {
		if(healFully)
			item.setDurability((short) 0);
		else {
			int newDur = item.getDurability() - ( 1 + (healAmount*level));
			
			if(newDur > 0)
				item.setDurability((short) newDur);
			else
				item.setDurability((short) 0);
		}
	}
}
 
Example 3
Source File: ArmorTask.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    for (Player p : Bukkit.getOnlinePlayers()) {
        if (!p.isValid() || p.isDead()) {
            continue;
        }

        PlayerProfile.get(p, profile -> {
            ItemStack[] armor = p.getInventory().getArmorContents();
            HashedArmorpiece[] cachedArmor = profile.getArmor();

            handleSlimefunArmor(p, armor, cachedArmor);

            if (hasSunlight(p)) {
                checkForSolarHelmet(p);
            }

            checkForRadiation(p);
        });
    }
}
 
Example 4
Source File: Civilian.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
public boolean isInCombat() {
    if (lastDamage < 0) {
        return false;
    }
    Player player = Bukkit.getPlayer(uuid);
    if (player == null || player.isDead()) {
        lastDamager = null;
        lastDamage = -1;
        return false;
    }
    if (lastDamager != null && (Bukkit.getPlayer(lastDamager) == null ||
            Bukkit.getPlayer(lastDamager).isDead())) {
        lastDamager = null;
        lastDamage = -1;
        return false;
    }
    int combatTagDuration = ConfigManager.getInstance().getCombatTagDuration();
    combatTagDuration *= 1000;
    if (lastDamage + combatTagDuration < System.currentTimeMillis()) {
        lastDamager = null;
        lastDamage = -1;
        return false;
    }
    return true;
}
 
Example 5
Source File: GriefDefenderPlugin.java    From GriefDefender with MIT License 5 votes vote down vote up
private void cleanup() {
    for (BukkitRunnable task : this.runningTasks) {
        task.cancel();
    }
    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());
            playerData.onDisconnect();
        }
    }
}
 
Example 6
Source File: CombatLogTracker.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerDamage(EntityDamageEvent event) {
  if (event.getDamage() <= 0) return;

  if (!(event.getEntity() instanceof Player)) return;
  Player player = (Player) event.getEntity();

  if (player.getGameMode() == GameMode.CREATIVE) return;

  if (player.isDead()) return;

  if (player.getNoDamageTicks() > 0) return;

  if (getResistanceFactor(player) <= 0) return;

  switch (event.getCause()) {
    case ENTITY_EXPLOSION:
    case BLOCK_EXPLOSION:
    case CUSTOM:
    case FALL:
    case FALLING_BLOCK:
    case LIGHTNING:
    case MELTING:
    case SUICIDE:
    case THORNS:
      return; // Skip damage causes that are not particularly likely to be followed by more damage

    case FIRE:
    case FIRE_TICK:
    case LAVA:
      if (hasFireResistance(player)) return;
      break;
  }

  // Record the player's damage with a timestamp
  this.recentDamage.put(player, new Damage(Instant.now(), event));
}
 
Example 7
Source File: CombatLogTracker.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerDamage(EntityDamageEvent event) {
    if(event.getDamage() <= 0) return;

    if(!(event.getEntity() instanceof Player)) return;
    Player player = (Player) event.getEntity();

    if(player.getGameMode() == GameMode.CREATIVE) return;

    if(player.isDead()) return;

    if(player.getNoDamageTicks() > 0) return;

    if(getResistanceFactor(player) <= 0) return;

    switch(event.getCause()) {
        case ENTITY_EXPLOSION:
        case BLOCK_EXPLOSION:
        case CUSTOM:
        case FALL:
        case FALLING_BLOCK:
        case LIGHTNING:
        case MELTING:
        case SUICIDE:
        case THORNS:
            return; // Skip damage causes that are not particularly likely to be followed by more damage

        case FIRE:
        case FIRE_TICK:
        case LAVA:
            if(hasFireResistance(player)) return;
            break;
    }

    // Record the player's damage with a timestamp
    this.recentDamage.put(player, new Damage(Instant.now(), event));
}
 
Example 8
Source File: GDClaim.java    From GriefDefender with MIT License 5 votes vote down vote up
@Override
public List<UUID> getPlayers() {
    Collection<Player> worldPlayerList = Bukkit.getServer().getWorld(this.world.getUID()).getPlayers();
    List<UUID> playerList = new ArrayList<>();
    for (Player player : worldPlayerList) {
        if (!player.isDead() && this.contains(VecHelper.toVector3i(player.getLocation()))) {
            playerList.add(player.getUniqueId());
        }
    }

    return playerList;
}
 
Example 9
Source File: Game.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public Team isOver() {
  if (this.isOver || this.state != GameState.RUNNING) {
    return null;
  }

  ArrayList<Player> players = this.getTeamPlayers();
  ArrayList<Team> teams = new ArrayList<>();

  if (players.size() == 0 || players.isEmpty()) {
    return null;
  }

  for (Player player : players) {
    Team playerTeam = this.getPlayerTeam(player);
    if (teams.contains(playerTeam)) {
      continue;
    }

    if (!player.isDead()) {
      teams.add(playerTeam);
    } else if (!playerTeam.isDead(this)) {
      teams.add(playerTeam);
    }
  }

  if (teams.size() == 1) {
    return teams.get(0);
  } else {
    return null;
  }
}
 
Example 10
Source File: BungeeGameCycle.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPlayerLeave(Player player) {
  if (player.isOnline() || player.isDead()) {
    this.bungeeSendToServer(BedwarsRel.getInstance().getBungeeHub(), player, true);
  }

  if (this.getGame().getState() == GameState.RUNNING && !this.getGame().isStopping()) {
    this.checkGameOver();
  }
}
 
Example 11
Source File: Util.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public boolean isBusy(UUID uuid) {
      Player player = SkyWarsReloaded.get().getServer().getPlayer(uuid);

      if (player == null) {
      	return true;
      }
      
      if (player.isDead()) {
      	return true;
      }
      
  	if (MatchManager.get().isSpectating(player)) {
  		return true;
  	}
  	
  	boolean allowed = false;
  	for (String world: SkyWarsReloaded.getCfg().getLobbyWorlds()) {
  		if (world.equalsIgnoreCase(player.getWorld().getName())) {
  			allowed = true;
  		}
  	}

  	if (!allowed) {
  		return true;
  	}
      
PlayerStat ps = PlayerStat.getPlayerStats(player);
if (ps == null) {
	PlayerStat.getPlayers().add(new PlayerStat(player));
	return true;
} else return !ps.isInitialized();
  }
 
Example 12
Source File: TheHangingGardens.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onUpdate() {
	super.onUpdate();
	
	for (Town t : this.getTown().getCiv().getTowns()) {
		for (Resident res : t.getResidents()) {
			try {
				Player player = CivGlobal.getPlayer(res);
				
				if (player.isDead() || !player.isValid()) {
					continue;
				}
				
				if (player.getHealth() >= 20) {
					continue;
				}
				
				TownChunk tc = CivGlobal.getTownChunk(player.getLocation());
				if (tc == null || tc.getTown() != this.getTown()) {
					continue;
				}
				
				if (player.getHealth() >= 19.0) {
					player.setHealth(20);
				} else {
					player.setHealth(player.getHealth() + 1);
				}
			} catch (CivException e) {
				//Player not online;
			}
			
		}
	}
}
 
Example 13
Source File: CommandHandler.java    From NyaaUtils with MIT License 4 votes vote down vote up
@SubCommand(value = "tpall", permission = "nu.tpall")
public void tpall(CommandSender sender, Arguments args) {
    Player p = asPlayer(sender);
    int r = args.nextInt();
    Block center = p.getLocation().getBlock();
    int minX = center.getX() - r;
    int minZ = center.getZ() - r;
    int maxX = center.getX() + r;
    int maxZ = center.getZ() + r;
    int maxY = center.getY() + 1;
    List<Location> locations = new ArrayList<>();
    int playerCount = Bukkit.getOnlinePlayers().size() - 1;
    for (int x = minX; x <= maxX; x++) {
        for (int z = minZ; z <= maxZ; z++) {
            for (int i = 0; i <= 16; i++) {
                Block b = p.getWorld().getBlockAt(x, maxY - i, z);
                if (b.getType().isSolid()) {
                    Block b2 = b.getRelative(BlockFace.UP, 1);
                    Block b3 = b.getRelative(BlockFace.UP, 2);
                    if ((b2.isEmpty() || b2.isPassable()) && (b3.isEmpty() || b3.isPassable()) && !b2.isLiquid() && !b3.isLiquid()) {
                        Location loc = b.getBoundingBox().getCenter().toLocation(b.getWorld());
                        loc.setY(b.getBoundingBox().getMaxY());
                        locations.add(loc.clone());
                        break;
                    }
                }
            }
        }
    }
    if (locations.size() < playerCount) {
        msg(sender, "user.tpall.error");
        return;
    }
    Collections.shuffle(locations);
    int success = 0;
    for (Player player : Bukkit.getOnlinePlayers()) {
        if (!player.isDead() && player.getUniqueId() != p.getUniqueId()) {
            if (player.getWorld() == p.getWorld() && player.getLocation().distance(p.getLocation()) + 3 <= r) {
                continue;
            }
            Location old = player.getLocation().clone();
            if (player.teleport(locations.get(success))) {
                success++;
                plugin.ess.getUser(player).setLastLocation(old);
            }
        }
    }
    msg(sender, "user.tpall.success", success);
}
 
Example 14
Source File: VaultOperations.java    From PlayerVaults with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Open another player's vault.
 *
 * @param player     The player to open to.
 * @param vaultOwner The name of the vault owner.
 * @param arg        The vault number to open.
 * @return Whether or not the player was allowed to open it.
 */
public static boolean openOtherVault(Player player, String vaultOwner, String arg) {
    if (isLocked()) {
        return false;
    }

    if (player.isSleeping() || player.isDead() || !player.isOnline()) {
        return false;
    }

    long time = System.currentTimeMillis();

    int number = 0;
    try {
        number = Integer.parseInt(arg);
        if (number < 1) {
            player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
            return false;
        }
    } catch (NumberFormatException nfe) {
        player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
    }

    Inventory inv = VaultManager.getInstance().loadOtherVault(vaultOwner, number, getMaxVaultSize(vaultOwner));
    String name = vaultOwner;
    try {
        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(vaultOwner));
        name = offlinePlayer.getName();
    } catch (Exception e) {
        // not a player
    }

    if (inv == null) {
        player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
    } else {
        player.openInventory(inv);

        // Check if the inventory was actually opened
        if (player.getOpenInventory().getTopInventory() instanceof CraftingInventory || player.getOpenInventory().getTopInventory() == null) {
            PlayerVaults.debug(String.format("Cancelled opening vault %s for %s from an outside source.", arg, player.getName()));
            return false; // inventory open event was cancelled.
        }
        player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_OTHER_VAULT.toString().replace("%v", arg).replace("%p", name));
        PlayerVaults.debug("opening other vault", time);

        // Need to set ViewInfo for a third party vault for the opening player.
        VaultViewInfo info = new VaultViewInfo(vaultOwner, number);
        PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), info);
        PlayerVaults.getInstance().getOpenInventories().put(player.getUniqueId().toString(), inv);
        return true;
    }

    PlayerVaults.debug("opening other vault returning false", time);
    return false;
}
 
Example 15
Source File: VaultOperations.java    From PlayerVaults with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Open a player's own vault.
 *
 * @param player The player to open to.
 * @param arg    The vault number to open.
 * @return Whether or not the player was allowed to open it.
 */
public static boolean openOwnVault(Player player, String arg) {
    if (isLocked()) {
        return false;
    }
    if (player.isSleeping() || player.isDead() || !player.isOnline()) {
        return false;
    }
    int number;
    try {
        number = Integer.parseInt(arg);
        if (number < 1) {
            return false;
        }
    } catch (NumberFormatException nfe) {
        player.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER.toString());
        return false;
    }

    if (checkPerms(player, number)) {
        if (EconomyOperations.payToOpen(player, number)) {
            Inventory inv = VaultManager.getInstance().loadOwnVault(player, number, getMaxVaultSize(player));
            if (inv == null) {
                PlayerVaults.debug(String.format("Failed to open null vault %d for %s. This is weird.", number, player.getName()));
                return false;
            }

            player.openInventory(inv);

            // Check if the inventory was actually opened
            if (player.getOpenInventory().getTopInventory() instanceof CraftingInventory || player.getOpenInventory().getTopInventory() == null) {
                PlayerVaults.debug(String.format("Cancelled opening vault %s for %s from an outside source.", arg, player.getName()));
                return false; // inventory open event was cancelled.
            }

            VaultViewInfo info = new VaultViewInfo(player.getUniqueId().toString(), number);
            PlayerVaults.getInstance().getOpenInventories().put(info.toString(), inv);

            player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_VAULT.toString().replace("%v", arg));
            return true;
        } else {
            player.sendMessage(Lang.TITLE.toString() + Lang.INSUFFICIENT_FUNDS);
            return false;
        }
    } else {
        player.sendMessage(Lang.TITLE.toString() + Lang.NO_PERMS);
    }
    return false;
}
 
Example 16
Source File: CombatLogTracker.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Get the cause of the player's imminent death, or null if they are not about to die
 * NOTE: not idempotent, has the side effect of clearing the recentDamage cache
 */
public @Nullable ImminentDeath getImminentDeath(Player player) {
    // If the player is already dead or in creative mode, we don't care
    if(player.isDead() || player.getGameMode() == GameMode.CREATIVE) return null;

    // If the player was on the ground, or is flying, or is able to fly, they are fine
    if(!(player.isOnGround() || player.isFlying() || player.getAllowFlight())) {
        // If the player is falling, detect an imminent falling death
        double fallDistance = player.getFallDistance();
        Block landingBlock = null;
        int waterDepth = 0;
        Location location = player.getLocation();

        if(location.getY() > 256) {
            // If player is above Y 256, assume they fell at least to there
            fallDistance += location.getY() - 256;
            location.setY(256);
        }

        // Search the blocks directly beneath the player until we find what they would have landed on
        Block block = null;
        for(; location.getY() >= 0; location.add(0, -1, 0)) {
            block = location.getBlock();
            if(block != null) {
                landingBlock = block;

                if(Materials.isWater(landingBlock.getType())) {
                    // If the player falls through water, reset fall distance and inc the water depth
                    fallDistance = -1;
                    waterDepth += 1;

                    // Break if they have fallen through enough water to stop falling
                    if(waterDepth >= BREAK_FALL_WATER_DEPTH) break;
                } else {
                    // If the block is not water, reset the water depth
                    waterDepth = 0;

                    if(Materials.isColliding(landingBlock.getType()) || Materials.isLava(landingBlock.getType())) {
                        // Break if the player hits a solid block or lava
                        break;
                    } else if(landingBlock.getType() == Material.WEB) {
                        // If they hit web, reset their fall distance, but assume they keep falling
                        fallDistance = -1;
                    }
                }
            }

            fallDistance += 1;
        }

        double resistanceFactor = getResistanceFactor(player);
        boolean fireResistance = hasFireResistance(player);

        // Now decide if the landing would have killed them
        if(location.getBlockY() < 0) {
            // The player would have fallen into the void
            return new ImminentDeath(EntityDamageEvent.DamageCause.VOID, location, null, false);
        } else if(landingBlock != null) {
            if(Materials.isColliding(landingBlock.getType()) && player.getHealth() <= resistanceFactor * (fallDistance - SAFE_FALL_DISTANCE)) {
                // The player would have landed on a solid block and taken enough fall damage to kill them
                return new ImminentDeath(EntityDamageEvent.DamageCause.FALL, landingBlock.getLocation().add(0, 0.5, 0), null, false);
            } else if (Materials.isLava(landingBlock.getType()) && resistanceFactor > 0 && !fireResistance) {
                // The player would have landed in lava, and we give the lava the benefit of the doubt
                return new ImminentDeath(EntityDamageEvent.DamageCause.LAVA, landingBlock.getLocation(), landingBlock, false);
            }
        }
    }

    // If we didn't predict a falling death, detect combat log due to recent damage
    Damage damage = this.recentDamage.remove(player);
    if(damage != null && damage.time.plus(RECENT_DAMAGE_THRESHOLD).isAfter(Instant.now())) {
        // Player logged out too soon after taking damage
        return new ImminentDeath(damage.event.getCause(), player.getLocation(), null, true);
    }

    return null;
}
 
Example 17
Source File: CombatLogTracker.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Get the cause of the player's imminent death, or null if they are not about to die NOTE: not
 * idempotent, has the side effect of clearing the recentDamage cache
 */
public @Nullable ImminentDeath getImminentDeath(Player player) {
  // If the player is already dead or in creative mode, we don't care
  if (player.isDead() || player.getGameMode() == GameMode.CREATIVE) return null;

  // If the player was on the ground, or is flying, or is able to fly, they are fine
  if (!(player.isOnGround() || player.isFlying() || player.getAllowFlight())) {
    // If the player is falling, detect an imminent falling death
    double fallDistance = player.getFallDistance();
    Block landingBlock = null;
    int waterDepth = 0;
    Location location = player.getLocation();

    if (location.getY() > 256) {
      // If player is above Y 256, assume they fell at least to there
      fallDistance += location.getY() - 256;
      location.setY(256);
    }

    // Search the blocks directly beneath the player until we find what they would have landed on
    Block block = null;
    for (; location.getY() >= 0; location.add(0, -1, 0)) {
      block = location.getBlock();
      if (block != null) {
        landingBlock = block;

        if (Materials.isWater(landingBlock.getType())) {
          // If the player falls through water, reset fall distance and inc the water depth
          fallDistance = -1;
          waterDepth += 1;

          // Break if they have fallen through enough water to stop falling
          if (waterDepth >= BREAK_FALL_WATER_DEPTH) break;
        } else {
          // If the block is not water, reset the water depth
          waterDepth = 0;

          if (Materials.isSolid(landingBlock.getType())
              || Materials.isLava(landingBlock.getType())) {
            // Break if the player hits a solid block or lava
            break;
          } else if (landingBlock.getType() == Material.WEB) {
            // If they hit web, reset their fall distance, but assume they keep falling
            fallDistance = -1;
          }
        }
      }

      fallDistance += 1;
    }

    double resistanceFactor = getResistanceFactor(player);
    boolean fireResistance = hasFireResistance(player);

    // Now decide if the landing would have killed them
    if (location.getBlockY() < 0) {
      // The player would have fallen into the void
      return new ImminentDeath(EntityDamageEvent.DamageCause.VOID, location, null, false);
    } else if (landingBlock != null) {
      if (Materials.isSolid(landingBlock.getType())
          && player.getHealth() <= resistanceFactor * (fallDistance - SAFE_FALL_DISTANCE)) {
        // The player would have landed on a solid block and taken enough fall damage to kill them
        return new ImminentDeath(
            EntityDamageEvent.DamageCause.FALL,
            landingBlock.getLocation().add(0, 0.5, 0),
            null,
            false);
      } else if (Materials.isLava(landingBlock.getType())
          && resistanceFactor > 0
          && !fireResistance) {
        // The player would have landed in lava, and we give the lava the benefit of the doubt
        return new ImminentDeath(
            EntityDamageEvent.DamageCause.LAVA, landingBlock.getLocation(), landingBlock, false);
      }
    }
  }

  // If we didn't predict a falling death, detect combat log due to recent damage
  Damage damage = this.recentDamage.remove(player);
  if (damage != null && damage.time.plus(RECENT_DAMAGE_THRESHOLD).isAfter(Instant.now())) {
    // Player logged out too soon after taking damage
    return new ImminentDeath(damage.event.getCause(), player.getLocation(), null, true);
  }

  return null;
}
 
Example 18
Source File: PlayerComponent.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
static boolean isDead(Player player) {
  return player.hasMetadata("isDead") || player.isDead();
}
 
Example 19
Source File: PlayerTickTask.java    From GriefDefender with MIT License 4 votes vote down vote up
@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;
                }
            }
        }
    }
}
 
Example 20
Source File: SpawnLoader.java    From AuthMeReloaded with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Return player's location if player is alive, or player's spawn location if dead.
 *
 * @param player player to retrieve
 *
 * @return location of the given player if alive, spawn location if dead.
 */
public Location getPlayerLocationOrSpawn(Player player) {
    if (player.isOnline() && player.isDead()) {
        return getSpawnLocation(player);
    }
    return player.getLocation();
}