Java Code Examples for org.bukkit.potion.PotionEffectType#getByName()

The following examples show how to use org.bukkit.potion.PotionEffectType#getByName() . 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: EffectEvent.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
public EffectEvent(Instruction instruction) throws InstructionParseException {
    super(instruction, true);
    String type = instruction.next();
    effect = PotionEffectType.getByName(type);
    if (effect == null) {
        throw new InstructionParseException("Effect type '" + type + "' does not exist");
    }
    try {
        duration = instruction.getVarNum();
        amplifier = instruction.getVarNum();
    } catch (NumberFormatException e) {
        throw new InstructionParseException("Could not parse number arguments", e);
    }

    if (instruction.hasArgument("--ambient")) {
        LogUtils.getLogger().log(Level.WARNING, instruction.getID().getFullID() + ": Effect event uses \"--ambient\" which is deprecated. Please use \"ambient\"");
        ambient = true;
    } else {
        ambient = instruction.hasArgument("ambient");
    }

    hidden = instruction.hasArgument("hidden");
    icon = !instruction.hasArgument("noicon");
}
 
Example 2
Source File: JsonItemUtils.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
public static PotionEffect parsePotionEffect(JsonObject jsonEffect) throws ParseException{
    PotionEffectType type = PotionEffectType.getByName(jsonEffect.get("type").getAsString());

    if (type == null){
        throw new ParseException("Invalid potion type: " + jsonEffect.get("type").getAsString());
    }

    int duration;
    int amplifier;

    try {
        duration = jsonEffect.get("duration").getAsInt();
        amplifier = jsonEffect.get("amplifier").getAsInt();
    }catch (NullPointerException ex){
        throw new ParseException("Missing duration or amplifier tag for: " + jsonEffect.toString());
    }

    return new PotionEffect(type, duration, amplifier);
}
 
Example 3
Source File: Instruction.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
public List<PotionEffect> getEffects(String string) throws InstructionParseException {
    if (string == null) {
        return null;
    }
    List<PotionEffect> effects = new ArrayList<>();
    String[] array = getArray(string);
    for (String effect : array) {
        String[] effParts = effect.split(":");
        PotionEffectType ID = PotionEffectType.getByName(effParts[0]);
        if (ID == null) {
            throw new PartParseException("Unknown potion effect" + effParts[0]);
        }
        int power, duration;
        try {
            power = Integer.parseInt(effect.split(":")[1]) - 1;
            duration = Integer.parseInt(effect.split(":")[2]) * 20;
        } catch (NumberFormatException e) {
            throw new PartParseException("Could not parse potion power/duration: " + effect, e);
        }
        effects.add(new PotionEffect(ID, duration, power));
    }
    return effects;
}
 
Example 4
Source File: Wild.java    From WildernessTp with MIT License 6 votes vote down vote up
public static void applyPotions(Player p) {
    List<String> potions = instance.getConfig().getStringList("Potions");
    int size = potions.size();
    if (size != 0) {
        for (int i = 0; i <= size - 1; i++) {
            String potDur = potions.get(i);
            String[] potionDuration = potDur.split(":");
            String pot = potionDuration[0];
            String dur = potionDuration[1];
            int duration = Integer.parseInt(dur) * 20;
            pot = pot.toUpperCase();
            PotionEffectType potion = PotionEffectType.getByName(pot);
            p.addPotionEffect(new PotionEffect(potion, duration, 100));
        }
    }
}
 
Example 5
Source File: PotionEffectFlag.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
@Override
public PotionEffect parseInput(FlagContext context) throws InvalidFlagFormat
{
	String[] split = context.getUserInput().trim().split(" ");
	if (split.length < 1 || split.length > 3)
	{
		throw new InvalidFlagFormat("Please use the following format: <effect name> [effect amplifier] [show particles]");
	}
	
	PotionEffectType potionEffect = PotionEffectType.getByName(split[0]);
	if (potionEffect == null)
	{
		throw new InvalidFlagFormat("Unable to find the potion effect type! Please refer to https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html");
	}
	
	return this.buildPotionEffect(split);
}
 
Example 6
Source File: PotionEffectFlag.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
private PotionEffect buildPotionEffect(String[] split)
{
	PotionEffectType potionEffect = PotionEffectType.getByName(split[0]);
	
	int amplifier = 0;
	if (split.length >= 2)
	{
		amplifier = Integer.parseInt(split[1]);
	}
	
	boolean showParticles = false;
	if (split.length >= 3)
	{
		showParticles = Boolean.parseBoolean(split[2]);
	}
	
	return new PotionEffect(potionEffect, PotionEffectFlag.POTION_EFFECT_DURATION, amplifier, true, showParticles);
}
 
