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

The following examples show how to use org.bukkit.potion.PotionEffect#getAmplifier() . 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: FeatureEmulation.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPotionEffectAdd(EntityPotionEffectEvent event) {
	if (!(event.getEntity() instanceof Player)) {
		return;
	}
	Player player = (Player) event.getEntity();
	PotionEffect effect = event.getNewEffect();
	if (effect != null) {
		int amplifierByte = (byte) effect.getAmplifier();
		if (effect.getAmplifier() != amplifierByte) {
			event.setCancelled(true);
			player.addPotionEffect(new PotionEffect(
				effect.getType(), effect.getDuration(), amplifierByte,
				effect.isAmbient(), effect.hasParticles(), effect.hasIcon()
			));
		}
	}
}
 
Example 2
Source File: CraftMetaPotion.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public boolean addCustomEffect(PotionEffect effect, boolean overwrite) {
    Validate.notNull(effect, "Potion effect must not be null");

    int index = indexOfEffect(effect.getType());
    if (index != -1) {
        if (overwrite) {
            PotionEffect old = customEffects.get(index);
            if (old.getAmplifier() == effect.getAmplifier() && old.getDuration() == effect.getDuration() && old.isAmbient() == effect.isAmbient()) {
                return false;
            }
            customEffects.set(index, effect);
            return true;
        } else {
            return false;
        }
    } else {
        if (customEffects == null) {
            customEffects = new ArrayList<PotionEffect>();
        }
        customEffects.add(effect);
        return true;
    }
}
 
Example 3
Source File: NightVision.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
private void sendAddPotionEffect(Player p, PotionEffect effect) {
    PacketContainer packet = new PacketContainer(ENTITY_EFFECT);
    //noinspection deprecation
    int effectID = effect.getType().getId();
    int amplifier = effect.getAmplifier();
    int duration = effect.getDuration();
    int entityID = p.getEntityId();
    packet.getIntegers().write(0, entityID);
    packet.getBytes().write(0, (byte) effectID);
    packet.getBytes().write(1, (byte) amplifier);
    packet.getIntegers().write(1, duration);
    // hide particles in 1.9
    packet.getBytes().write(2, (byte) 0);
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Cannot send packet", e);
    }
}
 
Example 4
Source File: CraftMetaPotion.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public boolean addCustomEffect(PotionEffect effect, boolean overwrite) {
    Validate.notNull(effect, "Potion effect must not be null");

    int index = indexOfEffect(effect.getType());
    if (index != -1) {
        if (overwrite) {
            PotionEffect old = customEffects.get(index);
            if (old.getAmplifier() == effect.getAmplifier() && old.getDuration() == effect.getDuration() && old.isAmbient() == effect.isAmbient()) {
                return false;
            }
            customEffects.set(index, effect);
            return true;
        } else {
            return false;
        }
    } else {
        if (customEffects == null) {
            customEffects = new ArrayList<PotionEffect>();
        }
        customEffects.add(effect);
        return true;
    }
}
 
Example 5
Source File: CombatLogTracker.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private static double getResistanceFactor(LivingEntity entity) {
    int amplifier = 0;
    for(PotionEffect effect : entity.getActivePotionEffects()) {
        if(PotionEffectType.DAMAGE_RESISTANCE.equals(effect.getType()) && effect.getAmplifier() > amplifier) {
            amplifier = effect.getAmplifier();
        }
    }
    return 1d - (amplifier / 5d);
}
 
