Created
March 20, 2016 05:40
-
-
Save Techcable/6bce0d61e7ec315ef4b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package net.techcable.utils; | |
| import java.util.EnumMap; | |
| import java.util.OptionalInt; | |
| import com.google.common.collect.ImmutableMap; | |
| import org.bukkit.potion.PotionType; | |
| public class PotionUtils { | |
| private static ImmutableMap<PotionType, int[]> POTION_DURATIONS; | |
| private static ImmutableMap<PotionType, Integer> EXTENDED_POTION_DURATIONS; | |
| public static OptionalInt getExtendedDuration(PotionType type) { | |
| Integer obj = EXTENDED_POTION_DURATIONS.get(type); | |
| return obj == null ? OptionalInt.empty() : OptionalInt.of(obj); | |
| } | |
| public static OptionalInt getDuration(PotionType type, int level) { | |
| int[] durations = POTION_DURATIONS.get(type); | |
| if (level < 0) { | |
| throw new IllegalArgumentException("Negative level: " + level); | |
| } else if (level >= durations.length) { | |
| return OptionalInt.empty(); | |
| } | |
| return OptionalInt.of(durations[level]); | |
| } | |
| static { | |
| EnumMap<PotionType, int[]> durations = new EnumMap<PotionType, int[]>(PotionType.class); | |
| EnumMap<PotionType, Integer> extendedDurations = new EnumMap<PotionType, Integer>(PotionType.class); | |
| durations.put(PotionType.WATER, new int[0]); | |
| //durations.put(PotionType.MUNDANE, new int[0]); | |
| //durations.put(PotionType.THICK, new int[0]); | |
| //durations.put(PotionType.AWKWARD, new int[0]); | |
| //durations.put(PotionType.NIGHT_VISION, new int[]{3600}); | |
| extendedDurations.put(PotionType.NIGHT_VISION, 9600); | |
| durations.put(PotionType.INVISIBILITY, new int[]{3600}); | |
| extendedDurations.put(PotionType.INVISIBILITY, 9600); | |
| durations.put(PotionType.JUMP, new int[]{3600, 1800}); | |
| extendedDurations.put(PotionType.JUMP, 9600); | |
| durations.put(PotionType.FIRE_RESISTANCE, new int[]{3600}); | |
| extendedDurations.put(PotionType.FIRE_RESISTANCE, 9600); | |
| durations.put(PotionType.SPEED, new int[]{3600, 1800}); | |
| extendedDurations.put(PotionType.SPEED, 9600); | |
| durations.put(PotionType.SLOWNESS, new int[]{1800}); | |
| extendedDurations.put(PotionType.SLOWNESS, 4800); | |
| durations.put(PotionType.WATER_BREATHING, new int[]{3600}); | |
| extendedDurations.put(PotionType.WATER_BREATHING, 9600); | |
| durations.put(PotionType.INSTANT_HEAL, new int[]{1,1}); | |
| durations.put(PotionType.INSTANT_DAMAGE, new int[]{1,1}); | |
| durations.put(PotionType.POISON, new int[]{900, 432}); | |
| extendedDurations.put(PotionType.POISON, 1800); | |
| durations.put(PotionType.REGEN, new int[]{900,450}); | |
| extendedDurations.put(PotionType.REGEN, 1800); | |
| durations.put(PotionType.STRENGTH, new int[]{3600,1800}); | |
| extendedDurations.put(PotionType.STRENGTH, 9600); | |
| durations.put(PotionType.WEAKNESS, new int[]{1800}); | |
| extendedDurations.put(PotionType.WEAKNESS, 4800); | |
| durations.put(PotionType.LUCK, new int[] {6000}); | |
| for (PotionType type : PotionType.values()) { | |
| if (!durations.containsKey(type)) { | |
| throw new AssertionError("No duration for type " + type); | |
| } else if (durations.get(type).length <= type.getMaxLevel()) { | |
| throw new AssertionError("No duration up to max level " + type.getMaxLevel() + " only goes up to " + durations.get(type).length); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment