Java Code Examples for org.bukkit.potion.PotionEffect#getType()

The following examples show how to use org.bukkit.potion.PotionEffect#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EffPoison.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(final Event e) {
	for (final LivingEntity le : entites.getArray(e)) {
		if (!cure) {
			Timespan dur;
			int d = (int) (duration != null && (dur = duration.getSingle(e)) != null ? 
					(dur.getTicks_i() >= Integer.MAX_VALUE ? Integer.MAX_VALUE : dur.getTicks_i()) : DEFAULT_DURATION);
			if (le.hasPotionEffect(PotionEffectType.POISON)) {
				for (final PotionEffect pe : le.getActivePotionEffects()) {
					if (pe.getType() != PotionEffectType.POISON)
						continue;
					d += pe.getDuration();
				}
			}
			le.addPotionEffect(new PotionEffect(PotionEffectType.POISON, d, 0), true);
		} else {
			le.removePotionEffect(PotionEffectType.POISON);
		}
	}
}
 
Example 2
Source File: CraftMetaPotion.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public boolean removeCustomEffect(PotionEffectType type) {
    Validate.notNull(type, "Potion effect type must not be null");

    if (!hasCustomEffects()) {
        return false;
    }

    boolean changed = false;
    Iterator<PotionEffect> iterator = customEffects.iterator();
    while (iterator.hasNext()) {
        PotionEffect effect = iterator.next();
        if (effect.getType() == type) {
            iterator.remove();
            changed = true;
        }
    }
    return changed;
}
 
Example 3
Source File: PotionClassifier.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public static double getScore(final PotionEffect effect) throws IllegalArgumentException {
  int level =
      effect.getAmplifier(); //  Level (>= 1 is normal effect, == 0 is no effect, < 0 is inverse
  // effect)
  PotionEffectType effectType = effect.getType();

  return (level >= 0
          ? potionEffectTypeImplications.getOrDefault(effectType, UNKNOWN)
          : inversePotionEffectTypeImplications.getOrDefault(effectType, UNKNOWN))
      * Math.abs(level)
      * ((double) effect.getDuration() / 20);
}
 
Example 4
Source File: Alive.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private void playDeathEffect(@Nullable ParticipantState killer) {
  playDeathSound(killer);

  // negative health boost potions sometimes change max health
  for (PotionEffect effect : bukkit.getActivePotionEffects()) {
    // Keep speed and NV for visual continuity
    if (effect.getType() != null
        && !PotionEffectType.NIGHT_VISION.equals(effect.getType())
        && !PotionEffectType.SPEED.equals(effect.getType())) {

      bukkit.removePotionEffect(effect.getType());
    }
  }

  // Flash/wobble the screen. If we don't delay this then the client glitches out
  // when the player dies from a potion effect. I have no idea why it happens,
  // but this fixes it. We could investigate a better fix at some point.
  smm.getMatch()
      .getExecutor(MatchScope.LOADED)
      .execute(
          () -> {
            if (bukkit.isOnline()) {
              bukkit.addPotionEffect(
                  new PotionEffect(
                      PotionEffectType.BLINDNESS,
                      options.blackout ? Integer.MAX_VALUE : 21,
                      0,
                      true,
                      false),
                  true);
              bukkit.addPotionEffect(
                  new PotionEffect(PotionEffectType.CONFUSION, 100, 0, true, false), true);
            }
          });
}
 
Example 5
Source File: MatchPlayer.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public void resetPotions() {
    final Player bukkit = getBukkit();
    for(PotionEffect effect : bukkit.getActivePotionEffects()) {
        if(effect.getType() != null) {
            bukkit.removePotionEffect(effect.getType());
        }
    }
}
 
Example 6
Source File: Alive.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private void playDeathEffect(@Nullable ParticipantState killer) {
    playDeathSound(killer);

    // negative health boost potions sometimes change max health
    for(PotionEffect effect : bukkit.getActivePotionEffects()) {
        // Keep speed and NV for visual continuity
        if(effect.getType() != null &&
           !PotionEffectType.NIGHT_VISION.equals(effect.getType()) &&
           !PotionEffectType.SPEED.equals(effect.getType())) {

            bukkit.removePotionEffect(effect.getType());
        }
    }
}
 
