Java Code Examples for org.bukkit.event.entity.EntityDamageByEntityEvent#getDamage()
The following examples show how to use
org.bukkit.event.entity.EntityDamageByEntityEvent#getDamage() .
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: Vampire.java From ce with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void effect(Event e, ItemStack item, int level) { EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e; Player damager = (Player) event.getDamager(); if (!getHasCooldown(damager)) { double heal = (((Damageable) damager).getHealth() + (event.getDamage() / damageHealFraction)); if ( heal < ((Damageable) damager).getMaxHealth()) damager.setHealth(heal); else damager.setHealth(((Damageable) damager).getMaxHealth()); int food = (int) (damager.getFoodLevel() + (event.getDamage() / damageHealFraction)); if ( food < 20) damager.setFoodLevel(food); else damager.setFoodLevel(20); EffectManager.playSound(damager.getLocation(), "ENTITY_PLAYER_BURP", 0.4f, 1f); generateCooldown(damager, cooldown); } }
Example 2
Source File: Healing.java From ce with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void effect(Event e, ItemStack item, int level) { if(e instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e; LivingEntity target = (LivingEntity) event.getEntity(); double newHealth = target.getHealth()+event.getDamage() + level; if(newHealth >= target.getMaxHealth()) newHealth = target.getMaxHealth(); target.setHealth(newHealth); event.setDamage(0); target.getWorld().playEffect(target.getLocation(), Effect.POTION_BREAK, 10); } }
Example 3
Source File: EntityListener.java From Guilds with MIT License | 5 votes |
/** * Handles the extra damage to a mob * * @param event */ @EventHandler public void onMobDamage(EntityDamageByEntityEvent event) { if (event.getDamager() instanceof Player) { Player player = (Player) event.getDamager(); Guild guild = guildHandler.getGuild(player); if (guild == null) { return; } double dmg = event.getDamage(); double multiplier = guild.getTier().getDamageMultiplier(); event.setDamage(dmg * multiplier); } }
Example 4
Source File: DealtDamageEvent.java From StackMob-3 with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onDamageDealt(EntityDamageByEntityEvent event) { if(event.getEntity() instanceof Player){ if(StackTools.hasSizeMoreThanOne(event.getDamager())){ int stackSize = StackTools.getSize(event.getDamager()); double extraDamage = event.getDamage() + ((event.getDamage() * (stackSize - 1)) * 0.2); event.setDamage(extraDamage); } } }
Example 5
Source File: EntityDamageListener.java From SaneEconomy with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onEntityDamage(EntityDamageByEntityEvent evt) { if (!(evt.getDamager() instanceof Player)) { return; } Player damager = ((Player) evt.getDamager()); Entity damagee = evt.getEntity(); if (!damager.hasPermission("saneeconomy.mobkills.use")) { return; } if (!this.plugin.getKillAmounts().containsKey(this.getEntityType(damagee))) { return; } Map<UUID, Double> damageDoneToThisEntity = new HashMap<>(); if (this.damageDealt.containsKey(damagee.getEntityId())) { damageDoneToThisEntity = this.damageDealt.get(damagee.getEntityId()); } else { this.damageDealt.put(damagee.getEntityId(), damageDoneToThisEntity); } double totalDamageDealt = 0; if (damageDoneToThisEntity.containsKey(damager.getUniqueId())) { totalDamageDealt += damageDoneToThisEntity.get(damager.getUniqueId()); } totalDamageDealt += evt.getDamage(); damageDoneToThisEntity.put(damager.getUniqueId(), totalDamageDealt); }
Example 6
Source File: Defense.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public void onDefense(EntityDamageByEntityEvent event, ItemStack stack) { double defValue = this.getDouble("value"); /* Try to get any extra defense enhancements from this item. */ LoreCraftableMaterial craftMat = LoreCraftableMaterial.getCraftMaterial(stack); if (craftMat == null) { return; } double extraDef = 0; AttributeUtil attrs = new AttributeUtil(stack); for (LoreEnhancement enh : attrs.getEnhancements()) { if (enh instanceof LoreEnhancementDefense) { extraDef += ((LoreEnhancementDefense)enh).getExtraDefense(attrs); } } defValue += extraDef; double damage = event.getDamage(); if (event.getEntity() instanceof Player) { Resident resident = CivGlobal.getResident(((Player)event.getEntity())); if (!resident.hasTechForItem(stack)) { defValue = defValue / 2; } } damage -= defValue; if (damage < 0.5) { /* Always do at least 0.5 damage. */ damage = 0.5; } event.setDamage(damage); }
Example 7
Source File: LWCEntityListener.java From Modern-LWC with MIT License | 4 votes |
@EventHandler(ignoreCancelled = true) public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if (!LWC.ENABLED || event.isCancelled()) { return; } LWC lwc = plugin.getLWC(); if (event.getDamager() instanceof Player) { Player player = (Player) event.getDamager(); Entity entity = event.getEntity(); EntityBlock entityBlock = new EntityBlock(entity); boolean ignoreBlockDestruction = Boolean .parseBoolean(lwc.resolveProtectionConfiguration(entityBlock, "ignoreBlockDestruction")); if (ignoreBlockDestruction) { return; } if (event.getEntityType().equals(EntityType.ARMOR_STAND)) { if (event.getDamage() < 1.0 || ((Player) event.getDamager()).getGameMode().equals(GameMode.CREATIVE)) { // Armor Stand Broke ProtectionCache cache = lwc.getProtectionCache(); String cacheKey = cache.cacheKey(entityBlock.getLocation()); // In the event they place a block, remove any known nulls there if (cache.isKnownNull(cacheKey)) { cache.remove(cacheKey); } Protection protection = lwc.findProtection(entityBlock); if (protection == null) { return; } boolean canAccess = lwc.canAccessProtection(player, protection); boolean canAdmin = lwc.canAdminProtection(player, protection); try { // Removing protection LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection, LWCProtectionDestroyEvent.Method.ENTITY_DESTRUCTION, canAccess, canAdmin); lwc.getModuleLoader().dispatchEvent(evt); protection.remove(); protection.removeAllPermissions(); protection.removeCache(); if (evt.isCancelled() || !canAccess) { event.setCancelled(true); } } catch (Exception e) { event.setCancelled(true); lwc.sendLocale(player, "protection.internalerror", "id", "BLOCK_BREAK"); e.printStackTrace(); } } /*else { // Armor Stand Punched LWC.getInstance().log("Armor Stand Punched"); if(plugin.getLWC().isProtectable(entity.getType())){ int A = 50000 + entity.getUniqueId().hashCode(); Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A); boolean canAccess = lwc.canAccessProtection(player, protection); boolean canAdmin = lwc.canAdminProtection(player, protection); Set<String> actions = lwc.wrapPlayer(player).getActionNames(); Module.Result result = Module.Result.CANCEL; // TODO: Finish this implementation if (protection != null) { LWCEntityDamageByEntityEvent evt = new LWCEntityDamageByEntityEvent(event, protection, actions, canAccess, canAdmin); lwc.getModuleLoader().dispatchEvent(evt); result = evt.getResult(); } else { } if (result == Module.Result.ALLOW) { return; } if (player.hasPermission("lwc.lockentity." + entity.getType()) || player.hasPermission("lwc.lockentity.all")) { if (onPlayerEntityInteract(p, entity, e.isCancelled())) { chunkUnload(entity.getWorld().getName(), A); e.setCancelled(true); } } if (protection != null) { if (canAccess) return; e.setCancelled(true); } } }*/ } } }
Example 8
Source File: DealDamageTaskType.java From Quests with MIT License | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onDamage(EntityDamageByEntityEvent e) { if (!(e.getDamager() instanceof Player)) { return; } Player player = (Player) e.getDamager(); double damage = e.getDamage(); QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId(), true); QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile(); for (Quest quest : super.getRegisteredQuests()) { if (questProgressFile.hasStartedQuest(quest)) { QuestProgress questProgress = questProgressFile.getQuestProgress(quest); for (Task task : quest.getTasksOfType(super.getType())) { TaskProgress taskProgress = questProgress.getTaskProgress(task.getId()); if (taskProgress.isCompleted()) { continue; } double progressDamage; int damageNeeded = (int) task.getConfigValue("amount"); if (taskProgress.getProgress() == null) { progressDamage = 0.0; } else { progressDamage = (double) taskProgress.getProgress(); } taskProgress.setProgress(progressDamage + damage); if (((double) taskProgress.getProgress()) >= (double) damageNeeded) { taskProgress.setCompleted(true); } } } } }
Example 9
Source File: SentinelTrait.java From Sentinel with MIT License | 4 votes |
/** * Called when this sentinel attacks something with a projectile, to correct damage handling. */ public void whenAttacksAreHappeningFromMyArrow(EntityDamageByEntityEvent event) { if (event.isCancelled()) { return; } if (!npc.isSpawned()) { return; } if (SentinelPlugin.instance.alternateDamage) { if (canEnforce) { canEnforce = false; whenAttacksHappened(event); if (!event.isCancelled()) { ((LivingEntity) event.getEntity()).damage(getDamage(true)); if (event.getEntity() instanceof LivingEntity) { weaponHelper.knockback((LivingEntity) event.getEntity()); } } if (SentinelPlugin.debugMe) { debug("enforce damage value to " + getDamage(true)); } } else { if (SentinelPlugin.debugMe) { debug("refuse damage enforcement"); } } event.setDamage(0); event.setCancelled(true); return; } double dam = getDamage(true); double modder = event.getDamage(EntityDamageEvent.DamageModifier.BASE); double rel = modder == 0.0 ? 1.0 : dam / modder; event.setDamage(EntityDamageEvent.DamageModifier.BASE, dam); for (EntityDamageEvent.DamageModifier mod : EntityDamageEvent.DamageModifier.values()) { if (mod != EntityDamageEvent.DamageModifier.BASE && event.isApplicable(mod)) { event.setDamage(mod, event.getDamage(mod) * rel); if (SentinelPlugin.debugMe) { debug("Set damage for " + mod + " to " + event.getDamage(mod)); } } } }
Example 10
Source File: CombatSystem.java From EliteMobs with GNU General Public License v3.0 | 2 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void eliteMobDamageHandler(EntityDamageByEntityEvent event) { if (event.isCancelled()) return; if (!(event.getEntity() instanceof Player)) return; LivingEntity damager = EntityFinder.getRealDamager(event); if (damager == null) return; if (!EntityTracker.isEliteMob(event.getDamager())) return; EliteMobEntity eliteMobEntity = EntityTracker.getEliteMobEntity(damager); if (eliteMobEntity == null) return; //From this point on, the damage event is fully altered by Elite Mobs //Get rid of all vanilla armor reduction for (EntityDamageEvent.DamageModifier modifier : EntityDamageEvent.DamageModifier.values()) if (event.isApplicable(modifier)) event.setDamage(modifier, 0); Player player = (Player) event.getEntity(); //Determine tiers double eliteTier = MobTierFinder.findMobTier(eliteMobEntity); double playerTier = ItemTierFinder.findArmorSetTier(player); double newDamage = eliteToPlayerDamageFormula(eliteTier, playerTier, player, event); //Prevent untouchable armor and 1-shots if (newDamage < 1) newDamage = 1; if (newDamage > 19) newDamage = 19; //Set the final damage value event.setDamage(EntityDamageEvent.DamageModifier.BASE, newDamage); //Deal with the player getting killed if (player.getHealth() - event.getDamage() <= 0) PlayerDeathMessageByEliteMob.addDeadPlayer(player, PlayerDeathMessageByEliteMob.intializeDeathMessage(player, damager)); }