Example 7
Source File: Parser.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static PotionEffect getPotion(Element potion) {
    PotionEffectType type = PotionEffectType.getByName(Strings.getTechnicalName(potion.getText()));
    if (type == null) type = new CraftPotionEffectType(MobEffectList.getByName(potion.getText().toLowerCase().replace(" ","_")));
    int duration = (int) (Strings.timeStringToExactSeconds(potion.getAttributeValue("duration")) * 20);
    int amplifier = 0;
    boolean ambient = false;
    if (potion.getAttributeValue("amplifier") != null)
        amplifier = Numbers.parseInt(potion.getAttributeValue("amplifier")) - 1;
    if (potion.getAttributeValue("ambient") != null)
        ambient = Boolean.parseBoolean(potion.getAttributeValue("ambient").toUpperCase());
    return new PotionEffect(type, duration, amplifier, ambient);
}
 
Example 8
Source File: XMLUtils.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public static PotionEffectType parsePotionEffectType(Node node, String text)
    throws InvalidXMLException {
  PotionEffectType type = PotionEffectType.getByName(text.toUpperCase().replace(" ", "_"));
  if (type == null) type = NMSHacks.getPotionEffectType(text);
  if (type == null) {
    throw new InvalidXMLException("Unknown potion type '" + node.getValue() + "'", node);
  }
  return type;
}
 
Example 9
Source File: EffectCondition.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
public EffectCondition(Instruction instruction) throws InstructionParseException {
    super(instruction, true);
    String string = instruction.next();
    type = PotionEffectType.getByName(string);
    if (type == null) {
        throw new InstructionParseException("Effect " + string + " does not exist");
    }
}
 
Example 10
Source File: ItemStackParser.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void parsePotionEffects() {
  PotionMeta customPotionMeta = (PotionMeta) this.finalStack.getItemMeta();
  for (Object potionEffect : (List<Object>) this.linkedSection.get("effects")) {
    LinkedHashMap<String, Object> potionEffectSection =
        (LinkedHashMap<String, Object>) potionEffect;

    if (!potionEffectSection.containsKey("type")) {
      continue;
    }

    PotionEffectType potionEffectType = null;
    int duration = 1;
    int amplifier = 0;

    potionEffectType =
        PotionEffectType.getByName(potionEffectSection.get("type").toString().toUpperCase());

    if (potionEffectSection.containsKey("duration")) {
      duration = Integer.parseInt(potionEffectSection.get("duration").toString()) * 20;
    }

    if (potionEffectSection.containsKey("amplifier")) {
      amplifier = Integer.parseInt(potionEffectSection.get("amplifier").toString()) - 1;
    }

    if (potionEffectType == null) {
      continue;
    }

    customPotionMeta.addCustomEffect(new PotionEffect(potionEffectType, duration, amplifier),
        true);
  }

  this.finalStack.setItemMeta(customPotionMeta);
}
 
Example 11
Source File: PotionEffectTypeFlag.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@Override
public PotionEffectType parseInput(FlagContext context) throws InvalidFlagFormat
{
	PotionEffectType potionEffect = PotionEffectType.getByName(context.getUserInput().trim());
	if (potionEffect != null)
	{
		return potionEffect;
	}
	else
	{
		throw new InvalidFlagFormat("Unable to find the potion effect type! Please refer to https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html");
	}
}
 
Example 12
Source File: CheckConfig.java    From WildernessTp with MIT License 5 votes vote down vote up
public boolean isCorrectPots() {
    List<String> pots = wild.getListPots();
    for (String s : pots) {
        String[] pot = s.split(":");
        if (pot.length != 2 || PotionEffectType.getByName(pot[0])==null) {
            return false;
        }
    }
    return true;
}
 
Example 13
Source File: CivPotionEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public CivPotionEffect(Spell spell, String key, Object target, Entity origin, int level, String value) {
    super(spell, key, target, origin, level, value);
    this.type = PotionEffectType.getByName(value);
    this.ticks = 40;
    this.level = 1;
    this.target = "self";

    this.potion = new PotionEffect(type, ticks, this.level);
}
 
Example 14
Source File: CivPotionEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public CivPotionEffect(Spell spell, String key, Object target, Entity origin, int level, ConfigurationSection section) {
    super(spell, key, target, origin, level, section);
    this.type = PotionEffectType.getByName(section.getString("type", "POISON"));
    this.ticks = (int) Math.round(Spell.getLevelAdjustedValue("" + section.getInt("ticks", 40), level, target, spell));
    this.level = (int) Math.round(Spell.getLevelAdjustedValue("" + section.getInt("level", 1), level, target, spell));
    String tempTarget = section.getString("target", "not-a-string");
    if (!tempTarget.equals("not-a-string")) {
        this.target = tempTarget;
    } else {
        this.target = "self";
    }
    this.config = section;

    this.potion = new PotionEffect(type, ticks, this.level);
}
 
Example 15
Source File: XMLUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static PotionEffectType parsePotionEffectType(Node node, String text) throws InvalidXMLException {
    PotionEffectType type = PotionEffectType.getByName(text.toUpperCase().replace(" ", "_"));
    if(type == null) type = Bukkit.potionEffectRegistry().get(parseKey(node, text));
    if(type == null) {
        throw new InvalidXMLException("Unknown potion effect '" + node.getValue() + "'", node);
    }
    return type;
}
 