Example 7
Source File: QAMain.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
public static void toggleNightvision(Player player, Gun g, boolean add) {
	if (add) {
		if (g.getZoomWhenIronSights() > 0) {
			currentlyScoping.add(player.getUniqueId());
			player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1200, g.getZoomWhenIronSights()));
		}
		if (g.hasnightVision()) {
			currentlyScoping.add(player.getUniqueId());
			player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 1200, 3));
		}
	} else {
		if (currentlyScoping.contains(player.getUniqueId())) {
			if (player.hasPotionEffect(PotionEffectType.SLOW) && (g == null || g.getZoomWhenIronSights() > 0))
				player.removePotionEffect(PotionEffectType.SLOW);
			boolean potionEff = false;
			try {
				potionEff = player.hasPotionEffect(PotionEffectType.NIGHT_VISION)
						&& (g == null || g.hasnightVision())
						&& player.getPotionEffect(PotionEffectType.NIGHT_VISION).getAmplifier() == 3;
			} catch (Error | Exception e3452) {
				for (PotionEffect pe : player.getActivePotionEffects())
					if (pe.getType() == PotionEffectType.NIGHT_VISION)
						potionEff = (g == null || g.hasnightVision()) && pe.getAmplifier() == 3;
			}
			if (potionEff)
				player.removePotionEffect(PotionEffectType.NIGHT_VISION);
			currentlyScoping.remove(player.getUniqueId());
		}
	}

}
 
Example 8
Source File: ListenerPotions.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onTag(PlayerTagEvent e) {
    Player player = e.getPlayer();
    Collection<PotionEffect> potionEffectList = player.getActivePotionEffects();
    for(PotionEffect potionEffect : potionEffectList) {
        if(potionEffect == null) continue;

        PotionEffectType type = potionEffect.getType();
        if(isBlocked(type)) player.removePotionEffect(type);
    }
}
 
Example 9
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
    RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - Is PotionSplashEvent");

    ProjectileSource thrower = event.getPotion().getShooter();
    for (PotionEffect e : event.getPotion().getEffects()) {
        PotionEffectType t = e.getType();
        if (!t.equals(PotionEffectType.BLINDNESS) && !t.equals(PotionEffectType.CONFUSION) && !t.equals(PotionEffectType.HARM) && !t.equals(PotionEffectType.HUNGER) && !t.equals(PotionEffectType.POISON) && !t.equals(PotionEffectType.SLOW) && !t.equals(PotionEffectType.SLOW_DIGGING) && !t.equals(PotionEffectType.WEAKNESS) && !t.equals(PotionEffectType.WITHER)) {
            return;
        }
    }
    Player shooter;
    if (thrower instanceof Player) {
        shooter = (Player) thrower;
    } else {
        return;
    }
    for (Entity e2 : event.getAffectedEntities()) {
        Region r = RedProtect.get().rm.getTopRegion(e2.getLocation());
        if (event.getEntity() instanceof Player) {
            if (r != null && r.flagExists("pvp") && !r.canPVP((Player) event.getEntity(), shooter)) {
                event.setCancelled(true);
                return;
            }
        } else {
            if (r != null && !r.canInteractPassives(shooter)) {
                event.setCancelled(true);
                return;
            }
        }
    }
}
 
Example 10
Source File: InventoryUtils.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public static @Nullable PotionEffectType getPrimaryEffectType(ItemStack potion) {
  for (PotionEffect effect : getEffects(potion)) {
    return effect.getType();
  }
  return null;
}
 
