mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-25 03:55:35 +01:00
Expose potion level for 1.9+, part 3. See #2205
This commit is contained in:
parent
90f8f0ec27
commit
181f4e0dec
@ -74,7 +74,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
|
||||||
import org.bukkit.material.Crops;
|
import org.bukkit.material.Crops;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -1316,6 +1315,12 @@ public class BukkitQuester implements Quester {
|
|||||||
if (formatNames) {
|
if (formatNames) {
|
||||||
message = message.replace("<item>", BukkitItemUtil.getName(goal));
|
message = message.replace("<item>", BukkitItemUtil.getName(goal));
|
||||||
}
|
}
|
||||||
|
final String level = BukkitItemUtil.getPrettyPotionLevel(goal.getItemMeta());
|
||||||
|
if (level.isEmpty()) {
|
||||||
|
message = message.replace(" <level>", level);
|
||||||
|
} else {
|
||||||
|
message = message.replace("<level>", level);
|
||||||
|
}
|
||||||
objectives.add(new BukkitObjective(ObjectiveType.BREW_ITEM, message, progress, goal));
|
objectives.add(new BukkitObjective(ObjectiveType.BREW_ITEM, message, progress, goal));
|
||||||
}
|
}
|
||||||
brewIndex++;
|
brewIndex++;
|
||||||
@ -1603,16 +1608,12 @@ public class BukkitQuester implements Quester {
|
|||||||
} else if (localeManager != null && settings.canTranslateNames() && goal.getItemMeta() != null
|
} else if (localeManager != null && settings.canTranslateNames() && goal.getItemMeta() != null
|
||||||
&& !goal.getItemMeta().hasDisplayName() && !goal.getType().equals(Material.WRITTEN_BOOK)) {
|
&& !goal.getItemMeta().hasDisplayName() && !goal.getType().equals(Material.WRITTEN_BOOK)) {
|
||||||
// Bukkit version is 1.9+ and item lacks custom name
|
// Bukkit version is 1.9+ and item lacks custom name
|
||||||
if (goal.getType().equals(Material.POTION) && localeManager.hasBasePotionData()) {
|
if (goal.getType().name().contains("POTION") && localeManager.hasBasePotionData()) {
|
||||||
final PotionMeta meta = (PotionMeta) goal.getItemMeta();
|
final String level = BukkitItemUtil.getPrettyPotionLevel(goal.getItemMeta());
|
||||||
if (meta != null && meta.getBasePotionData().isUpgraded()) {
|
if (level.isEmpty()) {
|
||||||
final int level = meta.getBasePotionData().getType().name().contains("SLOWNESS") ? 4 : 2;
|
message = message.replace(" <level>", level);
|
||||||
message = message.replace("<level>", ChatColor.GREEN + RomanNumeral.getNumeral(level)
|
|
||||||
+ ChatColor.RESET);
|
|
||||||
} else if (meta != null && meta.getBasePotionData().isExtended()) {
|
|
||||||
message = message.replace("<level>", ChatColor.GREEN + "+" + ChatColor.RESET);
|
|
||||||
} else {
|
} else {
|
||||||
message = message.replace(" <level>", "");
|
message = message.replace("<level>", level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
localeManager.sendMessage(quester.getPlayer(), message, goal);
|
localeManager.sendMessage(quester.getPlayer(), message, goal);
|
||||||
@ -3433,16 +3434,12 @@ public class BukkitQuester implements Quester {
|
|||||||
String message = formatCompletedObjectiveMessage("brewItem", goal.getAmount());
|
String message = formatCompletedObjectiveMessage("brewItem", goal.getAmount());
|
||||||
if (plugin.getConfigSettings().canTranslateNames() && is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) {
|
if (plugin.getConfigSettings().canTranslateNames() && is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) {
|
||||||
// Bukkit version is 1.9+
|
// Bukkit version is 1.9+
|
||||||
if (goal.getType().equals(Material.POTION) && plugin.getLocaleManager().hasBasePotionData()) {
|
if (goal.getType().name().contains("POTION") && plugin.getLocaleManager().hasBasePotionData()) {
|
||||||
final PotionMeta meta = (PotionMeta) goal.getItemMeta();
|
final String level = BukkitItemUtil.getPrettyPotionLevel(goal.getItemMeta());
|
||||||
if (meta != null && meta.getBasePotionData().isUpgraded()) {
|
if (level.isEmpty()) {
|
||||||
final int level = meta.getBasePotionData().getType().name().contains("SLOWNESS") ? 4 : 2;
|
message = message.replace(" <level>", level);
|
||||||
message = message.replace("<level>", ChatColor.GREEN + RomanNumeral.getNumeral(level)
|
|
||||||
+ ChatColor.RESET);
|
|
||||||
} else if (meta != null && meta.getBasePotionData().isExtended()) {
|
|
||||||
message = message.replace("<level>", ChatColor.GREEN + "+" + ChatColor.RESET);
|
|
||||||
} else {
|
} else {
|
||||||
message = message.replace(" <level>", "");
|
message = message.replace("<level>", level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!plugin.getLocaleManager().sendMessage(p, message, goal.getType(), goal.getDurability(),
|
if (!plugin.getLocaleManager().sendMessage(p, message, goal.getType(), goal.getDurability(),
|
||||||
|
@ -668,11 +668,11 @@ public class BukkitItemUtil {
|
|||||||
/**
|
/**
|
||||||
* Gets player-friendly name from enchantment. 'FIRE_ASPECT' becomes 'Fire Aspect'
|
* Gets player-friendly name from enchantment. 'FIRE_ASPECT' becomes 'Fire Aspect'
|
||||||
*
|
*
|
||||||
* @param e Enchantment to get pretty localized name of
|
* @param enchant Enchantment to get pretty localized name of
|
||||||
* @return pretty localized name
|
* @return pretty localized name
|
||||||
*/
|
*/
|
||||||
public static String getPrettyEnchantmentName(final Enchantment e) {
|
public static String getPrettyEnchantmentName(final Enchantment enchant) {
|
||||||
final String baseString = e.getName();
|
final String baseString = enchant.getName();
|
||||||
final String[] substrings = baseString.split("_");
|
final String[] substrings = baseString.split("_");
|
||||||
String prettyString = "";
|
String prettyString = "";
|
||||||
int size = 1;
|
int size = 1;
|
||||||
@ -775,4 +775,25 @@ public class BukkitItemUtil {
|
|||||||
}
|
}
|
||||||
return getEnchantmentFromProperName(enchant);
|
return getEnchantmentFromProperName(enchant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets player-friendly level from 1.9+ Potion meta. Upgrade returns numeral, extended returns '+'
|
||||||
|
*
|
||||||
|
* @param itemMeta Potion meta to get pretty localized level of
|
||||||
|
* @return pretty localized level or empty
|
||||||
|
*/
|
||||||
|
public static String getPrettyPotionLevel(final ItemMeta itemMeta) {
|
||||||
|
String prettyString = "";
|
||||||
|
if (Material.getMaterial("LINGERING_POTION") == null) {
|
||||||
|
return prettyString;
|
||||||
|
}
|
||||||
|
final PotionMeta meta = (PotionMeta) itemMeta;
|
||||||
|
if (meta != null && meta.getBasePotionData().isUpgraded()) {
|
||||||
|
final int level = meta.getBasePotionData().getType().name().contains("SLOWNESS") ? 4 : 2;
|
||||||
|
prettyString = ChatColor.GREEN + RomanNumeral.getNumeral(level) + ChatColor.RESET;
|
||||||
|
} else if (meta != null && meta.getBasePotionData().isExtended()) {
|
||||||
|
prettyString = ChatColor.GREEN + "+" + ChatColor.RESET;
|
||||||
|
}
|
||||||
|
return prettyString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user