org.bukkit.entity.EnderPearl#org.bukkit.entity.ThrownPotion源码实例Demo

下面列出了org.bukkit.entity.EnderPearl#org.bukkit.entity.ThrownPotion 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: PGM   文件: PotionClassifier.java
public static double getScore(ThrownPotion potion) {
  double score = 0;

  for (PotionEffect effect :
      Iterables.concat(
          potion.getEffects(),
          ((PotionMeta) potion.getItem().getItemMeta()).getCustomEffects())) {
    score += getScore(effect);
  }

  return score;
}
 
源代码2 项目: PGM   文件: DamageMatchModule.java
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(final PotionSplashEvent event) {
  ThrownPotion potion = event.getPotion();
  if (!PotionClassifier.isHarmful(potion)) return;

  for (LivingEntity entity : event.getAffectedEntities()) {
    ParticipantState victim = match.getParticipantState(entity);
    DamageInfo damageInfo =
        tracker().resolveDamage(EntityDamageEvent.DamageCause.MAGIC, entity, potion);

    if (victim != null && queryDamage(event, victim, damageInfo).isDenied()) {
      event.setIntensity(entity, 0);
    }
  }
}
 
源代码3 项目: PGM   文件: EntityTracker.java
public PhysicalInfo createEntity(Entity entity, @Nullable ParticipantState owner) {
  if (entity instanceof ThrownPotion) {
    return new ThrownPotionInfo((ThrownPotion) entity, owner);
  } else if (entity instanceof FallingBlock) {
    return new FallingBlockInfo((FallingBlock) entity, owner);
  } else if (entity instanceof LivingEntity) {
    return new MobInfo((LivingEntity) entity, owner);
  } else {
    return new EntityInfo(entity, owner);
  }
}
 
源代码4 项目: ProjectAres   文件: DamageMatchModule.java
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(final PotionSplashEvent event) {
    final ThrownPotion potion = event.getPotion();
    if(PotionClassification.classify(potion) != PotionClassification.HARMFUL) return;

    for(LivingEntity victim : event.getAffectedEntities()) {
        final ParticipantState victimState = getMatch().getParticipantState(victim);
        final DamageInfo damageInfo = damageResolver.resolveDamage(EntityDamageEvent.DamageCause.MAGIC, victim, potion);

        if(victimState != null && queryDamage(event, victimState, damageInfo).isDenied()) {
            event.setIntensity(victim, 0);
        }
    }
}
 
源代码5 项目: ProjectAres   文件: EntityTracker.java
public PhysicalInfo createEntity(Entity entity, @Nullable ParticipantState owner) {
    if(entity instanceof ThrownPotion) {
        return new ThrownPotionInfo((ThrownPotion) entity, owner);
    } else if(entity instanceof FallingBlock) {
        return new FallingBlockInfo((FallingBlock) entity, owner);
    } else if(entity instanceof LivingEntity) {
        return new MobInfo((LivingEntity) entity, owner);
    } else {
        return new EntityInfo(entity, owner);
    }
}
 
源代码6 项目: Guilds   文件: EntityListener.java
/**
 * Handles splash potions+
 *
 * @param event
 */
@EventHandler
public void onSplash(PotionSplashEvent event) {
    boolean isHarming = false;
    for (PotionEffect effect : event.getPotion().getEffects()) {
        if (bad.contains(effect.getType())) {
            isHarming = true;
            break;
        }
    }

    if (!isHarming)
        return;

    ThrownPotion potion = event.getPotion();

    if (!(potion.getShooter() instanceof Player))
        return;

    Player shooter = (Player) potion.getShooter();

    for (LivingEntity entity : event.getAffectedEntities()) {
        if (entity instanceof Player) {
            Player player = (Player) entity;
            if (guildHandler.isSameGuild(shooter, player) && potion.getShooter() != player) {
                event.setCancelled(!settingsManager.getProperty(GuildSettings.GUILD_DAMAGE));
                return;
            }
            if (guildHandler.isAlly(shooter, player)) {
                event.setCancelled(!settingsManager.getProperty(GuildSettings.ALLY_DAMAGE));
            }
        }
    }

}
 
