當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。