Example 6
Source File: IndicatorListener.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
private void showPotionHologram(Entity e, Collection<PotionEffect> effects) {
    for (PotionEffect effect : effects) {
        int amp = (effect.getAmplifier() < 1 ? 1 : effect.getAmplifier()) + 1;
        String content = Settings.INDICATOR_FORMAT.getValue("potion", effect.getType().getName().toLowerCase());
        content = content.replace("%effect%", StringUtil.capitalise(effect.getType().getName().replace("_", " "))).replace("%amp%", "" + new RomanNumeral(amp));
        Location l = e.getLocation().clone();
        l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("potion"));
        HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("potion"), true, content);
    }
}
 
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: 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 9
Source File: GlobalItemParser.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private PotionEffect checkPotionEffect(PotionEffect effect, Node node) throws InvalidXMLException {
    if(effect.getType().equals(PotionEffectType.HEALTH_BOOST) && effect.getAmplifier() < 0) {
        if(effect.getDuration() != Integer.MAX_VALUE) {
            // TODO: enable this check after existing maps are fixed
            // throw new InvalidXMLException("Negative health boost effect must have infinite duration (use max-health instead)", node);
        }
    }
    return effect;
}
 
Example 10
Source File: MoveEvent.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
private boolean testJumped() {
    int jumpBoostLvl = 0;
    for (PotionEffect pEffect : p.getActivePotionEffects()) {
        if (pEffect.getType().equals(PotionEffectType.JUMP)) {
            byte amp = (byte)pEffect.getAmplifier();
            jumpBoostLvl = amp + 1;
            break;
        }
    }
    float expectedDY = Math.max(0.42F + jumpBoostLvl * 0.1F, 0F);
    boolean leftGround = (pp.isOnGround() && !isOnGround());
    Vector from = pp.hasSentPosUpdate() ? getFrom().toVector() : pp.getPositionPredicted();
    float dY = (float)(getTo().getY() - from.getY());

    //Jumping right as you enter a 2-block-high space will not change your motY.
    //When these conditions are met, we'll give them the benefit of the doubt and say that they jumped.
    {
        AABB box = AABB.playerCollisionBox.clone();
        box.expand(-0.000001, -0.000001, -0.000001);
        box.translate(getTo().toVector().add(new Vector(0, expectedDY, 0)));
        boolean collidedNow = !box.getBlockAABBs(getTo().getWorld(), pp.getClientVersion()).isEmpty();

        box = AABB.playerCollisionBox.clone();
        box.expand(-0.000001, -0.000001, -0.000001);
        box.translate(getFrom().toVector().add(new Vector(0, expectedDY, 0)));
        boolean collidedBefore = !box.getBlockAABBs(getTo().getWorld(), pp.getClientVersion()).isEmpty();

        if(collidedNow && !collidedBefore && leftGround && dY == 0) {
            expectedDY = 0;
        }
    }

    boolean kbSimilarToJump = acceptedKnockback != null &&
            (Math.abs(acceptedKnockback.getY() - expectedDY) < 0.001 || hitCeiling);
    return !kbSimilarToJump && ((expectedDY == 0 && pp.isOnGround()) || leftGround) && (dY == expectedDY || hitCeiling);
}
 
Example 11
Source File: FlyOld.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
private int getJumpBoostLvl(Player p) {
    for (PotionEffect pEffect : p.getActivePotionEffects()) {
        if (pEffect.getType().equals(PotionEffectType.JUMP)) {
            return pEffect.getAmplifier() + 1;
        }
    }
    return 0;
}
 
Example 12
Source File: CombatLogTracker.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private static double getResistanceFactor(LivingEntity entity) {
  int amplifier = 0;
  for (PotionEffect effect : entity.getActivePotionEffects()) {
    if (PotionEffectType.DAMAGE_RESISTANCE.equals(effect.getType())
        && effect.getAmplifier() > amplifier) {
      amplifier = effect.getAmplifier();
    }
  }
  return 1d - (amplifier / 5d);
}
 
