mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-02 17:09:58 +01:00
[Experimental] Attempt restoring potion effect ID compatibility to 1.9
This commit is contained in:
parent
8167002092
commit
8116ce39d7
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.PotionMetaUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -151,6 +152,8 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
|
||||
throw new Exception("Can't spawn entity ID " + metaData + " from spawn eggs.");
|
||||
}
|
||||
retval = ess.getSpawnEggProvider().createEggItem(type);
|
||||
} else if (mat == Material.POTION) {
|
||||
retval = PotionMetaUtil.createPotionItem(metaData);
|
||||
} else {
|
||||
retval.setDurability(metaData);
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
package com.earth2me.essentials.utils;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
public class PotionMetaUtil {
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ItemStack createPotionItem(int effectId) throws IllegalArgumentException {
|
||||
int damageValue = getBit(effectId, 0) +
|
||||
2 * getBit(effectId, 1) +
|
||||
4 * getBit(effectId, 2) +
|
||||
8 * getBit(effectId, 3);
|
||||
|
||||
PotionType type = PotionType.getByDamageValue(damageValue);
|
||||
if (getBit(effectId, 15) != 1 || type == null) {
|
||||
throw new IllegalArgumentException("Unable to process potion effect ID " + effectId);
|
||||
}
|
||||
|
||||
int level = getBit(effectId, 5) + 1;
|
||||
boolean extended = getBit(effectId, 6) == 1;
|
||||
boolean splash = getBit(effectId, 14) == 1;
|
||||
|
||||
Potion potion = new Potion(type, level);
|
||||
potion.setHasExtendedDuration(extended);
|
||||
potion.setSplash(splash);
|
||||
|
||||
return potion.toItemStack(1);
|
||||
}
|
||||
|
||||
private static int getBit(int n, int k) {
|
||||
return (n >> k) & 1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user