本文整理汇总了Java中org.bukkit.event.entity.EntityDamageByEntityEvent.setDamage方法的典型用法代码示例。如果您正苦于以下问题:Java EntityDamageByEntityEvent.setDamage方法的具体用法?Java EntityDamageByEntityEvent.setDamage怎么用?Java EntityDamageByEntityEvent.setDamage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.entity.EntityDamageByEntityEvent
的用法示例。
在下文中一共展示了EntityDamageByEntityEvent.setDamage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDamage
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if ((event.getDamager() instanceof Player)) {
Player player = (Player) event.getDamager();
if (player.getInventory().getItemInMainHand().getType() == Material.DIAMOND_AXE) {
event.setDamage(event.getDamage() - 6.0D + 3.0D);
} else if (player.getInventory().getItemInMainHand().getType() == Material.IRON_AXE) {
event.setDamage(event.getDamage() - 6.0D + 2.5D);
} else if (player.getInventory().getItemInMainHand().getType() == Material.STONE_AXE) {
event.setDamage(event.getDamage() - 6.0D + 2.0D);
} else if ((player.getInventory().getItemInMainHand().getType() == Material.GOLD_AXE) ||
(player.getInventory().getItemInMainHand().getType() == Material.WOOD_AXE)) {
event.setDamage(event.getDamage() - 4.0D + 1.5D);
} else if (player.getInventory().getItemInMainHand().getType() == Material.DIAMOND_SPADE) {
event.setDamage(event.getDamage() - 2.5D + 2.0D);
} else if (player.getInventory().getItemInMainHand().getType() == Material.STONE_SPADE) {
event.setDamage(event.getDamage() - 0.75D + 1.25D);
}
}
}
示例2: onEntityDamageByEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
Entity damager = event.getDamager();
if (entity instanceof Player && damager instanceof Player) {
Player attacker = (Player) damager;
if (plugin.getPvpClassManager().getEquippedClass(attacker) == this) {
ItemStack stack = attacker.getItemInHand();
if (stack != null && stack.getType() == Material.GOLD_SWORD && stack.getEnchantments().isEmpty()) {
Player player = (Player) entity;
player.sendMessage(SettingsYML.ENEMY_COLOUR + attacker.getName() + ChatColor.YELLOW + " has backstabbed you.");
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
attacker.sendMessage(ChatColor.YELLOW + "You have backstabbed " + SettingsYML.ENEMY_COLOUR + player.getName() + ChatColor.YELLOW + '.');
attacker.setItemInHand(new ItemStack(Material.AIR, 1));
player.setHealth(12);
attacker.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
event.setDamage(3.0);
}
}
}
}
示例3: onDamageEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onDamageEntity(EntityDamageByEntityEvent e){
Player p;
if (e.getDamager() instanceof Player && e.getEntity() instanceof Zombie){
p = (Player)e.getDamager();
Weapon weapon;
if (p.getInventory().getItemInMainHand() == null || !Weapon.isWeapon(p.getInventory().getItemInMainHand())) return;
if (Weapon.getWeaponByItemStack(p.getInventory().getItemInMainHand()) == null) {
e.setDamage(0);
return;
}
weapon = Weapon.getWeaponByItemStack(p.getInventory().getItemInMainHand());
if (weapon.getId() != 0) return;
e.setDamage(((Zombie) e.getEntity()).getMaxHealth());
}
if (e.getDamager() instanceof Zombie && e.getEntity() instanceof Player) {
p = (Player) e.getEntity();
if (this.plugin.getBlooding().contains(new TWDPlayer(p.getUniqueId()))) return;
this.plugin.getBlooding().add(new TWDPlayer(p.getUniqueId()));
}
}
示例4: onEntityDamage
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent e) {
if ((e.getDamager() instanceof Arrow) && (((Arrow) e.getDamager()).getShooter() instanceof Player) && e.getDamager().getCustomName() == name) {
e.setDamage(e.getDamage() + damage);
if (effect != null) {
((LivingEntity) e.getEntity()).addPotionEffect(effect);
}
}
if ((e.getDamager() instanceof Fireball) && (((Fireball) e.getDamager()).getShooter() instanceof Player) && e.getDamager().getCustomName() == name) {
e.setDamage(e.getDamage() + damage);
}
if ((e.getDamager() instanceof Snowball) && (((Snowball) e.getDamager()).getShooter() instanceof Player) && e.getDamager().getCustomName() == name) {
e.setDamage(e.getDamage() + damage);
}
}
示例5: onProjectileHurtEvent
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onProjectileHurtEvent(EntityDamageByEntityEvent event) {
if(!(event.getEntity() instanceof LivingEntity)) return;
final LivingEntity damagedEntity = (LivingEntity) event.getEntity();
final ProjectileDefinition projectileDefinition = Projectiles.getProjectileDefinition(event.getDamager());
if(projectileDefinition == null) return;
if(!projectileDefinition.potion().isEmpty()) {
damagedEntity.addPotionEffects(projectileDefinition.potion());
}
if(projectileDefinition.damage() != null) {
event.setDamage(projectileDefinition.damage());
}
}
示例6: onEntityDamageByEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Player attacker = getDamageSource(event.getDamager());
Entity eDefender = event.getEntity();
if (!(eDefender instanceof Player)) {
forbidIfInProtectedTerritory(attacker, eDefender, event, ATTACK);
return;
}
Player defender = (Player) eDefender;
Faction aFaction = plugin.getFactionCache().getByMember(attacker);
Faction dFaction = plugin.getFactionCache().getByMember(defender);
Faction rFaction = plugin.getFactionCache().getByLocation(defender.getLocation());
if (aFaction.getRelation(dFaction).isProtected()) {
ParsingUtil.sendMessage(attacker, FMessage.PROTECTION_CANNOT_ATTACK_PLAYER.getMessage(), dFaction);
event.setCancelled(true);
} else if (rFaction != null && rFaction.getRelation(dFaction).isProtected()) {
if (plugin.getFConfig().isTerritoryProtectionEnabled() && (!plugin.getFConfig().isCapitalProtectionEnabled()
|| rFaction.getCapital().equals(plugin.getBoard().getByLocation(eDefender.getLocation())))) {
ParsingUtil.sendMessage(attacker, FMessage.PROTECTION_CANNOT_ATTACK_FACTION.getMessage(), rFaction);
event.setCancelled(true);
} else if (plugin.getFConfig().getTerritoryShield() != 0) {
event.setDamage(event.getDamage() * plugin.getFConfig().getTerritoryShield());
}
}
}
示例7: damage
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@Override
public void damage(double amount, Entity source)
{
Map<DamageModifier, Double> modifiers = new EnumMap<>(DamageModifier.class);
modifiers.put(DamageModifier.BASE, 1.0);
Map<DamageModifier, Function<Double, Double>> modifierFunctions = new EnumMap<>(DamageModifier.class);
modifierFunctions.put(DamageModifier.BASE, damage -> damage);
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(source, this, DamageCause.ENTITY_ATTACK, modifiers, modifierFunctions);
event.setDamage(amount);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled())
{
setHealth(health - amount);
}
}
示例8: onEntityDamageByEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
if (api.getGameManager().isLegacyPvP()) {
Entity attacker = event.getDamager();
if (attacker instanceof Player) {
Player player = (Player) attacker;
ItemStack inHand = player.getInventory().getItemInMainHand();
if (inHand != null) {
double baseDamage = event.getDamage(EntityDamageEvent.DamageModifier.BASE);
double currentDamage = this.getCurrentDamage(inHand.getType());
if (currentDamage != 0.0D) {
double damageFactor = baseDamage / currentDamage;
double legacyDamage = this.getLegacyDamage(inHand.getType()) * damageFactor;
event.setDamage(EntityDamageEvent.DamageModifier.BASE, legacyDamage);
}
}
}
}
}
示例9: onEntityDamageByEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if ((event.getDamager() instanceof Player)) {
Player p = (Player)event.getDamager();
if (Kit.getKit(p).getName().equalsIgnoreCase("woodcutter") && (p.getItemInHand().getType().name().contains("_AXE"))) {
Random r = new Random();
double multiplier = 1.0D + 1.0D * r.nextDouble() - r.nextDouble() + 0.5D;
if (multiplier < 1.0D)
multiplier = 1.0D;
if (multiplier >= 2.0D) {
multiplier = 2.0D;
}
event.setDamage((int)(event.getDamage() * multiplier));
}
}
}
示例10: offenseEffect
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@Override
public void offenseEffect(LivingEntity user, LivingEntity target, EntityDamageByEntityEvent event){
double health = user.getHealth();
if (health == 3.0 || health == 2.5) {
event.setDamage(event.getDamage() + 0.5);
} else if (health == 2.0 || health == 1.5) {
event.setDamage(event.getDamage() + 1.0);
} else if (health == 1.0){
event.setDamage(event.getDamage() + 1.5);
} else if (health == 0.5){
event.setDamage(event.getDamage() + 2.0);
}
}
示例11: weakDamageDirectWithGun
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
/**
* Doesn't seem to work right now but basically, if you smack someone over the head
* with the gun instead of shoot it, do less damage.
*
* @param event The hit event
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void weakDamageDirectWithGun(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof LivingEntity) {
LivingEntity damager = (LivingEntity) event.getDamager();
EntityEquipment equips = damager.getEquipment();
StandardGun gun = findGun(equips.getItemInMainHand());
if (gun != null) {
// modify damage!
event.setDamage(gun.getBluntDamage());
}
}
}
示例12: weakDamageDirectWithGun
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
/**
* Doesn't seem to work right now but basically, if you smack someone over the head
* with the gun instead of shoot it, do less damage.
*
* @param event The hit event
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void weakDamageDirectWithGun(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof LivingEntity) {
LivingEntity damager = (LivingEntity) event.getDamager();
EntityEquipment equips = damager.getEquipment();
if (isGun(equips.getItemInMainHand())) {
// modify damage!
event.setDamage(this.bluntDamage);
}
}
}
示例13: onPlayerDamage
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerDamage(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
if ((damager instanceof Player && ItemUtils.isWeapon(((Player) damager).getItemInHand())) ||
(damager instanceof Projectile && ((Projectile) damager).getShooter() instanceof Player)) {
event.setDamage(DAMAGE);
}
}
示例14: handlePlayerDamage
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void handlePlayerDamage(EntityDamageByEntityEvent event) {
if(event.getDamager() instanceof Player) {
if(((Player) event.getDamager()).getItemInHand().containsEnchantment(Enchantment.DAMAGE_ALL)) event.setDamage(1000);
} else if(event.getDamager() instanceof Arrow && ((Arrow) event.getDamager()).getShooter() instanceof Player) {
if(((Arrow) event.getDamager()).getDamage() > 2D) event.setDamage(1000);
}
}
示例15: onEntityDamageByEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
/**
* Removes the hit cooldown upon a player attack and reduces the amount of damage dealt according to a modifier.
*
* @param event The event
*/
@EventHandler(ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Player
&& event.getDamager() instanceof Player
&& event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK)) {
event.setDamage(event.getDamage() * damageReduction);
Bukkit.getScheduler().runTask(OpenUHC.getInstance(), () -> ((Player) entity).setNoDamageTicks(0));
}
}