Merge branch 'graywolf336-bleeding' into bleeding

This commit is contained in:
garbagemule 2014-12-08 17:03:54 +01:00
commit 03fad84ece
4 changed files with 146 additions and 0 deletions

View File

@ -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);

View File

@ -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_AMPLIFIER = 0;
private static final int DEFAULT_POTION_DURATION = Integer.MAX_VALUE;
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.trim());
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 = withAmplifier(parts[0], parts[1]);
break;
case 3:
result = withAmplifierAndDuration(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 withAmplifier(String type, String amplifier) {
PotionEffectType effect = getType(type);
int amp = getAmplification(amplifier);
if (effect == null || amp == -1) {
return null;
} else {
return new PotionEffect(effect, DEFAULT_POTION_DURATION, amp);
}
}
private static PotionEffect withAmplifierAndDuration(String type, String amplifier, String duration) {
PotionEffectType effect = getType(type);
int amp = getAmplification(amplifier);
int dur = getDuration(duration);
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.toUpperCase());
}
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;
}
}

View File

@ -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;
}

View File

@ -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