/** * Patching witch's potions * * @param event Event */ @EventHandler public void onPotionSplash(PotionSplashEvent event) { ThrownPotion potion = event.getPotion(); if (potion.getShooter() instanceof Witch) { event.setCancelled(true); List<PotionEffectType> potionEffects = new ArrayList<>(); potionEffects.add(PotionEffectType.SLOW_DIGGING); potionEffects.add(PotionEffectType.CONFUSION); potionEffects.add(PotionEffectType.NIGHT_VISION); potionEffects.add(PotionEffectType.HUNGER); potionEffects.add(PotionEffectType.BLINDNESS); PotionEffect selected = new PotionEffect(potionEffects.get(new Random().nextInt(potionEffects.size())), 20 * 15, 1); for (LivingEntity ent : event.getAffectedEntities()) ent.addPotionEffect(selected); } }
@Override public Relation compare(final EntityData e, final ItemType i) { if (e instanceof Item) return Relation.get(i.isOfType(((Item) e).getItemStack())); if (e instanceof ThrownPotion) return Relation.get(i.isOfType(Material.POTION.getId(), PotionEffectUtils.guessData((ThrownPotion) e))); if (Skript.classExists("org.bukkit.entity.WitherSkull") && e instanceof WitherSkull) return Relation.get(i.isOfType(Material.SKULL_ITEM.getId(), (short) 1)); if (entityMaterials.containsKey(e.getType())) return Relation.get(i.isOfType(entityMaterials.get(e.getType()).getId(), (short) 0)); for (final Entry<Class<? extends Entity>, Material> m : entityMaterials.entrySet()) { if (m.getKey().isAssignableFrom(e.getType())) return Relation.get(i.isOfType(m.getValue().getId(), (short) 0)); } return Relation.NOT_EQUAL; }
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerInteract(PlayerInteractEvent event) { if (Action.RIGHT_CLICK_BLOCK == event.getAction() || Action.RIGHT_CLICK_AIR == event.getAction()) { Player player = event.getPlayer(); if (Material.POTION == player.getItemInHand().getType()) { event.setCancelled(true); ThrownPotion potion = player.launchProjectile(ThrownPotion.class); potion.setItem(player.getItemInHand()); int slot = player.getInventory().getHeldItemSlot(); player.getInventory().setItem(slot, player.getItemInHand()); player.updateInventory(); } } }
@EventHandler(ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent event) { if (!(event instanceof EntityDamageByEntityEvent)) return; EntityDamageByEntityEvent subEvent = (EntityDamageByEntityEvent) event; Player attacker = null; Entity damageSource = subEvent.getDamager(); if (damageSource instanceof Player) { attacker = (Player) damageSource; } else if (damageSource instanceof Arrow || damageSource instanceof ThrownPotion) { Projectile proj = (Projectile) damageSource; if (proj.getShooter() instanceof Player) attacker = (Player) proj.getShooter(); } if (attacker != null) PlayerHelper.resetIdleTimer(attacker); }
public void onSplashPotionThrown(PotionSplashEvent event) { ThrownPotion potion = event.getPotion(); PotionEffect pShort = new PotionEffect(PotionEffectType.INVISIBILITY, 2701, 0, true); PotionEffect pLong = new PotionEffect(PotionEffectType.INVISIBILITY, 7201, 0, true); LivingEntity entity = potion.getShooter(); if ((entity instanceof Player)) { if (locationInWarzone(entity.getLocation())) { if (potion.getEffects().contains(pShort)) { event.setCancelled(true); giveBackPotion((Player) entity, (short) 32702); } else if (potion.getEffects().contains(pLong)) { event.setCancelled(true); giveBackPotion((Player) entity, (short) 32766); } } } }
@EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) { Projectile entity = event.getEntity(); if (!(entity instanceof ThrownPotion)) { return; } ProjectileSource shooter = entity.getShooter(); if (!(shooter instanceof Player)) { return; } Location l = BukkitUtil.getLocation(entity); if (!PS.get().hasPlotArea(l.getWorld())) { return; } PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); Plot plot = l.getOwnedPlot(); if (plot != null && !plot.isAdded(pp.getUUID())) { entity.remove(); event.setCancelled(true); } }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPotionSplash(PotionSplashEvent event) { ThrownPotion damager = event.getPotion(); Location l = BukkitUtil.getLocation(damager); if (!PS.get().hasPlotArea(l.getWorld())) { return; } int count = 0; for (LivingEntity victim : event.getAffectedEntities()) { if (!entityDamage(damager, victim)) { event.setIntensity(victim, 0); count++; } } if ((count > 0 && count == event.getAffectedEntities().size()) || !onProjectileHit(event)) { event.setCancelled(true); } }
@EventHandler public void onPotionSplash(PotionSplashEvent event) { ThrownPotion potion = event.getEntity(); boolean harms = canHarm(potion); if (event.getEntity().getShooter() instanceof Player && disabledPlayers.contains((Player) event.getEntity().getShooter()) && harms) { event.setCancelled(true); ((Player) event.getEntity().getShooter()).sendMessage(ChatColor.DARK_RED + "You cannot harm other players with PvP off!"); return; } boolean cancellations = false; boolean everyone = true; for (LivingEntity e : event.getAffectedEntities()) { if (e instanceof Player && harms && disabledPlayers.contains((Player) e)) { event.setIntensity(e, 0.0); cancellations = true; } else { everyone = false; } } if (everyone) { event.setCancelled(true); ((Player) event.getEntity().getShooter()).sendMessage(ChatColor.LIGHT_PURPLE + "All targets of your splash potion has PvP disabled."); } else if (cancellations) { ((Player) event.getEntity().getShooter()).sendMessage(ChatColor.LIGHT_PURPLE + "Your splash potion's effects have been nullified on targets with PvP disabled."); } }
/** * 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; }
@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); } } }
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); } }
@Nullable @Override protected PotionEffect[] get(Event e) { Entity ent = entity.getSingle(e); if (ent == null) { return null; } if (ent instanceof ThrownPotion) { return ((ThrownPotion) ent).getEffects().stream().toArray(PotionEffect[]::new); } else if (ent instanceof TippedArrow) { return ((TippedArrow) ent).getCustomEffects().stream().toArray(PotionEffect[]::new); } return null; }
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) public void onPotionSplash(PotionSplashEvent event) { ThrownPotion potion = event.getPotion(); if (potion.getShooter() instanceof Player && BukkitUtils.isDebuff(potion)) { for (LivingEntity livingEntity : event.getAffectedEntities()) { if (livingEntity instanceof Player) { if (getRemaining((Player) livingEntity) > 0L) { event.setIntensity(livingEntity, 0); } } } } }
@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; }
@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; }
@Override public void set(final ThrownPotion entity) { if (types != null) { final ItemType t = CollectionUtils.getRandom(types); assert t != null; entity.setItem(t.getRandom()); } }
public static short guessData(final ThrownPotion p) { if (p.getEffects().size() == 1) { final PotionEffect e = p.getEffects().iterator().next(); final Potion d = new Potion(PotionType.getByEffect(e.getType())).splash(); return d.toDamageValue(); } return 0; }
@EventHandler public void onPotionSplash(PotionSplashEvent event) { ThrownPotion ePotion = event.getPotion(); Entity eShooter = ePotion.getShooter(); if (eShooter instanceof Player) { Player shooter = (Player) eShooter; BPPlayer bpShooter = BPPlayer.get(shooter); if (bpShooter.isInGame()) { Game game = bpShooter.getGame(); for (LivingEntity eTarget : event.getAffectedEntities()) if (eTarget instanceof Player) { Player target = (Player) eTarget; BPPlayer bpTarget = BPPlayer.get(target); if (bpTarget.isInGameWith(bpShooter)) game.getListener().onPlayerSplashedByPotion(event, bpShooter, bpTarget); else event.setIntensity(eTarget, 0); } else event.setIntensity(eTarget, 0); } else event.setCancelled(true); } else event.setCancelled(true); }
/** * PotionSplashEvent */ public static PotionSplashEvent callPotionSplashEvent(EntityPotion potion, Map<LivingEntity, Double> affectedEntities) { ThrownPotion thrownPotion = (ThrownPotion) potion.getBukkitEntity(); PotionSplashEvent event = new PotionSplashEvent(thrownPotion, affectedEntities); Bukkit.getPluginManager().callEvent(event); return event; }
private void handleTraps() { Player player = getPlayer(); if (Permissions.trapsBypass(player)) { return; } if (Misc.getRandom().nextBoolean()) { player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.Boom")); TNTPrimed tnt = (TNTPrimed) player.getWorld().spawnEntity(fishingCatch.getLocation(), EntityType.PRIMED_TNT); fishingCatch.setPassenger(tnt); Vector velocity = fishingCatch.getVelocity(); double magnitude = velocity.length(); fishingCatch.setVelocity(velocity.multiply((magnitude + 1) / magnitude)); tnt.setMetadata(mcMMO.tntsafeMetadataKey, mcMMO.metadataValue); tnt.setFuseTicks(3 * Misc.TICK_CONVERSION_FACTOR); } else { player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.Poison")); ThrownPotion thrownPotion = player.getWorld().spawn(fishingCatch.getLocation(), ThrownPotion.class); thrownPotion.setItem(new Potion(PotionType.POISON).splash().toItemStack(1)); fishingCatch.setPassenger(thrownPotion); } }
@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; }
public static LingeringPotionSplashEvent callLingeringPotionSplashEvent(EntityPotion potion, EntityAreaEffectCloud cloud) { ThrownPotion thrownPotion = (ThrownPotion) potion.getBukkitEntity(); AreaEffectCloud effectCloud = (AreaEffectCloud) cloud.getBukkitEntity(); LingeringPotionSplashEvent event = new LingeringPotionSplashEvent(thrownPotion, effectCloud); Bukkit.getPluginManager().callEvent(event); return event; }
private boolean canHarm(ThrownPotion potion) { for (PotionEffect potionEffect : potion.getEffects()) { if (potionEffect.getType() == PotionEffectType.HARM || potionEffect.getType() == PotionEffectType.POISON || potionEffect.getType() == PotionEffectType.WEAKNESS || potionEffect.getType() == PotionEffectType.SLOW_DIGGING || potionEffect.getType() == PotionEffectType.HUNGER || potionEffect.getType() == PotionEffectType.BLINDNESS || potionEffect.getType() == PotionEffectType.SLOW) { return true; } } return false; }
public ExtendedPotionSplashEvent(final RegionDb db, final PotionSplashEvent event) { super(db.getPlugin(), event); final ThrownPotion potion = event.getPotion(); for (final PotionEffect e : potion.getEffects()) { if (getNegativeEffects().contains(e.getType())) { this.hasNegativeEffect = true; break; } } this.getPlugin().info(String.valueOf(this.hasNegativeEffect)); }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onDamage(EntityDamageByEntityEvent e) { if(e.getDamager() instanceof Player) { if(e.getEntity() instanceof Player) { //Player damager = (Player) e.getDamager(); //damager.sendMessage(ChatColor.RED + "you are not allowed to pvp on this server!"); if(!pl.getConfiguration().getPvpConfig().isFakePvpEnabled()) { e.setCancelled(true); } } } else if(e.getDamager() instanceof Arrow) { Arrow arrow = (Arrow) e.getDamager(); if(arrow.getShooter() instanceof Player) { if(e.getEntity() instanceof Player) { //Player damager = (Player) arrow.getShooter(); //damager.sendMessage(ChatColor.RED + "you are not allowed to pvp on this server!"); arrow.remove(); e.setCancelled(true); } } } else if(e.getDamager() instanceof ThrownPotion) { ThrownPotion pot = (ThrownPotion) e.getDamager(); if(pot.getShooter() instanceof Player) { if(e.getEntity() instanceof Player) { //Player damager = (Player) pot.getShooter(); //damager.sendMessage(ChatColor.RED + "you are not allowed to pvp on this server!"); pot.remove(); e.setCancelled(true); } } } }
public Entity checkSource(Entity source) { if (source instanceof Player) { return source; } if ((source instanceof Projectile) && (((Projectile) source).getShooter() instanceof Player)) { return ((Projectile) source).getShooter(); } if ((source instanceof ThrownPotion) && (((ThrownPotion) source).getShooter() instanceof Player)) { return ((ThrownPotion) source).getShooter(); } return null; }