Example 11
Source File: MatchPlayerImpl.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void reset() {
  getMatch().callEvent(new PlayerResetEvent(this));

  setFrozen(false);
  Player bukkit = getBukkit();
  bukkit.closeInventory();
  resetInventory();
  bukkit.setArrowsStuck(0);
  bukkit.setExhaustion(0);
  bukkit.setFallDistance(0);
  bukkit.setFireTicks(0);
  bukkit.setFoodLevel(20); // full
  bukkit.setHealth(bukkit.getMaxHealth());
  bukkit.setLevel(0);
  bukkit.setExp(0); // clear xp
  bukkit.setSaturation(5); // default
  bukkit.setAllowFlight(false);
  bukkit.setFlying(false);
  bukkit.setSneaking(false);
  bukkit.setSprinting(false);
  bukkit.setFlySpeed(0.1f);
  bukkit.setKnockbackReduction(0);
  bukkit.setWalkSpeed(WalkSpeedKit.BUKKIT_DEFAULT);

  for (PotionEffect effect : bukkit.getActivePotionEffects()) {
    if (effect.getType() != null) {
      bukkit.removePotionEffect(effect.getType());
    }
  }

  for (Attribute attribute : ATTRIBUTES) {
    AttributeInstance attributes = bukkit.getAttribute(attribute);
    if (attributes == null) continue;

    for (AttributeModifier modifier : attributes.getModifiers()) {
      attributes.removeModifier(modifier);
    }
  }

  NMSHacks.setAbsorption(bukkit, 0);

  // we only reset bed spawn here so people don't have to see annoying messages when they respawn
  bukkit.setBedSpawnLocation(null);
}
 
Example 12
Source File: Poisonous.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
	if (!dropPoisonedMeat) {
		return;
	}

	LivingEntity mob = event.getEntity();
	Player player = mob.getKiller();

	if (player == null) {
		return;
	}

	if (Lists.WORLDS.contains(player.getWorld().getName())) {
		return;
	}

	boolean isPoisoned = false;

	for (PotionEffect potionEffect : mob.getActivePotionEffects()) {
		if (potionEffect.getType() == PotionEffectType.POISON) {
			isPoisoned = true;
			break;
		}
	}

	if (!isPoisoned) {
		return;
	}

	int numberOfMeat = 0;
	int numberOfPotatoes = 0;

	Iterator<ItemStack> iterator = event.getDrops().iterator();

	while (iterator.hasNext()) {
		ItemStack drop = iterator.next();
		if (isMeat(drop)) {
			iterator.remove();
			numberOfMeat++;
		} else if (drop.getType() == Material.POTATO) {
			iterator.remove();
			numberOfPotatoes++;
		}
	}

	ChatWriter.logModifier(player, event, this, player.getInventory().getItemInMainHand(),
			"Entity(" + event.getEntity().getType().toString() + ")");

	if (numberOfMeat > 0) event.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, numberOfMeat));
	if (numberOfPotatoes > 0) event.getDrops().add(new ItemStack(Material.POISONOUS_POTATO, numberOfPotatoes));
}
 
Example 13
Source File: PotionUtils.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static @Nullable PotionEffectType primaryEffectType(ItemStack potion) {
    for(PotionEffect effect : effects(potion)) {
        return effect.getType();
    }
    return null;
}
 
Example 14
Source File: PotionHandler.java    From BetonQuest with GNU General Public License v3.0 4 votes vote down vote up
boolean check(PotionEffect effect) {
    switch (customTypeE) {
        case WHATEVER:
            return true;
        case REQUIRED:
            if (effect.getType() != customType) {
                return false;
            }
            switch (durationE) {
                case EQUAL:
                    if (duration != effect.getDuration()) {
                        return false;
                    }
                    break;
                case MORE:
                    if (duration > effect.getDuration()) {
                        return false;
                    }
                    break;
                case LESS:
                    if (duration < effect.getDuration()) {
                        return false;
                    }
                    break;
                case WHATEVER:
                    break;
            }
            switch (powerE) {
                case EQUAL:
                    if (power != effect.getAmplifier()) {
                        return false;
                    }
                    break;
                case MORE:
                    if (power > effect.getAmplifier()) {
                        return false;
                    }
                    break;
                case LESS:
                    if (power < effect.getAmplifier()) {
                        return false;
                    }
                    break;
                case WHATEVER:
                    break;
            }
            return true;
        case FORBIDDEN:
            return effect == null;
        default:
            return false;
    }
}