use of org.bukkit.potion.PotionEffectType in project Glowstone by GlowstoneMC.
the class GlowMetaPotion method fromNBT.
public static PotionEffect fromNBT(CompoundTag tag) {
PotionEffectType type = PotionEffectType.getById(tag.getByte("Id"));
int duration = tag.getInt("Duration");
int amplifier = tag.getByte("Amplifier");
boolean ambient = tag.isByte("Ambient") && tag.getBool("Ambient");
boolean particles = !tag.isByte("ShowParticles") || tag.getBool("ShowParticles");
return new PotionEffect(type, duration, amplifier, ambient, particles);
}
use of org.bukkit.potion.PotionEffectType in project Bukkit by Bukkit.
the class EffectCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender)) {
return true;
}
if (args.length < 2) {
sender.sendMessage(getUsage());
return true;
}
final Player player = sender.getServer().getPlayer(args[0]);
if (player == null) {
sender.sendMessage(ChatColor.RED + String.format("Player, %s, not found", args[0]));
return true;
}
if ("clear".equalsIgnoreCase(args[1])) {
for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
sender.sendMessage(String.format("Took all effects from %s", args[0]));
return true;
}
PotionEffectType effect = PotionEffectType.getByName(args[1]);
if (effect == null) {
effect = PotionEffectType.getById(getInteger(sender, args[1], 0));
}
if (effect == null) {
sender.sendMessage(ChatColor.RED + String.format("Effect, %s, not found", args[1]));
return true;
}
int duration = 600;
int duration_temp = 30;
int amplification = 0;
if (args.length >= 3) {
duration_temp = getInteger(sender, args[2], 0, 1000000);
if (effect.isInstant()) {
duration = duration_temp;
} else {
duration = duration_temp * 20;
}
} else if (effect.isInstant()) {
duration = 1;
}
if (args.length >= 4) {
amplification = getInteger(sender, args[3], 0, 255);
}
if (duration_temp == 0) {
if (!player.hasPotionEffect(effect)) {
sender.sendMessage(String.format("Couldn't take %s from %s as they do not have the effect", effect.getName(), args[0]));
return true;
}
player.removePotionEffect(effect);
broadcastCommandMessage(sender, String.format("Took %s from %s", effect.getName(), args[0]));
} else {
final PotionEffect applyEffect = new PotionEffect(effect, duration, amplification);
player.addPotionEffect(applyEffect, true);
broadcastCommandMessage(sender, String.format("Given %s (ID %d) * %d to %s for %d seconds", effect.getName(), effect.getId(), amplification, args[0], duration_temp));
}
return true;
}
use of org.bukkit.potion.PotionEffectType in project xAuth by CypherX.
the class PlayerDataHandler method buildPotFx.
private Collection<PotionEffect> buildPotFx(String str) {
String[] effectSplit = str.split(";");
String[] type = effectSplit[0].split(",");
String[] duration = effectSplit[1].split(",");
String[] amplifier = effectSplit[2].split(",");
Collection<PotionEffect> effects = new ArrayList<PotionEffect>();
for (int i = 0; i < type.length; i++) {
PotionEffectType potFxType = PotionEffectType.getById(Integer.parseInt(type[i]));
int potFxDur = Integer.parseInt(duration[i]);
int potFxAmp = Integer.parseInt(amplifier[i]);
effects.add(new PotionEffect(potFxType, potFxDur, potFxAmp));
}
return effects;
}
use of org.bukkit.potion.PotionEffectType in project Denizen-For-Bukkit by DenizenScript.
the class EntityPotionEffects method adjust.
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("potion_effects")) {
dList effects = dList.valueOf(mechanism.getValue().asString());
for (String effect : effects) {
List<String> split = CoreUtilities.split(effect, ',');
if (split.size() != 3) {
continue;
}
PotionEffectType effectType = PotionEffectType.getByName(split.get(0));
if (Integer.valueOf(split.get(1)) == null || Integer.valueOf(split.get(2)) == null || effectType == null) {
continue;
}
entity.getLivingEntity().addPotionEffect(new PotionEffect(effectType, Integer.valueOf(split.get(2)), Integer.valueOf(split.get(1))));
}
}
}
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);
}
}
Aggregations