mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36:46 +01:00
Update to new Potions API, still supports old config options
This commit is contained in:
parent
9bc97c6dd3
commit
a08016647a
@ -9,8 +9,11 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.potion.Potion;
|
||||||
|
import org.bukkit.potion.PotionData;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.potion.PotionType;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.ConfigLoader;
|
import com.gmail.nossr50.config.ConfigLoader;
|
||||||
@ -122,7 +125,15 @@ public class PotionConfig extends ConfigLoader {
|
|||||||
name = ChatColor.translateAlternateColorCodes('&', name);
|
name = ChatColor.translateAlternateColorCodes('&', name);
|
||||||
}
|
}
|
||||||
|
|
||||||
short dataValue = Short.parseShort(potion_section.getString("Data", potion_section.getName())); // Default to the section name for backwards compatability
|
PotionData data;
|
||||||
|
if (!potion_section.contains("PotionData")) { // Backwards config compatability
|
||||||
|
short dataValue = Short.parseShort(potion_section.getName());
|
||||||
|
Potion potion = Potion.fromDamage(dataValue);
|
||||||
|
data = new PotionData(potion.getType(), potion.hasExtendedDuration(), potion.getLevel() == 2);
|
||||||
|
} else {
|
||||||
|
ConfigurationSection potionData = potion_section.getConfigurationSection("PotionData");
|
||||||
|
data = new PotionData(PotionType.valueOf(potionData.getString("PotionType", "WATER")), potionData.getBoolean("Extended", false), potionData.getBoolean("Upgraded", false));
|
||||||
|
}
|
||||||
|
|
||||||
Material material = Material.POTION;
|
Material material = Material.POTION;
|
||||||
String mat = potion_section.getString("Material", null);
|
String mat = potion_section.getString("Material", null);
|
||||||
@ -168,7 +179,7 @@ public class PotionConfig extends ConfigLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AlchemyPotion(material, dataValue, name, lore, effects, children);
|
return new AlchemyPotion(material, data, name, lore, effects, children);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
mcMMO.p.getLogger().warning("Failed to load Alchemy potion: " + potion_section.getName());
|
mcMMO.p.getLogger().warning("Failed to load Alchemy potion: " + potion_section.getName());
|
||||||
|
@ -8,21 +8,22 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
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.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
import com.gmail.nossr50.config.skills.alchemy.PotionConfig;
|
import com.gmail.nossr50.config.skills.alchemy.PotionConfig;
|
||||||
|
|
||||||
public class AlchemyPotion {
|
public class AlchemyPotion {
|
||||||
private Material material;
|
private Material material;
|
||||||
private short dataValue;
|
private PotionData data;
|
||||||
private String name;
|
private String name;
|
||||||
private List<String> lore;
|
private List<String> lore;
|
||||||
private List<PotionEffect> effects;
|
private List<PotionEffect> effects;
|
||||||
private Map<ItemStack, String> children;
|
private Map<ItemStack, String> children;
|
||||||
|
|
||||||
public AlchemyPotion(Material material, short dataValue, String name, List<String> lore, List<PotionEffect> effects, Map<ItemStack, String> children) {
|
public AlchemyPotion(Material material, PotionData data, String name, List<String> lore, List<PotionEffect> effects, Map<ItemStack, String> children) {
|
||||||
this.material = material;
|
this.material = material;
|
||||||
this.dataValue = dataValue;
|
this.data = data;
|
||||||
this.lore = lore;
|
this.lore = lore;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.effects = effects;
|
this.effects = effects;
|
||||||
@ -30,13 +31,14 @@ public class AlchemyPotion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "AlchemyPotion{" + dataValue + ", " + name + ", Effects[" + effects.size() + "], Children[" + children.size() + "]}";
|
return "AlchemyPotion{" + data + ", " + name + ", Effects[" + effects.size() + "], Children[" + children.size() + "]}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack toItemStack(int amount) {
|
public ItemStack toItemStack(int amount) {
|
||||||
ItemStack potion = new ItemStack(material, amount, this.getDataValue());
|
ItemStack potion = new ItemStack(material, amount);
|
||||||
PotionMeta meta = (PotionMeta) potion.getItemMeta();
|
PotionMeta meta = (PotionMeta) potion.getItemMeta();
|
||||||
|
|
||||||
|
meta.setBasePotionData(data);
|
||||||
if (this.getName() != null) {
|
if (this.getName() != null) {
|
||||||
meta.setDisplayName(this.getName());
|
meta.setDisplayName(this.getName());
|
||||||
}
|
}
|
||||||
@ -63,12 +65,12 @@ public class AlchemyPotion {
|
|||||||
return Potion.fromItemStack(this.toItemStack(amount));
|
return Potion.fromItemStack(this.toItemStack(amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getDataValue() {
|
public PotionData getData() {
|
||||||
return dataValue;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDataValue(short data_value) {
|
public void setData(PotionData data) {
|
||||||
this.dataValue = data_value;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -118,13 +120,20 @@ public class AlchemyPotion {
|
|||||||
if (item.getType() != material) {
|
if (item.getType() != material) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (item.getDurability() != dataValue) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!item.hasItemMeta()) {
|
if (!item.hasItemMeta()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PotionMeta meta = (PotionMeta) item.getItemMeta();
|
PotionMeta meta = (PotionMeta) item.getItemMeta();
|
||||||
|
PotionData that = meta.getBasePotionData();
|
||||||
|
if (data.getType() != that.getType()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (data.isExtended() != that.isExtended()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (data.isUpgraded() != that.isUpgraded()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (PotionEffect effect : effects) {
|
for (PotionEffect effect : effects) {
|
||||||
if (!meta.hasCustomEffect(effect.getType())) {
|
if (!meta.hasCustomEffect(effect.getType())) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.potion.Potion;
|
import org.bukkit.potion.Potion;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionType;
|
||||||
|
|
||||||
public enum PotionStage {
|
public enum PotionStage {
|
||||||
FIVE(5),
|
FIVE(5),
|
||||||
@ -42,7 +43,7 @@ public enum PotionStage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isWaterBottle(AlchemyPotion input) {
|
private static boolean isWaterBottle(AlchemyPotion input) {
|
||||||
return input.getDataValue() == 0;
|
return input.getData().getType() == PotionType.WATER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PotionStage getPotionStage(AlchemyPotion alchemyPotion) {
|
public static PotionStage getPotionStage(AlchemyPotion alchemyPotion) {
|
||||||
|
Loading…
Reference in New Issue
Block a user