use of org.bukkit.potion.PotionEffectType in project EliteMobs by MagmaGuy.
the class EliteDropsHandler method superDropParser.
public void superDropParser() {
List<String> lootCount = lootCounter();
for (String lootEntry : lootCount) {
int itemPower = 0;
StringBuilder path = new StringBuilder();
path.append(lootEntry);
String previousPath = path.toString();
String itemType = itemTypeHandler(previousPath);
itemPower += itemTypePower(Material.getMaterial(itemType));
Bukkit.getLogger().info("Adding: " + previousPath);
String itemName = itemNameHandler(previousPath);
List itemLore = itemLoreHandler(previousPath);
List itemEnchantments = itemEnchantmentHandler(previousPath);
List potionEffects = itemPotionEffectHandler(previousPath);
ItemStack itemStack = new ItemStack(Material.getMaterial(itemType), 1);
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(itemName);
itemMeta.setLore(itemLore);
if (itemEnchantments != null) {
for (Object object : itemEnchantments) {
String string = object.toString();
String[] parsedString = string.split(",");
String enchantmentName = parsedString[0];
Enchantment enchantmentType = Enchantment.getByName(enchantmentName);
int enchantmentLevel = Integer.parseInt(parsedString[1]);
itemPower += enchantmentLevel;
itemMeta.addEnchant(enchantmentType, enchantmentLevel, true);
}
}
itemStack.setItemMeta(itemMeta);
lootList.add(itemStack);
List<PotionEffect> parsedPotionEffect = new ArrayList();
//Add potion effects to a separate list to reduce i/o operations
if (potionEffects != null) {
for (Object object : potionEffects) {
String string = object.toString();
String[] parsedString = string.split(",");
String potionEffectTypeString = parsedString[0];
PotionEffectType potionEffectType = PotionEffectType.getByName(potionEffectTypeString);
//this is a really bad way of doing things, two wrongs make a right
if (parsedString.length % 2 != 0) {
getLogger().info("Your item " + itemName + " has a problematic potions effect entry.");
}
int potionEffectAmplifier = Integer.parseInt(parsedString[1]);
itemPower += potionEffectAmplifier;
PotionEffect potionEffect = new PotionEffect(potionEffectType, 40, potionEffectAmplifier);
parsedPotionEffect.add(potionEffect);
}
potionEffectItemList.put(itemStack, parsedPotionEffect);
}
rankedItemMapCreator(itemPower, itemStack);
}
}
use of org.bukkit.potion.PotionEffectType in project CommandHelper by EngineHub.
the class BukkitMCLivingEntity method removeEffect.
@Override
public boolean removeEffect(int potionID) {
PotionEffectType t = PotionEffectType.getById(potionID);
boolean hasIt = false;
for (PotionEffect pe : le.getActivePotionEffects()) {
if (pe.getType() == t) {
hasIt = true;
break;
}
}
le.removePotionEffect(t);
return hasIt;
}
use of org.bukkit.potion.PotionEffectType in project CommandHelper by EngineHub.
the class BukkitMCPlayer method removeEffect.
@Override
public boolean removeEffect(int potionID) {
PotionEffectType t = PotionEffectType.getById(potionID);
boolean hasIt = false;
for (PotionEffect pe : p.getActivePotionEffects()) {
if (pe.getType() == t) {
hasIt = true;
break;
}
}
p.removePotionEffect(t);
return hasIt;
}
use of org.bukkit.potion.PotionEffectType in project MagicPlugin by elBukkit.
the class ConfigurationUtils method getPotionEffectObjects.
@Nullable
public static List<PotionEffect> getPotionEffectObjects(ConfigurationSection baseConfig, String key, Logger log) {
List<PotionEffect> potionEffects = null;
Collection<ConfigurationSection> potionEffectList = getNodeList(baseConfig, key);
if (potionEffectList != null) {
potionEffects = new ArrayList<>();
for (ConfigurationSection potionEffectSection : potionEffectList) {
try {
PotionEffectType effectType = PotionEffectType.getByName(potionEffectSection.getString("type").toUpperCase());
if (effectType == null) {
log.log(Level.WARNING, "Invalid potion effect type: " + potionEffectSection.getString("type", "(null)"));
continue;
}
int ticks = (int) (potionEffectSection.getLong("duration", 3600000) / 50);
ticks = potionEffectSection.getInt("ticks", ticks);
int amplifier = potionEffectSection.getInt("amplifier", 0);
boolean ambient = potionEffectSection.getBoolean("ambient", true);
boolean particles = potionEffectSection.getBoolean("particles", true);
potionEffects.add(new PotionEffect(effectType, ticks, amplifier, ambient, particles));
} catch (Exception ex) {
log.log(Level.WARNING, "Invalid potion effect type: " + potionEffectSection.getString("type", "(null)"), ex);
}
}
}
return potionEffects;
}
use of org.bukkit.potion.PotionEffectType in project MagicPlugin by elBukkit.
the class BaseSpell method getPotionEffects.
public static Collection<PotionEffect> getPotionEffects(ConfigurationSection parameters, Integer duration, boolean ambient, boolean particles) {
List<PotionEffect> effects = new ArrayList<>();
PotionEffectType[] effectTypes = PotionEffectType.values();
for (PotionEffectType effectType : effectTypes) {
// Why is there a null entry in this list? Maybe a 1.7 bug?
if (effectType == null)
continue;
String parameterName = "effect_" + effectType.getName().toLowerCase();
if (parameters.contains(parameterName)) {
String value = parameters.getString(parameterName);
int ticks = 10;
int power = 1;
try {
if (value.contains(",")) {
String[] pieces = StringUtils.split(value, ',');
ticks = (int) Float.parseFloat(pieces[0]);
power = (int) Float.parseFloat(pieces[1]);
} else {
power = (int) Float.parseFloat(value);
if (duration != null) {
ticks = duration / 50;
}
}
} catch (Exception ex) {
Bukkit.getLogger().warning("Error parsing potion effect for " + effectType + ": " + value);
}
PotionEffect effect = new PotionEffect(effectType, ticks, power, ambient, particles);
effects.add(effect);
}
}
return effects;
}
Aggregations