Add potion effects to bosses when they spawn.

With this feature you can add potions to the bosses when they spawn,
adding the ability to add strength to the boss for the first 30 seconds
making it harder for the first few seconds and once the effect wears
goes away the boss becomes easier. The syntax is in the same style as
potion items, except it uses either the potion effect enum name or the
potion effect id.

POTION_EFFECT:duration in seconds:amplifer

SLOW:360:4;INVISIBILITY:36000:0

If no duration is given, the plugin will default to sixty seconds. If
the amplifer was not provided, the plugin will default to zero. The
potion effect amplifcation starts at 0 being level 1.
This commit is contained in:
graywolf336
2014-11-27 03:37:14 -06:00
parent 7648338047
commit 1090550a3b
4 changed files with 146 additions and 0 deletions
@@ -183,6 +183,7 @@ public class MASpawnThread implements Runnable
boss.setDrops(bw.getDrops());
bw.addMABoss(boss);
bw.activateAbilities(arena);
e.addPotionEffects(bw.getPotions());
if (bw.getBossName() != null) {
e.setCustomName(bw.getBossName());
e.setCustomNameVisible(true);
@@ -0,0 +1,123 @@
package com.garbagemule.MobArena.util;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.garbagemule.MobArena.Messenger;
public class PotionEffectParser
{
private static final int TICKS_PER_SECOND = 20;
private static final int DEFAULT_POTION_DURATION = 1200;
private static final int DEFAULT_POTION_AMPLIFIER = 0;
public static List<PotionEffect> parsePotionEffects(String s) {
if (s == null || s.isEmpty())
return null;
List<PotionEffect> potions = new ArrayList<PotionEffect>();
for (String potion : s.split(",")) {
PotionEffect eff = parsePotionEffect(potion);
if (eff != null) {
potions.add(eff);
}
}
return potions;
}
public static PotionEffect parsePotionEffect(String p) {
if (p == null || p.isEmpty())
return null;
String[] parts = p.split(":");
PotionEffect result = null;
switch (parts.length) {
case 1:
result = parseSingle(parts[0]);
break;
case 2:
result = withDuration(parts[0], parts[1]);
break;
case 3:
result = withDurationAndAmplifier(parts[0], parts[1], parts[2]);
break;
}
if (result == null) {
Messenger.warning("Failed to parse potion effect: " + p);
return null;
}
return result;
}
private static PotionEffect parseSingle(String type) {
PotionEffectType effect = getType(type);
if (effect == null) {
return null;
} else {
return new PotionEffect(effect, DEFAULT_POTION_DURATION, DEFAULT_POTION_AMPLIFIER);
}
}
private static PotionEffect withDuration(String type, String duration) {
PotionEffectType effect = getType(type);
int dur = getDuration(duration);
if (effect == null || dur == -1) {
return null;
} else {
return new PotionEffect(effect, dur * TICKS_PER_SECOND, DEFAULT_POTION_AMPLIFIER);
}
}
private static PotionEffect withDurationAndAmplifier(String type, String duration, String amplifier) {
PotionEffectType effect = getType(type);
int dur = getDuration(duration);
int amp = getAmplification(amplifier);
if (effect == null || dur == -1 || amp == -1) {
return null;
} else {
return new PotionEffect(effect, dur * TICKS_PER_SECOND, amp);
}
}
private static PotionEffectType getType(String type) {
PotionEffectType effect = null;
if (type.matches("[0-9]*")) {
effect = PotionEffectType.getById(Integer.parseInt(type));
} else {
effect = PotionEffectType.getByName(type);
}
return effect;
}
private static int getDuration(String duration) {
int dur = -1;
if (duration.matches("[0-9]*")) {
dur = Integer.parseInt(duration);
}
return dur;
}
private static int getAmplification(String amplifier) {
int amp = -1;
if (amplifier.matches("[0-9]*")) {
amp = Integer.parseInt(amplifier);
}
return amp;
}
}
@@ -3,14 +3,17 @@ package com.garbagemule.MobArena.waves;
import java.util.*;
import com.garbagemule.MobArena.ArenaClass;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import com.garbagemule.MobArena.Messenger;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.region.ArenaRegion;
import com.garbagemule.MobArena.util.ItemParser;
import com.garbagemule.MobArena.util.PotionEffectParser;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityManager;
import com.garbagemule.MobArena.waves.enums.*;
@@ -297,6 +300,13 @@ public class WaveParser
List<ItemStack> drops = ItemParser.parseItems(drp);
result.setDrops(drops);
// Potions!
String pots = config.getString("potions");
if (pots != null) {
List<PotionEffect> potions = PotionEffectParser.parsePotionEffects(pots);
if (potions != null) result.setPotions(potions);
}
return result;
}
@@ -8,6 +8,7 @@ import java.util.Map;
import java.util.Set;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import com.garbagemule.MobArena.Messenger;
import com.garbagemule.MobArena.Msg;
@@ -34,11 +35,13 @@ public class BossWave extends AbstractWave
private ItemStack reward;
private List<ItemStack> drops;
private List<PotionEffect> potions;
public BossWave(MACreature monster) {
this.monster = monster;
this.bosses = new HashSet<MABoss>();
this.abilities = new ArrayList<Ability>();
this.potions = new ArrayList<PotionEffect>();
this.activated = false;
this.abilityAnnounce = false;
this.setType(WaveType.BOSS);
@@ -130,6 +133,14 @@ public class BossWave extends AbstractWave
this.drops = drops;
}
public List<PotionEffect> getPotions() {
return potions;
}
public void setPotions(List<PotionEffect> potions) {
this.potions = potions;
}
public void activateAbilities(Arena arena) {
if (activated) {
return;
@@ -159,6 +170,7 @@ public class BossWave extends AbstractWave
result.flatHealth = this.flatHealth;
result.reward = this.reward;
result.drops = this.drops;
result.potions = this.potions;
result.bossName = this.bossName;
// From AbstractWave