Merge pull request #2 from mcMMO-Dev/master

Merge master
This commit is contained in:
Dor 2016-03-12 05:05:37 +02:00
commit 47f73ba455
5 changed files with 70 additions and 36 deletions

View File

@ -64,6 +64,9 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader {
while (output.replaceAll("[//s]", "").startsWith("#")) { while (output.replaceAll("[//s]", "").startsWith("#")) {
output = output.substring(output.indexOf('\n', output.indexOf('#')) + 1); 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 // Read the internal config to get comments, then put them in the new one
try { try {
@ -86,11 +89,15 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader {
} }
} }
output = "";
// Dump to the new one // Dump to the new one
for (String key : comments.keySet()) { for (String key : keys) {
if (output.contains(key)) { String comment = comments.get(key.substring(0, key.indexOf(":") + 1));
output = output.substring(0, output.indexOf(key)) + comments.get(key) + output.substring(output.indexOf(key)); if (comment != null) {
output += comment;
} }
output += key;
output += "\n";
} }
} }
catch (Exception e) { catch (Exception e) {

View File

@ -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());

View File

@ -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;

View File

@ -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) {

View File

@ -58,7 +58,8 @@ Potions:
WATER: WATER:
Material: POTION Material: POTION
Data: 0 PotionData:
PotionType: WATER
Children: Children:
BLAZE_POWDER: MUNDANE_POTION BLAZE_POWDER: MUNDANE_POTION
FERMENTED_SPIDER_EYE: 8200 FERMENTED_SPIDER_EYE: 8200
@ -73,7 +74,8 @@ Potions:
AWKWARD: AWKWARD:
Material: POTION Material: POTION
Data: 16 PotionData:
PotionType: AWKWARD
Children: Children:
APPLE: 5376 # Potion of Health Boost APPLE: 5376 # Potion of Health Boost
BLAZE_POWDER: 8201 # Potion of Strength BLAZE_POWDER: 8201 # Potion of Strength
@ -93,46 +95,50 @@ Potions:
SLIME_BALL: 1024 # Potion of Dullness SLIME_BALL: 1024 # Potion of Dullness
SPECKLED_MELON: 8197 # Potion of Healing SPECKLED_MELON: 8197 # Potion of Healing
SPIDER_EYE: 8196 # Potion of Poison 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) WATER_LILY: 8205 # Potion of Water Breathing (Minecraft 1.6)
'RAW_FISH:3': 8205 # Potion of Water Breathing (Minecraft 1.7) 'RAW_FISH:3': 8205 # Potion of Water Breathing (Minecraft 1.7)
THICK: THICK:
Material: POTION Material: POTION
Data: 32 PotionData:
PotionType: THICK
Children: Children:
FERMENTED_SPIDER_EYE: 8200 FERMENTED_SPIDER_EYE: 8200
MUNDANE_POTION_EXTENDED:
Material: POTION
Data: 64
Children:
FERMENTED_SPIDER_EYE: 8264
MUNDANE_POTION: MUNDANE_POTION:
Material: POTION Material: POTION
Data: 8912 PotionData:
PotionType: MUNDANE
Children: Children:
FERMENTED_SPIDER_EYE: 8200 FERMENTED_SPIDER_EYE: 8200
SULPHUR: 16384 SULPHUR: 16384
### DRINKABLE POTIONS ###################################################### ### DRINKABLE POTIONS ######################################################
8194: # Potion of Swiftness SWIFTNESS:
PotionData:
PotionType: SPEED
Children: Children:
FERMENTED_SPIDER_EYE: 8202 FERMENTED_SPIDER_EYE: 8202
GLOWSTONE_DUST: 8226 GLOWSTONE_DUST: SWIFTNESS_2
REDSTONE: 8258 REDSTONE: SWIFTNESS_EXT
SULPHUR: 16386 SULPHUR: 16386
8226: # Potion of Swiftness II SWIFTNESS_2:
PotionData:
PotionType: SPEED
Upgraded: true
Children: Children:
FERMENTED_SPIDER_EYE: 8266 FERMENTED_SPIDER_EYE: 8266
REDSTONE: 8258 REDSTONE: SWIFTNESS_EXT
SULPHUR: 16418 SULPHUR: 16418
8258: # Potion of Swiftness Extended SWIFTNESS_EXT: # Potion of Swiftness Extended
PotionData:
PotionType: SPEED
Extended: true
Children: Children:
FERMENTED_SPIDER_EYE: 8202 FERMENTED_SPIDER_EYE: 8202
GLOWSTONE_DUST: 8226 GLOWSTONE_DUST: SWIFTNESS_2
SULPHUR: 16450 SULPHUR: 16450
8202: # Potion of Slowness 8202: # Potion of Slowness