diff --git a/src/main/java/com/gmail/nossr50/config/AutoUpdateConfigLoader.java b/src/main/java/com/gmail/nossr50/config/AutoUpdateConfigLoader.java index 424bf3faf..bf95cb291 100644 --- a/src/main/java/com/gmail/nossr50/config/AutoUpdateConfigLoader.java +++ b/src/main/java/com/gmail/nossr50/config/AutoUpdateConfigLoader.java @@ -64,6 +64,9 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader { while (output.replaceAll("[//s]", "").startsWith("#")) { output = output.substring(output.indexOf('\n', output.indexOf('#')) + 1); } + + String[] keys = output.split("\n"); + // Read the internal config to get comments, then put them in the new one try { @@ -86,11 +89,15 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader { } } + output = ""; // Dump to the new one - for (String key : comments.keySet()) { - if (output.contains(key)) { - output = output.substring(0, output.indexOf(key)) + comments.get(key) + output.substring(output.indexOf(key)); + for (String key : keys) { + String comment = comments.get(key.substring(0, key.indexOf(":") + 1)); + if (comment != null) { + output += comment; } + output += key; + output += "\n"; } } catch (Exception e) { diff --git a/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java b/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java index cfdbe188d..da27b02c3 100644 --- a/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java +++ b/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java @@ -9,8 +9,11 @@ import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.Potion; +import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.potion.PotionType; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.ConfigLoader; @@ -122,7 +125,15 @@ public class PotionConfig extends ConfigLoader { 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; 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) { mcMMO.p.getLogger().warning("Failed to load Alchemy potion: " + potion_section.getName()); diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/AlchemyPotion.java b/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/AlchemyPotion.java index 2ecb2c17b..bebf3c554 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/AlchemyPotion.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/AlchemyPotion.java @@ -8,21 +8,22 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.Potion; +import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import com.gmail.nossr50.config.skills.alchemy.PotionConfig; public class AlchemyPotion { private Material material; - private short dataValue; + private PotionData data; private String name; private List lore; private List effects; private Map children; - public AlchemyPotion(Material material, short dataValue, String name, List lore, List effects, Map children) { + public AlchemyPotion(Material material, PotionData data, String name, List lore, List effects, Map children) { this.material = material; - this.dataValue = dataValue; + this.data = data; this.lore = lore; this.name = name; this.effects = effects; @@ -30,13 +31,14 @@ public class AlchemyPotion { } 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) { - ItemStack potion = new ItemStack(material, amount, this.getDataValue()); + ItemStack potion = new ItemStack(material, amount); PotionMeta meta = (PotionMeta) potion.getItemMeta(); + meta.setBasePotionData(data); if (this.getName() != null) { meta.setDisplayName(this.getName()); } @@ -63,12 +65,12 @@ public class AlchemyPotion { return Potion.fromItemStack(this.toItemStack(amount)); } - public short getDataValue() { - return dataValue; + public PotionData getData() { + return data; } - public void setDataValue(short data_value) { - this.dataValue = data_value; + public void setData(PotionData data) { + this.data = data; } public String getName() { @@ -118,13 +120,20 @@ public class AlchemyPotion { if (item.getType() != material) { return false; } - if (item.getDurability() != dataValue) { - return false; - } if (!item.hasItemMeta()) { return false; } 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) { if (!meta.hasCustomEffect(effect.getType())) { return false; diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/PotionStage.java b/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/PotionStage.java index 7ceb2c04a..93146bce4 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/PotionStage.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/PotionStage.java @@ -4,6 +4,7 @@ import java.util.List; import org.bukkit.potion.Potion; import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionType; public enum PotionStage { FIVE(5), @@ -42,7 +43,7 @@ public enum PotionStage { } private static boolean isWaterBottle(AlchemyPotion input) { - return input.getDataValue() == 0; + return input.getData().getType() == PotionType.WATER; } public static PotionStage getPotionStage(AlchemyPotion alchemyPotion) { diff --git a/src/main/resources/potions.yml b/src/main/resources/potions.yml index ad77b51c8..6bd7ed5b1 100644 --- a/src/main/resources/potions.yml +++ b/src/main/resources/potions.yml @@ -58,7 +58,8 @@ Potions: WATER: Material: POTION - Data: 0 + PotionData: + PotionType: WATER Children: BLAZE_POWDER: MUNDANE_POTION FERMENTED_SPIDER_EYE: 8200 @@ -73,7 +74,8 @@ Potions: AWKWARD: Material: POTION - Data: 16 + PotionData: + PotionType: AWKWARD Children: APPLE: 5376 # Potion of Health Boost BLAZE_POWDER: 8201 # Potion of Strength @@ -93,46 +95,50 @@ Potions: SLIME_BALL: 1024 # Potion of Dullness SPECKLED_MELON: 8197 # Potion of Healing SPIDER_EYE: 8196 # Potion of Poison - SUGAR: 8194 # Potion of Swiftness + SUGAR: SWIFTNESS # Potion of Swiftness WATER_LILY: 8205 # Potion of Water Breathing (Minecraft 1.6) 'RAW_FISH:3': 8205 # Potion of Water Breathing (Minecraft 1.7) THICK: Material: POTION - Data: 32 + PotionData: + PotionType: THICK Children: FERMENTED_SPIDER_EYE: 8200 - MUNDANE_POTION_EXTENDED: - Material: POTION - Data: 64 - Children: - FERMENTED_SPIDER_EYE: 8264 - MUNDANE_POTION: Material: POTION - Data: 8912 + PotionData: + PotionType: MUNDANE Children: FERMENTED_SPIDER_EYE: 8200 SULPHUR: 16384 ### DRINKABLE POTIONS ###################################################### - 8194: # Potion of Swiftness + SWIFTNESS: + PotionData: + PotionType: SPEED Children: FERMENTED_SPIDER_EYE: 8202 - GLOWSTONE_DUST: 8226 - REDSTONE: 8258 + GLOWSTONE_DUST: SWIFTNESS_2 + REDSTONE: SWIFTNESS_EXT SULPHUR: 16386 - 8226: # Potion of Swiftness II + SWIFTNESS_2: + PotionData: + PotionType: SPEED + Upgraded: true Children: FERMENTED_SPIDER_EYE: 8266 - REDSTONE: 8258 + REDSTONE: SWIFTNESS_EXT SULPHUR: 16418 - 8258: # Potion of Swiftness Extended + SWIFTNESS_EXT: # Potion of Swiftness Extended + PotionData: + PotionType: SPEED + Extended: true Children: FERMENTED_SPIDER_EYE: 8202 - GLOWSTONE_DUST: 8226 + GLOWSTONE_DUST: SWIFTNESS_2 SULPHUR: 16450 8202: # Potion of Slowness