Example 16
Source File: Items.java    From TabooLib with MIT License 5 votes vote down vote up
public static PotionEffectType asPotionEffectType(String potion) {
    try {
        PotionEffectType type = PotionEffectType.getByName(potion);
        return type != null ? type : PotionEffectType.getById(NumberConversions.toInt(potion));
    } catch (Throwable e) {
        return null;
    }
}
 
Example 17
Source File: PotionEffectTypeFlag.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
@Override
public PotionEffectType unmarshal(Object o)
{
	return PotionEffectType.getByName(o.toString());
}
 
Example 18
Source File: PotionAreaEffect.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
private void applyPotion(String potionString, UUID uuid, String typeName, boolean isMember, String key) {
    for (String currentPotionString : potionString.split(",")) {
        String[] splitPotionString = currentPotionString.split("\\.");
        String potionTypeString = splitPotionString[0];

        boolean invert = potionTypeString.startsWith("^");

        if (invert) {
            potionTypeString = potionTypeString.substring(1);
        }

        if (invert == isMember) {
            return;
        }

        PotionEffectType potionType;
        int duration = 40;
        int amplifier = 1;
        int chance = 100;
        int cooldown = 0;
        try {
            potionType = PotionEffectType.getByName(potionTypeString);
            if (potionType == null) {
                Civs.logger.severe("Invalid potion type for " + typeName);
                return;
            }
            if (splitPotionString.length > 1) {
                duration = Integer.parseInt(splitPotionString[1]);
            }
            if (splitPotionString.length > 2) {
                amplifier = Integer.parseInt(splitPotionString[2]);
            }
            if (splitPotionString.length > 3) {
                chance = Integer.parseInt(splitPotionString[3]);
                chance = Math.max(Math.min(chance, 100), 0);
            }
            if (splitPotionString.length > 4) {
                cooldown = Integer.parseInt(splitPotionString[4]);
                cooldown = Math.max(cooldown, 0);
            }
        } catch (Exception e) {
            Civs.logger.severe("Invalid potion type for " + typeName);
            return;
        }
        if (Math.random() * 100 > chance) {
            return;
        }
        if (cooldown > 0) {
            cooldowns.put(key, System.currentTimeMillis() + (cooldown * 1000));
        }

        PotionEffect potionEffect = new PotionEffect(potionType, duration * 20, amplifier);

        Player player = Bukkit.getPlayer(uuid);
        if (player == null) {
            return;
        }
        player.addPotionEffect(potionEffect);
    }
}
 
Example 19
Source File: PotionEffectApplier.java    From EliteMobs with GNU General Public License v3.0 2 votes vote down vote up
private HashMap<PotionEffect, List<String>> potionEffectCreator(List<String> deobfuscatedLore, boolean event) {

        HashMap<PotionEffect, List<String>> potionEffects = new HashMap<>();


        for (String string : deobfuscatedLore) {

            int substringIndex = 0;
            PotionEffectType potionEffectType = null;
            int potionEffectMagnitude = 0;
            String victim;
            List<String> tags = new ArrayList<>();


            for (String substring : string.split(":")) {

                if (substringIndex == 0) {

                    potionEffectType = PotionEffectType.getByName(substring);

                }

                if (substringIndex == 1) {

                    potionEffectMagnitude = Integer.parseInt(substring);

                }

                if (substringIndex == 2) {

                    victim = substring;
                    if (victim.equalsIgnoreCase(TARGET) || victim.equalsIgnoreCase(SELF)) {

                        tags.add(victim);

                    } else {

                        Bukkit.getLogger().info("[EliteMobs] Error with ItemsCustomLootList.yml: was expecting '" + TARGET + "' or '"
                                + SELF + "' values but got '" + victim + "' instead.");

                    }

                }

                if (substringIndex == 3) {

                    if (substring.equalsIgnoreCase(CONTINUOUS)) {

                        tags.add(substring);

                    } else if (substring.equalsIgnoreCase(ONHIT)) {

                        tags.add(substring);

                    } else {

                        Bukkit.getLogger().info("[EliteMobs] Error with ItemsCustomLootList.yml: was expecting '" + CONTINUOUS +
                                "' or '" + ONHIT + "' value but got '" + substring + "' instead.");

                    }

                }

                substringIndex++;

            }

            if (potionEffectType != null && potionEffectMagnitude > 0) {

                PotionEffect potionEffect;

                if (!event) potionEffect = continuousPotionEffect(potionEffectType, potionEffectMagnitude - 1);
                else potionEffect = eventPotionEffect(potionEffectType, potionEffectMagnitude - 1);

                potionEffects.put(potionEffect, tags);

            } else {

                Bukkit.getLogger().info("[EliteMobs] There seems to be something very wrong with one of your potion effects.");
                Bukkit.getLogger().info("[EliteMobs] An item has an invalid potion effect or potion effect level.");
                Bukkit.getLogger().info("[EliteMobs] Problematic entry has the follow settings: " + string);

            }

        }


        return potionEffects;

    }