mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 20:00:46 +00:00
[Likely breaks 1.8 compatibility, will be fixed] Use non-deprecated methods
This commit is contained in:
parent
8116ce39d7
commit
c266778c1e
1 changed files with 37 additions and 9 deletions
|
@ -1,31 +1,59 @@
|
||||||
package com.earth2me.essentials.utils;
|
package com.earth2me.essentials.utils;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
import org.bukkit.potion.Potion;
|
import org.bukkit.potion.Potion;
|
||||||
|
import org.bukkit.potion.PotionData;
|
||||||
import org.bukkit.potion.PotionType;
|
import org.bukkit.potion.PotionType;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class PotionMetaUtil {
|
public class PotionMetaUtil {
|
||||||
@SuppressWarnings("deprecation")
|
private static Map<Integer, PotionType> damageValueToType = ImmutableMap.<Integer, PotionType>builder()
|
||||||
|
.put(1, PotionType.REGEN)
|
||||||
|
.put(2, PotionType.SPEED)
|
||||||
|
.put(3, PotionType.FIRE_RESISTANCE)
|
||||||
|
.put(4, PotionType.POISON)
|
||||||
|
.put(5, PotionType.INSTANT_HEAL)
|
||||||
|
.put(6, PotionType.NIGHT_VISION)
|
||||||
|
// Skip 7
|
||||||
|
.put(8, PotionType.WEAKNESS)
|
||||||
|
.put(9, PotionType.STRENGTH)
|
||||||
|
.put(10, PotionType.SLOWNESS)
|
||||||
|
.put(11, PotionType.JUMP)
|
||||||
|
.put(12, PotionType.INSTANT_DAMAGE)
|
||||||
|
.put(13, PotionType.WATER_BREATHING)
|
||||||
|
.put(14, PotionType.INVISIBILITY)
|
||||||
|
.build();
|
||||||
|
|
||||||
public static ItemStack createPotionItem(int effectId) throws IllegalArgumentException {
|
public static ItemStack createPotionItem(int effectId) throws IllegalArgumentException {
|
||||||
int damageValue = getBit(effectId, 0) +
|
int damageValue = getBit(effectId, 0) +
|
||||||
2 * getBit(effectId, 1) +
|
2 * getBit(effectId, 1) +
|
||||||
4 * getBit(effectId, 2) +
|
4 * getBit(effectId, 2) +
|
||||||
8 * getBit(effectId, 3);
|
8 * getBit(effectId, 3);
|
||||||
|
|
||||||
PotionType type = PotionType.getByDamageValue(damageValue);
|
PotionType type = damageValueToType.get(damageValue);
|
||||||
if (getBit(effectId, 15) != 1 || type == null) {
|
if (type == null) {
|
||||||
throw new IllegalArgumentException("Unable to process potion effect ID " + effectId);
|
throw new IllegalArgumentException("Unable to process potion effect ID " + effectId + " with damage value " + damageValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
int level = getBit(effectId, 5) + 1;
|
|
||||||
boolean extended = getBit(effectId, 6) == 1;
|
boolean extended = getBit(effectId, 6) == 1;
|
||||||
|
boolean upgraded = getBit(effectId, 5) == 1;
|
||||||
boolean splash = getBit(effectId, 14) == 1;
|
boolean splash = getBit(effectId, 14) == 1;
|
||||||
|
|
||||||
Potion potion = new Potion(type, level);
|
ItemStack potion;
|
||||||
potion.setHasExtendedDuration(extended);
|
if (splash) {
|
||||||
potion.setSplash(splash);
|
potion = new ItemStack(Material.SPLASH_POTION, 1);
|
||||||
|
} else {
|
||||||
|
potion = new ItemStack(Material.POTION, 1);
|
||||||
|
}
|
||||||
|
|
||||||
return potion.toItemStack(1);
|
PotionMeta meta = (PotionMeta) potion.getItemMeta();
|
||||||
|
PotionData potionType = new PotionData(type, extended, upgraded);
|
||||||
|
|
||||||
|
return potion;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getBit(int n, int k) {
|
private static int getBit(int n, int k) {
|
||||||
|
|
Loading…
Reference in a new issue