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

The following examples show how to use org.bukkit.potion.PotionEffect#getDuration() . 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: 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 2
Source File: GhostSquadronMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
private void reveal(Player player, int ticks) {
    RevealEntry entry = this.revealMap.get(player);
    if(entry == null) entry = new RevealEntry();

    entry.revealTicks = ticks;

    for(PotionEffect e : player.getActivePotionEffects()) {
        if(e.getType().equals(PotionEffectType.INVISIBILITY)) {
            entry.potionTicks = e.getDuration();
        }
    }

    player.removePotionEffect(PotionEffectType.INVISIBILITY);

    this.revealMap.put(player, entry);
}
 
Example 3
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 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: 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 6
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 7
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 8
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 9
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;
    }
}