Fixed Potion Shops on 1.8.x

This commit is contained in:
Eric 2016-07-30 17:40:19 +02:00
parent eaa2f056eb
commit e522746eeb
2 changed files with 41 additions and 12 deletions

View File

@ -14,6 +14,7 @@ import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
import java.util.ArrayList; import java.util.ArrayList;
@ -946,16 +947,30 @@ public class LanguageUtils {
if (stack.getItemMeta() instanceof PotionMeta) { if (stack.getItemMeta() instanceof PotionMeta) {
PotionMeta meta = (PotionMeta) stack.getItemMeta(); PotionMeta meta = (PotionMeta) stack.getItemMeta();
PotionType potionType = meta.getBasePotionData().getType(); PotionType potionType;
if (Utils.getMajorVersion() < 9) {
potionType = Potion.fromItemStack(stack).getType();
} else {
potionType = meta.getBasePotionData().getType();
}
for (PotionName potionName : potionNames) { for (PotionName potionName : potionNames) {
if (material == Material.POTION) { if (material == Material.POTION) {
if (potionName.getPotionItemType() == PotionName.PotionItemType.POTION && potionName.getPotionType() == potionType) { if (Utils.getMajorVersion() < 9) {
return potionName.getLocalizedName(); if (Potion.fromItemStack(stack).isSplash()) {
} if (potionName.getPotionItemType() == PotionName.PotionItemType.SPLASH_POTION && potionName.getPotionType() == potionType) {
} else if (material == Material.SPLASH_POTION) { return potionName.getLocalizedName();
if (potionName.getPotionItemType() == PotionName.PotionItemType.SPLASH_POTION && potionName.getPotionType() == potionType) { }
return potionName.getLocalizedName(); } else {
if (potionName.getPotionItemType() == PotionName.PotionItemType.POTION && potionName.getPotionType() == potionType) {
return potionName.getLocalizedName();
}
}
} else {
if (potionName.getPotionItemType() == PotionName.PotionItemType.POTION && potionName.getPotionType() == potionType) {
return potionName.getLocalizedName();
}
} }
} else { } else {
if (Utils.getMajorVersion() >= 9) { if (Utils.getMajorVersion() >= 9) {
@ -967,6 +982,10 @@ public class LanguageUtils {
if (potionName.getPotionItemType() == PotionName.PotionItemType.TIPPED_ARROW && potionName.getPotionType() == potionType) { if (potionName.getPotionItemType() == PotionName.PotionItemType.TIPPED_ARROW && potionName.getPotionType() == potionType) {
return potionName.getLocalizedName(); return potionName.getLocalizedName();
} }
} else if (material == Material.SPLASH_POTION) {
if (potionName.getPotionItemType() == PotionName.PotionItemType.SPLASH_POTION && potionName.getPotionType() == potionType) {
return potionName.getLocalizedName();
}
} }
} }
} }
@ -1052,12 +1071,22 @@ public class LanguageUtils {
*/ */
public static String getPotionEffectName(ItemStack itemStack) { public static String getPotionEffectName(ItemStack itemStack) {
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta(); PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
PotionType potionType;
boolean upgraded;
String potionEffectString = formatDefaultString(potionMeta.getBasePotionData().getType().toString()); if (Utils.getMajorVersion() < 9) {
String upgradeString = potionMeta.getBasePotionData().isUpgraded() ? "II" : ""; potionType = Potion.fromItemStack(itemStack).getType();
upgraded = (Potion.fromItemStack(itemStack).getTier() == Potion.Tier.TWO);
} else {
potionType = potionMeta.getBasePotionData().getType();
upgraded = potionMeta.getBasePotionData().isUpgraded();
}
String potionEffectString = formatDefaultString(potionType.toString());
String upgradeString = upgraded ? "II" : "";
for (PotionEffectName potionEffectName : potionEffectNames) { for (PotionEffectName potionEffectName : potionEffectNames) {
if (potionEffectName.getEffect() == potionMeta.getBasePotionData().getType()) { if (potionEffectName.getEffect() == potionType) {
potionEffectString = potionEffectName.getLocalizedName(); potionEffectString = potionEffectName.getLocalizedName();
} }
} }

View File

@ -319,14 +319,14 @@ public class ShopInteractListener implements Listener {
Map<Enchantment, Integer> enchantmentMap; Map<Enchantment, Integer> enchantmentMap;
if (Utils.getMajorVersion() >= 9) { if (Utils.getMajorVersion() >= 9) {
if (type == Material.TIPPED_ARROW || type == Material.LINGERING_POTION) { if (type == Material.TIPPED_ARROW || type == Material.LINGERING_POTION || type == Material.SPLASH_POTION) {
potionEffectString = LanguageUtils.getPotionEffectName(shop.getProduct()); potionEffectString = LanguageUtils.getPotionEffectName(shop.getProduct());
if (potionEffectString == null) if (potionEffectString == null)
potionEffectString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_NONE); potionEffectString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_NONE);
} }
} }
if (type == Material.POTION || type == Material.SPLASH_POTION) { if (type == Material.POTION) {
potionEffectString = LanguageUtils.getPotionEffectName(shop.getProduct()); potionEffectString = LanguageUtils.getPotionEffectName(shop.getProduct());
if (potionEffectString == null) if (potionEffectString == null)
potionEffectString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_NONE); potionEffectString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_NONE);