本文整理汇总了Java中org.bukkit.entity.Player.isOnGround方法的典型用法代码示例。如果您正苦于以下问题:Java Player.isOnGround方法的具体用法?Java Player.isOnGround怎么用?Java Player.isOnGround使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Player
的用法示例。
在下文中一共展示了Player.isOnGround方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@Override
public void run() {
Map<UUID, Boolean> clone = new HashMap<>(this.grounded);
for (Player player : Bukkit.getOnlinePlayers()) {
Boolean last = clone.get(player.getUniqueId());
boolean current = player.isOnGround();
if (last == null || last != current) {
PlayerOnGroundEvent call = new PlayerOnGroundEvent(player, current);
this.grounded.put(player.getUniqueId(), current);
for (EventPriority priority : EventPriority.values())
EventUtil.callEvent(call, PlayerOnGroundEvent.getHandlerList(), priority);
}
}
// Remove players who have logged out
for (UUID uuid : clone.keySet()) {
if (Bukkit.getPlayer(uuid) == null)
this.grounded.remove(uuid);
}
}
示例2: onPlayerFall
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onPlayerFall(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (!InventoryManager.playerIsLoaded(player) || player.isFlying()
|| player.getVehicle() != null) {
return;
}
PlayerWrapper playerWrapper = InventoryManager.get(player);
boolean endFalling = false;
if (!player.isOnGround()) {
if (playerIsSneakOnLadder(player) || isPlayerCanFall(player)) {
playerWrapper.onFall();
} else if (!player.isGliding()) {
endFalling = true;
}
} else if (playerWrapper.isFalling()) {
endFalling = true;
}
if (endFalling) {
playerWrapper.setFalling(false);
}
}
示例3: onPlayerMoveWhenNotLoaded
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onPlayerMoveWhenNotLoaded(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (!InventoryManager.isAllowedWorld(player.getWorld()) || InventoryManager.playerIsLoaded(player)) {
return;
}
if (PlayerLoader.isPreparedPlayer(player)) {
PlayerLoader.removePlayer(player);
player.kickPlayer(RPGInventory.getLanguage().getMessage("error.rp.denied"));
event.setCancelled(true);
} else {
Location toLocation = event.getTo();
Location newLocation = event.getFrom().clone();
//noinspection deprecation
if (!player.isOnGround()) {
newLocation.setY(toLocation.getY());
}
newLocation.setPitch(toLocation.getPitch());
newLocation.setYaw(toLocation.getYaw());
event.setTo(newLocation);
}
}
示例4: getImminentDeath
import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
* 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;
}
示例5: onEntityDamageByEntity
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player) || !(event.getDamager() instanceof Player)) {
return;
}
if (event.isCancelled()) {
return;
}
Player damaged = (Player) event.getEntity();
Player damager = (Player) event.getDamager();
if (damaged.getNoDamageTicks() > damaged.getMaximumNoDamageTicks() / 2D) {
return;
}
Vector knockback = damaged.getLocation().toVector().subtract(damager.getLocation().toVector()).normalize();
double horMultiplier = 1.1;
double verMultiplier = 1.04;
double sprintMultiplier = damager.isSprinting() ? 0.81D : 0.5D;
double kbMultiplier = damager.getItemInHand() == null ? 0 : damager.getItemInHand().getEnchantmentLevel(Enchantment.KNOCKBACK) * 0.2D;
@SuppressWarnings("deprecation")
double airMultiplier = damaged.isOnGround() ? 1 : 0.94;
knockback.setX((knockback.getX() * sprintMultiplier + kbMultiplier) * horMultiplier);
knockback.setY(0.35D * airMultiplier * verMultiplier);
knockback.setZ((knockback.getZ() * sprintMultiplier + kbMultiplier) * horMultiplier);
try {
// Send the velocity packet immediately instead of using setVelocity, which fixes the 'relog bug'
Object entityPlayer = damaged.getClass().getMethod("getHandle").invoke(damaged);
Object playerConnection = fieldPlayerConnection.get(entityPlayer);
Object packet = packetVelocity.newInstance(damaged.getEntityId(), knockback.getX(), knockback.getY(), knockback.getZ());
sendPacket.invoke(playerConnection, packet);
} catch (SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException e) {
e.printStackTrace();
}
//Bukkit.getScheduler().scheduleSyncDelayedTask(core, new Runnable() {
//public void run() {
//double horMultiplier = KnockbackPatch.getInstance().getHorMultiplier();
//double verMultiplier = KnockbackPatch.getInstance().getVerMultiplier();
//double sprintMultiplier = damager.isSprinting() ? 0.8D : 0.5D;
//double kbMultiplier = damager.getItemInHand() == null ? 0 : damager.getItemInHand().getEnchantmentLevel(Enchantment.KNOCKBACK) * 0.2D;
//@SuppressWarnings("deprecation")
//double airMultiplier = damaged.isOnGround() ? 1 : 0.8;
//
//nockback.setX((knockback.getX() * sprintMultiplier + kbMultiplier) * horMultiplier);
//knockback.setY(0.35D * airMultiplier * verMultiplier);
//knockback.setZ((knockback.getZ() * sprintMultiplier + kbMultiplier) * horMultiplier);
//
//try {
// Send the velocity packet immediately instead of using setVelocity, which fixes the 'relog bug'
// Object entityPlayer = damaged.getClass().getMethod("getHandle").invoke(damaged);
// Object playerConnection = fieldPlayerConnection.get(entityPlayer);
// Object packet = packetVelocity.newInstance(damaged.getEntityId(), knockback.getX(), knockback.getY(), knockback.getZ());
// sendPacket.invoke(playerConnection, packet);
// } catch (SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException e) {
// e.printStackTrace();
// }
//}
//}, 2L);
}
示例6: isFlying
import org.bukkit.entity.Player; //导入方法依赖的package包/类
public static boolean isFlying(UUID player){
Player p = Bukkit.getServer().getPlayer(player);
if((p.isFlying()) && (!p.isOnGround())){
return true;
} else {
return false;
}
}