当前位置: 首页>>代码示例>>Java>>正文


Java EntityDamageByEntityEvent.isCancelled方法代码示例

本文整理汇总了Java中org.bukkit.event.entity.EntityDamageByEntityEvent.isCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java EntityDamageByEntityEvent.isCancelled方法的具体用法?Java EntityDamageByEntityEvent.isCancelled怎么用?Java EntityDamageByEntityEvent.isCancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.event.entity.EntityDamageByEntityEvent的用法示例。


在下文中一共展示了EntityDamageByEntityEvent.isCancelled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onAttack

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
	{
		Player player = (Player)event.getDamager();
		ItemStack mainItem = player.getInventory().getItemInMainHand();
		LivingEntity enemy = (LivingEntity)event.getEntity();
		
		if(mainItem.getType() == Material.GOLD_SPADE)
		{
			enemy.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 100, 0, false));
			enemy.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100, 0, false));
			player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 48, 2, true));
			Location particleLoc = player.getLocation();
			particleLoc.setY(particleLoc.getY() + 2);
               ParticleEffect.HEART.display(0.5f, 0, 0.5f, 1, 2, particleLoc, 64);
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:22,代码来源:ObsidianMaceWeakness.java

示例2: onAttack

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
	{
		Player player = (Player)event.getDamager();
		ItemStack mainItem = player.getInventory().getItemInMainHand();
		LivingEntity enemy = (LivingEntity)event.getEntity();

		Random rand = new Random();
		
		if(mainItem.getType() == Material.GOLD_AXE)
		{
			enemy.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 480, 2, false));
			enemy.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 480, 0, false));
           	enemy.getLocation().getWorld().playSound(enemy.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:21,代码来源:StarBattleaxeWither.java

示例3: 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);
	}
}
 
开发者ID:seeseemelk,项目名称:MockBukkit,代码行数:17,代码来源:PlayerMock.java

示例4: onDamage

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
/**
 * Switch players on arrow hit
 *
 * @param event Event instance
 */