Example 13
Source File: MoveEvent.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
private Vector handlePendingVelocities() {
    List<Pair<Vector, Long>> kbs = pp.getPendingVelocities();
    if (kbs.size() > 0) {
        double epsilon = 0.003;
        int kbIndex;
        int expiredKbs = 0;
        long currTime = System.currentTimeMillis();
        Vector currVelocity = new Vector(getTo().getX() - getFrom().getX(), getTo().getY() - getFrom().getY(), getTo().getZ() - getFrom().getZ());
        boolean jump = pp.isOnGround() && Math.abs(0.42 - currVelocity.getY()) < 0.00001;
        double speedPotMultiplier = 1;
        for (PotionEffect effect : p.getActivePotionEffects()) {
            if (!effect.getType().equals(PotionEffectType.SPEED))
                continue;
            speedPotMultiplier = 1 + (effect.getAmplifier() + 1 * 0.2);
        }
        boolean flying          = pp.isFlying();
        double sprintMultiplier = flying ? (pp.isSprinting() ? 2 : 1) : (pp.isSprinting() ? 1.3 : 1);
        double weirdConstant    = (jump && pp.isSprinting() ? 0.2518462 : (pp.isSwimming() ? 0.0196 : 0.098)); //(pp.isOnGround() ? 0.098 : (flying ? 0.049 : 0.0196));
        double baseMultiplier   = flying ? (10 * p.getFlySpeed()) : (5 * p.getWalkSpeed() * speedPotMultiplier);
        double maxDiscrepancy   = weirdConstant * baseMultiplier * sprintMultiplier + epsilon;

        //pending knockbacks must be in order; get the first entry in the list.
        //if the first entry doesn't work (probably because they were fired on the same tick),
        //then work down the list until we find something
        for (kbIndex = 0; kbIndex < kbs.size(); kbIndex++) {
            Pair<Vector, Long> kb = kbs.get(kbIndex);

            //replace the following if-statement with this sometime? You'll have to worry about the else-statement, though.
            //int timeDiff = (int)(currTime - kb.getValue());
            //int ping = ServerUtils.getPing(p);
            //int lowerBound = 100;
            //int upperBound = 300;
            //if (timeDiff >= ping - lowerBound && timeDiff <= ping + upperBound) { //400ms window to allow for network jitter

            if (currTime - kb.getValue() <= ServerUtils.getPing(p) + 200) { //add 200 just in case the player's ping jumps a bit

                Vector kbVelocity = kb.getKey();
                double x = hitSlowdown ? 0.6 * kbVelocity.getX() : kbVelocity.getX();
                double y = kbVelocity.getY();
                double z = hitSlowdown ? 0.6 * kbVelocity.getZ() : kbVelocity.getZ();

                //check Y component
                //skip to next kb if...
                if (!((boxSidesTouchingBlocks.contains(Direction.TOP) && y > 0) || (boxSidesTouchingBlocks.contains(Direction.BOTTOM) && y < 0)) && /*...player isn't colliding...*/
                        Math.abs(y - currVelocity.getY()) > 0.01 && /*...and velocity is nowhere close to kb velocity...*/
                        !jump && !pp.isSwimming() && !step /*...and did not jump and is not swimming and did not "step"*/) {
                    continue;
                }

                double minThresX = x - maxDiscrepancy;
                double maxThresX = x + maxDiscrepancy;
                double minThresZ = z - maxDiscrepancy;
                double maxThresZ = z + maxDiscrepancy;

                //check X component
                //skip to next kb if...
                if (!((boxSidesTouchingBlocks.contains(Direction.EAST) && x > 0) || (boxSidesTouchingBlocks.contains(Direction.WEST) && x < 0)) && /*...player isn't colliding...*/
                        !(currVelocity.getX() <= maxThresX && currVelocity.getX() >= minThresX)) { /*...and velocity is nowhere close to kb velocity...*/
                    continue;
                }
                //check Z component
                //skip to next kb if...
                if (!((boxSidesTouchingBlocks.contains(Direction.SOUTH) && z > 0) || (boxSidesTouchingBlocks.contains(Direction.NORTH) && z < 0)) && /*...player isn't colliding...*/
                        !(currVelocity.getZ() <= maxThresZ && currVelocity.getZ() >= minThresZ)) { /*...and velocity is nowhere close to kb velocity...*/
                    continue;
                }
                kbs.subList(0, kbIndex + 1).clear();
                return kbVelocity;
            }
            else {
                failedKnockback = true;
                expiredKbs++;
            }
        }
        kbs.subList(0, expiredKbs).clear();
    }
    return null;
}
 
