本文整理匯總了Java中org.bukkit.entity.EntityType.PLAYER屬性的典型用法代碼示例。如果您正苦於以下問題:Java EntityType.PLAYER屬性的具體用法?Java EntityType.PLAYER怎麽用?Java EntityType.PLAYER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.bukkit.entity.EntityType
的用法示例。
在下文中一共展示了EntityType.PLAYER屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onRegen
@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);
}
示例2: onPlayerFall
@EventHandler
public void onPlayerFall(EntityDamageEvent event) {
if (event.getEntity().getType() == EntityType.PLAYER
&& event.getCause() == EntityDamageEvent.DamageCause.FALL) {
Player player = (Player) event.getEntity();
if (!InventoryManager.playerIsLoaded(player)) {
return;
}
Modifier jumpModifier = ItemManager.getModifier(player, ItemStat.StatType.JUMP);
double height = (1.5D + jumpModifier.getBonus()) * jumpModifier.getMultiplier() * 1.5;
event.setDamage(event.getDamage() - height);
if (event.getDamage() <= 0.0D) {
event.setCancelled(true);
}
}
}
示例3: ClickCheckItem
@EventHandler
public void ClickCheckItem(InventoryClickEvent evt){
if(ConfigPatch.AntiLongStringCrashenable == true){
if(evt.getWhoClicked().getType() != EntityType.PLAYER){
return;
}
Player player = (Player) evt.getWhoClicked();
ItemStack item = evt.getCursor();
if(item != null){
if(item.hasItemMeta() && item.getItemMeta().getDisplayName() != null){
if(item.getItemMeta().getDisplayName().length() >= 127){
evt.setCancelled(true);
evt.setCurrentItem(null);
AzureAPI.log(player, ConfigPatch.AntiLongStringCrashWarnMessage);
}
}
}
}
}
示例4: onEntityToggleGlide
@EventHandler(ignoreCancelled = true)
public void onEntityToggleGlide(EntityToggleGlideEvent event) {
if (event.getEntityType() != EntityType.PLAYER) {
return;
}
Player player = (Player) event.getEntity();
if (!InventoryManager.playerIsLoaded(player)) {
return;
}
if (event.isGliding()) {
PlayerWrapper playerWrapper = InventoryManager.get(player);
playerWrapper.onStartGliding();
}
}
示例5: onDamageWhenPlayerNotLoaded
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onDamageWhenPlayerNotLoaded(EntityDamageEvent event) {
if (event.getEntityType() != EntityType.PLAYER) {
return;
}
Player player = (Player) event.getEntity();
if (InventoryManager.playerIsLoaded(player)) {
return;
}
if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
PlayerLoader.setDamageForPlayer(player, event.getFinalDamage());
}
event.setCancelled(true);
}
示例6: EntityFarmChecker
@EventHandler
public void EntityFarmChecker(EntityInteractEvent event){
if(ConfigFunction.ProtectFarmenable){
if(event.getEntityType() != EntityType.PLAYER){
Block block = event.getBlock();
if(block.getType() == Material.SOIL||block.getType() == Material.CROPS){
event.setCancelled(true);
}
}
}
}
示例7: getNearbyPlayers
public static List<Player> getNearbyPlayers(Location location, double distance) {
List<Player> nearbyPlayers = new ArrayList<>();
for (LivingEntity entity : location.getWorld().getLivingEntities()) {
if (entity.getType() == EntityType.PLAYER && entity.getLocation().distance(location) <= distance) {
nearbyPlayers.add((Player) entity);
}
}
return nearbyPlayers;
}
示例8: onEntityDismount
@EventHandler
public void onEntityDismount(EntityDismountEvent event)
{
if (event.getEntity().getType() != EntityType.PLAYER)
return;
if (!this.hasPlayer((Player) event.getEntity()))
return;
event.getDismounted().setPassenger(event.getEntity());
}
示例9: onSpawn
@EventHandler
public void onSpawn(EntitySpawnEvent event) {
if (Skywars.getInstance().isSingleServerMode()) {
if (event.getEntityType() != EntityType.PLAYER && event.getEntityType() != EntityType.DROPPED_ITEM && event.getEntityType() != EntityType.PRIMED_TNT) {
event.setCancelled(true);
}
}
}
示例10: onCraftItem
@EventHandler(priority = EventPriority.HIGH)
public void onCraftItem(CraftItemEvent event)
{
if( event.getRecipe().getResult().getType() == Material.STONE_SWORD
|| event.getRecipe().getResult().getType() == Material.IRON_SWORD
|| event.getRecipe().getResult().getType() == Material.GOLD_SWORD
|| event.getRecipe().getResult().getType() == Material.DIAMOND_SWORD
|| event.getRecipe().getResult().getType() == Material.LEATHER_BOOTS
|| event.getRecipe().getResult().getType() == Material.LEATHER_LEGGINGS
|| event.getRecipe().getResult().getType() == Material.LEATHER_CHESTPLATE
|| event.getRecipe().getResult().getType() == Material.LEATHER_HELMET
|| event.getRecipe().getResult().getType() == Material.CHAINMAIL_BOOTS
|| event.getRecipe().getResult().getType() == Material.CHAINMAIL_LEGGINGS
|| event.getRecipe().getResult().getType() == Material.CHAINMAIL_CHESTPLATE
|| event.getRecipe().getResult().getType() == Material.CHAINMAIL_HELMET
|| event.getRecipe().getResult().getType() == Material.GOLD_BOOTS
|| event.getRecipe().getResult().getType() == Material.GOLD_LEGGINGS
|| event.getRecipe().getResult().getType() == Material.GOLD_CHESTPLATE
|| event.getRecipe().getResult().getType() == Material.GOLD_HELMET
|| event.getRecipe().getResult().getType() == Material.IRON_BOOTS
|| event.getRecipe().getResult().getType() == Material.IRON_LEGGINGS
|| event.getRecipe().getResult().getType() == Material.IRON_CHESTPLATE
|| event.getRecipe().getResult().getType() == Material.IRON_HELMET
|| event.getRecipe().getResult().getType() == Material.DIAMOND_BOOTS
|| event.getRecipe().getResult().getType() == Material.DIAMOND_LEGGINGS
|| event.getRecipe().getResult().getType() == Material.DIAMOND_CHESTPLATE
|| event.getRecipe().getResult().getType() == Material.DIAMOND_HELMET)
{
if( event.getWhoClicked().getType() == EntityType.PLAYER )
{
Player p = (Player)event.getWhoClicked();
p.sendMessage("Sorry, you are not allowed to craft this item. Purchase it from a Safe Dock instead.");
}
event.setCancelled(false);
}
}
示例11: onEntityDeath
/**
* When a player kill a mob there's a 40% chance to spawn the same at the same place
*
* @param event Event
*/
@EventHandler
public void onEntityDeath(EntityDeathEvent event)
{
if (event.getEntity().getType() == EntityType.PLAYER)
return;
if (this.random.nextDouble() < (double) this.moduleConfiguration.get("chance"))
event.getEntity().getWorld().spawnEntity(event.getEntity().getLocation(), event.getEntity().getType());
}
示例12: onTarget
@EventHandler
public void onTarget(EntityTargetLivingEntityEvent event) {
if (!(event.getEntity() instanceof Tameable) || !(event.getEntity() instanceof LivingEntity)
|| event.getTarget() == null || !InventoryManager.isAllowedWorld(event.getTarget().getWorld())) {
return;
}
LivingEntity petEntity = (LivingEntity) event.getEntity();
final OfflinePlayer player = (OfflinePlayer) ((Tameable) petEntity).getOwner();
if (!InventoryManager.playerIsLoaded(player)) {
return;
}
PlayerWrapper playerWrapper = InventoryManager.get(player);
if (playerWrapper.hasPet() && petEntity == playerWrapper.getPet()) {
PetType petType = PetManager.getPetFromEntity(petEntity, player);
if (petType == null) {
return;
}
if (event.getTarget() != null && event.getTarget().getType() == EntityType.PLAYER) {
event.setCancelled(!petType.isAttackPlayers());
} else {
event.setCancelled(!petType.isAttackMobs());
}
}
}
示例13: onDamage
/**
* Cancel fall damages
*
* @param event Event instance
*/
@EventHandler
public void onDamage(EntityDamageEvent event)
{
if (event.getEntityType() == EntityType.PLAYER && event.getCause() == EntityDamageEvent.DamageCause.FALL)
{
event.setCancelled(true);
event.setDamage(0);
}
}
示例14: onDamage
/**
* Fire player on damage
* @param event Event
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onDamage(EntityDamageEvent event)
{
if (((SurvivalGame) SamaGamesAPI.get().getGameManager().getGame()).isDamagesActivated()
&& event.getEntityType() == EntityType.PLAYER
&& event.getCause() != EntityDamageEvent.DamageCause.FIRE
&& event.getCause() != EntityDamageEvent.DamageCause.FIRE_TICK
&& event.getDamage() > 0
&& !event.isCancelled())
event.getEntity().setFireTicks((int) this.moduleConfiguration.get("fire-time") * 20);
}
示例15: onMobJump
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onMobJump(EntityInteractEvent e) {
if (!cm.farmProtectEnabled) {
return;
}
if (e.getEntityType() == EntityType.PLAYER) {
return;
}
if (e.getBlock().getType() == Material.SOIL) {
e.setCancelled(true);
}
}