源代码7 项目: Skript   文件: ThrownPotionData.java
@Override
protected boolean init(final @Nullable Class<? extends ThrownPotion> c, final @Nullable ThrownPotion e) {
	if (e != null) {
		final ItemStack i = e.getItem();
		if (i == null)
			return false;
		types = new ItemType[] {new ItemType(i)};
	}
	return true;
}
 
源代码8 项目: Skript   文件: ThrownPotionData.java
@Override
protected boolean match(final ThrownPotion entity) {
	if (types != null) {
		for (final ItemType t : types) {
			if (t.isOfType(entity.getItem()))
				return true;
		}
		return false;
	}
	return true;
}
 
源代码9 项目: Skript   文件: ThrownPotionData.java
@Override
public void set(final ThrownPotion entity) {
	if (types != null) {
		final ItemType t = CollectionUtils.getRandom(types);
		assert t != null;
		ItemStack i = t.getRandom();
		if (i == null)
			return; // Missing item, can't make thrown potion of it
		entity.setItem(i);
	}
}
 
源代码10 项目: Skript   文件: PotionEffectUtils.java
public static short guessData(final ThrownPotion p) {
	if (p.getEffects().size() == 1) {
		final PotionEffect e = p.getEffects().iterator().next();
		PotionType type = PotionType.getByEffect(e.getType());
		assert type != null;
		final Potion d = new Potion(type).splash();
		return d.toDamageValue();
	}
	return 0;
}
 
源代码11 项目: Thermos   文件: CraftEventFactory.java
/**
 * PotionSplashEvent
 */
public static PotionSplashEvent callPotionSplashEvent(net.minecraft.entity.projectile.EntityPotion potion, Map<LivingEntity, Double> affectedEntities) {
    ThrownPotion thrownPotion = (ThrownPotion) potion.getBukkitEntity();

    PotionSplashEvent event = new PotionSplashEvent(thrownPotion, affectedEntities);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
 
源代码12 项目: ce   文件: PotionLauncher.java
@Override
public boolean effect(Event event, Player player) {
    int slot = player.getInventory().getHeldItemSlot();

    ItemStack potion = player.getInventory().getItem(slot + 1);
    Location loc = player.getLocation();
    if (potion != null && potion.getType().toString().contains("POTION")) {
        ThrownPotion tp = player.launchProjectile(ThrownPotion.class);
        EffectManager.playSound(loc, "ENTITY_GENERIC_EXPLODE", 0.5f, 2f);

        try {
            tp.setItem(potion);
        } catch (IllegalArgumentException ex) {
            ItemStack pt = potion.clone();
            if (potion.getType().equals(Material.POTION) || potion.getType().equals(Material.LINGERING_POTION))
                pt.setType(Material.SPLASH_POTION);
            tp.setItem(pt);
        }

        tp.setBounce(false);
        tp.setVelocity(loc.getDirection().multiply(ProjectileSpeedMultiplier));
        if (!player.getGameMode().equals(GameMode.CREATIVE)) {
            potion.setAmount(potion.getAmount() - 1);
            player.getInventory().setItem(slot + 1, potion);
            player.updateInventory();
        }
        return true;
    } else {
        player.sendMessage(ChatColor.RED + "You need a Potion in the slot to the right of the Potion Launcher!");
        player.getWorld().playEffect(loc, Effect.CLICK1, 5);
    }
    return false;
}
 
源代码13 项目: PGM   文件: PotionClassifier.java
public static boolean isHarmful(ThrownPotion potion) {
  return getScore(potion) <= HARMFUL;
}
 
源代码14 项目: PGM   文件: ThrownPotionInfo.java
public ThrownPotionInfo(ThrownPotion entity, @Nullable ParticipantState owner) {
  super(entity, owner);
  this.effectType = InventoryUtils.getPrimaryEffectType(entity.getItem());
}
 
源代码15 项目: PGM   文件: ThrownPotionInfo.java
public ThrownPotionInfo(ThrownPotion entity) {
  this(entity, null);
}
 
源代码16 项目: Kettle   文件: PotionSplashEvent.java
public PotionSplashEvent(final ThrownPotion potion, final Map<LivingEntity, Double> affectedEntities) {
    super(potion);

    this.affectedEntities = affectedEntities;
}
 
源代码17 项目: Kettle   文件: PotionSplashEvent.java
@Override
public ThrownPotion getEntity() {
    return (ThrownPotion) entity;
}
 
源代码18 项目: Kettle   文件: LingeringPotionSplashEvent.java
public LingeringPotionSplashEvent(final ThrownPotion potion, final AreaEffectCloud entity) {
    super(potion);
    this.entity = entity;
}
 
源代码19 项目: ProjectAres   文件: ThrownPotionInfo.java
public ThrownPotionInfo(ThrownPotion entity, @Nullable ParticipantState owner) {
    super(entity, owner);
    this.effectType = PotionUtils.primaryEffectType(entity.getItem());
}
 
源代码20 项目: ProjectAres   文件: ThrownPotionInfo.java
public ThrownPotionInfo(ThrownPotion entity) {
    this(entity, null);
}
 
源代码21 项目: Skript   文件: ThrownPotionData.java
@Override
public Class<? extends ThrownPotion> getType() {
	return ThrownPotion.class;
}
 
源代码22 项目: Thermos   文件: CraftLivingEntity.java
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
 
源代码23 项目: NPCFactory   文件: NPCEntity.java
@Override
public boolean damageEntity(DamageSource source, float damage) {
    if(godmode || noDamageTicks > 0) {
        return false;
    }

    DamageCause cause = null;
    org.bukkit.entity.Entity bEntity = null;
    if(source instanceof EntityDamageSource) {
        Entity damager = source.getEntity();
        cause = DamageCause.ENTITY_ATTACK;
        if(source instanceof EntityDamageSourceIndirect) {
            damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource();
            if(damager.getBukkitEntity() instanceof ThrownPotion) {
                cause = DamageCause.MAGIC;
            } else if(damager.getBukkitEntity() instanceof Projectile) {
                cause = DamageCause.PROJECTILE;
            }
        }

        bEntity = damager.getBukkitEntity();
    } else if(source == DamageSource.FIRE)
        cause = DamageCause.FIRE;
    else if(source == DamageSource.STARVE)
        cause = DamageCause.STARVATION;
    else if(source == DamageSource.WITHER)
        cause = DamageCause.WITHER;
    else if(source == DamageSource.STUCK)
        cause = DamageCause.SUFFOCATION;
    else if(source == DamageSource.DROWN)
        cause = DamageCause.DROWNING;
    else if(source == DamageSource.BURN)
        cause = DamageCause.FIRE_TICK;
    else if(source == CraftEventFactory.MELTING)
        cause = DamageCause.MELTING;
    else if(source == CraftEventFactory.POISON)
        cause = DamageCause.POISON;
    else if(source == DamageSource.MAGIC) {
        cause = DamageCause.MAGIC;
    } else if(source == DamageSource.OUT_OF_WORLD) {
        cause = DamageCause.VOID;
    }

    if(cause != null) {
        NPCDamageEvent event = new NPCDamageEvent(this, bEntity, cause, (double) damage);
        Bukkit.getPluginManager().callEvent(event);
        if(!event.isCancelled()) {
            return super.damageEntity(source, (float) event.getDamage());
        } else {
            return false;
        }
    }

    if(super.damageEntity(source, damage)) {
        if(bEntity != null) {
            Entity e = ((CraftEntity) bEntity).getHandle();
            double d0 = e.locX - this.locX;

            double d1;
            for(d1 = e.locZ - this.locZ; d0 * d0 + d1 * d1 < 0.0001D; d1 = (Math.random() - Math.random()) * 0.01D) {
                d0 = (Math.random() - Math.random()) * 0.01D;
            }

            a(e, damage, d0, d1);
        }

        return true;
    } else {
        return false;
    }
}
 
源代码24 项目: Kettle   文件: PotionSplashEvent.java
/**
 * Gets the potion which caused this event
 *
 * @return The thrown potion entity
 */
public ThrownPotion getPotion() {
    return (ThrownPotion) getEntity();
}