Example 14
Source File: MoveEvent.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
private float computeMaximumInputForce(boolean considerItemUse) {
    //"initForce" is the value of "strafe" or "forward" in MCP's moveEntityWithHeading(float, float) in
    //EntityLivingBase. When the WASD keys are polled, these are either incremented or decremented by 1.
    //Before reaching the method, the "strafe" and "forward" values are multiplied by 0.98,
    //and if sneaking, they are also multiplied by 0.3, and if using an item, they are also multiplied by 0.2.
    float initForce = 0.98F;
    if(pp.isSneaking())
        initForce *= 0.3;

    boolean usingItem = considerItemUse && (pp.isConsumingOrPullingBowMetadataIncluded() || pp.isBlocking());
    if(usingItem)
        initForce *= 0.2;
    boolean sprinting = pp.isSprinting() && !usingItem && !pp.isSneaking();
    boolean flying = pp.isFlying();

    float speedEffectMultiplier = 1;
    for (PotionEffect effect : p.getActivePotionEffects()) {
        if (!effect.getType().equals(PotionEffectType.SPEED))
            continue;
        int level = effect.getAmplifier() + 1;
        speedEffectMultiplier += (level * 0.2F);
    }

    //patch some inconsistencies
    boolean teleportBug = pp.getCurrentTick() == pp.getLastTeleportAcceptTick();
    boolean onGround = teleportBug ? pp.isOnGroundReally() : pp.isOnGround();

    //Skidded from MCP's moveEntityWithHeading(float, float) in EntityLivingBase
    float multiplier;
    if (onGround) {
        //0.16277136 technically should be 0.162771336. But this is what was written in MCP.
        //0.162771336 is not a magic number. It is 0.546^3
        multiplier = 0.1F * 0.16277136F / (newFriction * newFriction * newFriction);
        float groundMultiplier = 5 * p.getWalkSpeed() * speedEffectMultiplier;
        multiplier *= groundMultiplier;
    }
    else {
        float flyMultiplier = 10 * p.getFlySpeed();
        multiplier = (flying ? 0.05F : 0.02F) * flyMultiplier;
    }

    //Assume moving diagonally, since sometimes it's faster to move diagonally.
    //Skidded from MCP's moveFlying(float, float, float) in Entity
    float diagonal = (float)Math.sqrt(2 * initForce * initForce);
    if (diagonal < 1.0F) {
        diagonal = 1.0F;
    }
    //Force for each component of the diagonal vector.
    //Division by "diagonal" pretty much normalizes it... most of the time.
    float componentForce = initForce * multiplier / diagonal;

    //now find the hypotenuse i.e. magnitude of this diagonal vector
    float finalForce = (float)Math.sqrt(2 * componentForce * componentForce);

    return (float) (finalForce * (sprinting ? (flying ? 2 : 1.3) : 1));
}
 
Example 15
Source File: PotionEffectFlag.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
@Override
public Object marshal(PotionEffect o)
{
	return o.getType().getName() + " " + o.getAmplifier() + " " + o.hasParticles();
}
 
Example 16
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;
    }
}
 
Example 17
Source File: CraftPotionUtil.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public static net.minecraft.potion.PotionEffect fromBukkit(PotionEffect effect) {
    Potion type = Potion.getPotionById(effect.getType().getId());
    return new net.minecraft.potion.PotionEffect(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
}
 
Example 18
Source File: PotionUtil.java    From AACAdditionPro with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Used to get the Amplifier of a {@link PotionEffect}.
 *
 * @param effect the effect which should be tested.
 *
 * @return the amplifier of the {@link PotionEffect} or null if the player doesn't have it.
 */
public static Integer getAmplifier(final PotionEffect effect)
{
    return effect == null ?
           null :
           effect.getAmplifier();
}