@EventHandler(priority = EventPriority.LOWEST)
public void onDamage(EntityDamageByEntityEvent event)
{
    if (!event.isCancelled() && event.getDamager() instanceof Arrow && event.getEntity() instanceof Player)
    {
        ProjectileSource source = ((Arrow)event.getDamager()).getShooter();

        if (source == null || !(source instanceof Player))
            return;

        Player player = (Player)source;
        Location tmp = player.getLocation();

        player.teleport(event.getEntity());
        event.getEntity().teleport(tmp);
    }
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:23,代码来源:SwitcherooModule.java

示例5: onDamage

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onDamage(EntityDamageByEntityEvent e) {
    if (e.isCancelled()) {
        return;
    }
    if (!(e.getDamager() instanceof Player)) {
        return;
    }
    Player p = (Player) e.getDamager();
    long left = CooldownManager.getInstance().getLeft(p, 3000);
    if (left == 0) {
        CooldownManager.getInstance().add(p);
        return;
    }
    e.setCancelled(true);
    p.sendMessage(Messages.prefix + Messages.Cooldown.replace("%time%", String.valueOf(left)));
}
 
开发者ID:Soldier233,项目名称:ArchersBattle,代码行数:18,代码来源:PlayerListener.java

示例6: handleFriendlyFire

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.NORMAL)
public void handleFriendlyFire(EntityDamageByEntityEvent event) {
    if(event.isCancelled() && event.getDamager() instanceof Arrow) {
        Arrow arrow = (Arrow) event.getDamager();
        if(arrow.getPickupRule() == Arrow.PickupRule.ALLOWED && arrow.getShooter() != null && arrow.getShooter() instanceof Player){
            Player owner = (Player) arrow.getShooter();
            owner.getInventory().addItem(new ItemStack(Material.ARROW));
            arrow.remove();
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:12,代码来源:FriendlyFireRefundMatchModule.java

示例7: onAttack

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
	{
		Player player = (Player)event.getDamager();
		ItemStack item = player.getItemInHand();
		if(item.getType() == Material.WOOD_SPADE)
		{
			item.setDurability((short)(item.getDurability() - 2));
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:16,代码来源:FirestrikerClick.java

示例8: onDamaged

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onDamaged(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getEntity() instanceof Player)
	{
		Player player = (Player)event.getEntity();
		healing.getScore(player).setScore(0);
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:12,代码来源:MedicKit.java

示例9: onHit

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.HIGHEST)
public void onHit(EntityDamageByEntityEvent e) {
	if(e.isCancelled())return;
	if (e.getEntity() instanceof Player && e.getDamager() instanceof Player) {
		// Player to = (Player) e.getEntity();
		Player by = (Player) e.getDamager();
		if (!e.isCancelled()) {
			by.giveExp(5);
		}
	}
}
 
开发者ID:OverloadedCore,项目名称:kaosEssentials,代码行数:12,代码来源:Core.java

示例10: onDamageByEntity

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler
public void onDamageByEntity(EntityDamageByEntityEvent event) {
	if (event.isCancelled()) {
		return;
	}
	if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
		Game game = Chambers.getInstance().getGameManager().getGame();
		if (game.getInvincibilityTime() > 0) {
			Player damager = (Player) event.getDamager();
			damager.sendMessage(ChatColor.RED + "The invincibility timer is still on.");
			event.setCancelled(true);
		}
	}
}
 
开发者ID:HuliPvP,项目名称:Chambers,代码行数:15,代码来源:GameDamageListener.java

示例11: onAttack

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getDamager() instanceof Player)
	{
		Player player = (Player)event.getDamager();
		ItemStack mainItem = player.getInventory().getItemInMainHand();
		
		if(dualWield.getScore(player).getScore() == 0)
		{
			if(mainItem.getType() == Material.GOLD_AXE)
			{
				if(spin.getScore(player).getScore() == 0)
				{
					if(player.getFoodLevel() > 6)
					{
						Random rand = new Random();
						
						Spin(player);
						
						if(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)
							player.setFoodLevel(player.getFoodLevel() - 1);
						
						int chance_reduceDur = rand.nextInt(10) + 1;
						switch(chance_reduceDur)
						{
							case 1:
								mainItem.setDurability((short)(mainItem.getDurability() + 1));
								break;
							default:
						}
						
						if(mainItem.getDurability() >= 32)
						{
							player.getLocation().getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
							player.getInventory().setItemInMainHand(null);
						}
						player.updateInventory();
					}
					else
					{
						player.sendMessage(ChatColor.RED + Survival.Words.get("Lack of energy, unable to spin"));
					}
				}
			}
		}
		else
		{
			event.setCancelled(true);
			return;
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:56,代码来源:Valkyrie.java

示例12: onAttack

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
	{
		Player player = (Player)event.getDamager();
		ItemStack mainItem = player.getInventory().getItemInMainHand();
		ItemStack offItem = player.getInventory().getItemInOffHand();
		LivingEntity enemy = (LivingEntity)event.getEntity();

		Random rand = new Random();
		
		if(mainItem.getType() == Material.WOOD_HOE)
		{
			enemy.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 80, 0, false));
			if(mainItem.getDurability() >= 59)
			{
				player.getLocation().getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
				player.getInventory().setItemInMainHand(null);
			}
		}
		
		if(offItem.getType() == Material.WOOD_HOE)
		{
			int chance_poison = rand.nextInt(4) + 1;
			switch(chance_poison)
			{
				case 1:
				case 2:
				enemy.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 80, 0, false));
				break;
				default:
			}
			offItem.setDurability((short)(offItem.getDurability() + 1));
			if(offItem.getDurability() >= 59)
			{
				player.getLocation().getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
				player.getInventory().setItemInOffHand(null);
			}
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:44,代码来源:ShivPoison.java

示例13: onAttack

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getEntity() instanceof Player)
	{
		Player player = (Player)event.getEntity();
		ItemStack offItem = player.getInventory().getItemInOffHand();

		if(dualWield.getScore(player).getScore() == 1)
		{
			event.setCancelled(true);
			return;
		}
		
		Random rand = new Random();
		
		if(offItem.getType() == Material.GOLD_HOE)
		{
			if(event.getDamager() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
			{
				LivingEntity enemy = (LivingEntity)event.getDamager();
				enemy.damage(event.getDamage() * 40 / 100, player);
			}
			
			int chance_reduceDur = rand.nextInt(10) + 1;
			switch(chance_reduceDur)
			{
				case 1:
					offItem.setDurability((short)(offItem.getDurability() + 1));
					break;
				default:
			}

			if(offItem.getDurability() >= 32)
			{
				player.getLocation().getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
				player.getInventory().setItemInOffHand(null);
			}
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:44,代码来源:GiantBlade.java

示例14: customDeath

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.HIGHEST)
public void customDeath(EntityDamageByEntityEvent e){
	if(e.isCancelled())return;
	if(e.getEntity() instanceof Player && e.getDamager() instanceof Player){
		Player p = (Player) e.getEntity();
		if(e.getFinalDamage() >= p.getHealth()){
			Player killer = (Player) e.getDamager();
			String uuid2 = killer.getUniqueId().toString();
			e.setCancelled(true);
			if(! p.getName().equals(killer.getName())){ // if they were killed by someone else, not themselves
				setTokens(uuid2, getTokens(uuid2)+2);
				killer.sendMessage(tag + ChatColor.BLUE + "You have received " + ChatColor.GOLD + "2" +
						ChatColor.BLUE + " tokens for killing " + p.getName());
			}
			Bukkit.getServer().broadcastMessage(ChatColor.GRAY + killer.getName() + " destroyed " + p.getName());
			// Set statistics
			//killer.setStatistic(Statistic.KILL_ENTITY, killer.getStatistic(Statistic.KILL_ENTITY) + 1);
			//p.setStatistic(Statistic.DEATHS, p.getStatistic(Statistic.DEATHS) + 1);
			// Reset health, so they dont die
			p.setHealth(p.getMaxHealth());
			// Inventory clearing
			p.getInventory().clear();
			ItemStack air = new ItemStack(Material.AIR);
			p.getInventory().setHelmet(air);
			p.getInventory().setChestplate(air);
			p.getInventory().setLeggings(air);
			p.getInventory().setBoots(air);
			// Drop emerald at death location
			ItemStack reward = new ItemStack(Material.EMERALD);
			p.getWorld().dropItemNaturally(p.getLocation(), reward);
			// Clear potion effects
			for(PotionEffect pe : p.getActivePotionEffects()){
				p.removePotionEffect(pe.getType());
			}
			// Stop infinite kill glitch
			p.setGameMode(GameMode.SPECTATOR);
			p.setGameMode(GameMode.ADVENTURE);
			// Send them to the SPAWN of the world
			p.teleport(p.getWorld().getSpawnLocation());
			p.setFireTicks(0);
		}
	}
}
 
开发者ID:OverloadedCore,项目名称:kaosEssentials,代码行数:44,代码来源:Core.java

示例15: onEntityDamageByEntity

import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的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);
	}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:64,代码来源:KnockBackListener.java


注:本文中的org.bukkit.event.entity.EntityDamageByEntityEvent.isCancelled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。