use of org.bukkit.potion.PotionData in project acidisland by tastybento.
the class Challenges method getPotion.
/**
* Converts a serialized potion to a ItemStack of that potion
* @param element
* @param rewardQty
* @param configFile that is being used
* @return ItemStack of the potion
*/
public static ItemStack getPotion(String[] element, int rewardQty, String configFile) {
// Check for potion aspects
boolean splash = false;
boolean extended = false;
boolean linger = false;
int level = 1;
if (element.length > 2) {
// Add level etc.
if (!element[2].isEmpty()) {
try {
level = Integer.valueOf(element[2]);
} catch (Exception e) {
level = 1;
}
}
}
if (element.length > 3) {
// Bukkit.getLogger().info("DEBUG: level = " + Integer.valueOf(element[2]));
if (element[3].equalsIgnoreCase("EXTENDED")) {
// Bukkit.getLogger().info("DEBUG: Extended");
extended = true;
}
}
if (element.length > 4) {
if (element[4].equalsIgnoreCase("SPLASH")) {
// Bukkit.getLogger().info("DEBUG: splash");
splash = true;
}
if (element[4].equalsIgnoreCase("LINGER")) {
// Bukkit.getLogger().info("DEBUG: linger");
linger = true;
}
}
if (Bukkit.getServer().getVersion().contains("(MC: 1.8") || Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
// Add the effect of the potion
final PotionType potionType = PotionType.valueOf(element[1]);
if (potionType == null) {
Bukkit.getLogger().severe("Potion effect '" + element[1] + "' in " + configFile + " is unknown - skipping!");
Bukkit.getLogger().severe("Use one of the following:");
for (PotionType name : PotionType.values()) {
Bukkit.getLogger().severe(name.name());
}
} else {
final Potion rewPotion = new Potion(potionType);
if (potionType != PotionType.INSTANT_DAMAGE && potionType != PotionType.INSTANT_HEAL) {
// Instant potions cannot be extended
rewPotion.setHasExtendedDuration(extended);
}
rewPotion.setLevel(level);
rewPotion.setSplash(splash);
return rewPotion.toItemStack(rewardQty);
}
} else {
// 1.9
try {
ItemStack result = new ItemStack(Material.POTION, rewardQty);
if (splash) {
result = new ItemStack(Material.SPLASH_POTION, rewardQty);
}
if (linger) {
result = new ItemStack(Material.LINGERING_POTION, rewardQty);
}
PotionMeta potionMeta = (PotionMeta) result.getItemMeta();
try {
PotionData potionData = new PotionData(PotionType.valueOf(element[1].toUpperCase()), extended, level > 1 ? true : false);
potionMeta.setBasePotionData(potionData);
} catch (IllegalArgumentException iae) {
Bukkit.getLogger().severe("Potion parsing problem with " + element[1] + ": " + iae.getMessage());
potionMeta.setBasePotionData(new PotionData(PotionType.WATER));
}
result.setItemMeta(potionMeta);
return result;
/*
Potion1_9 rewPotion = new Potion1_9(Potion1_9.PotionType.valueOf(element[1].toUpperCase()));
rewPotion.setHasExtendedDuration(extended);
rewPotion.setStrong(level > 1 ? true : false);
rewPotion.setSplash(splash);
rewPotion.setLinger(linger);
return rewPotion.toItemStack(rewardQty);
*/
} catch (Exception e) {
e.printStackTrace();
Bukkit.getLogger().severe("Potion effect '" + element[1] + "' in " + configFile + " is unknown - skipping!");
Bukkit.getLogger().severe("Use one of the following:");
for (PotionType name : PotionType.values()) {
Bukkit.getLogger().severe(name.name());
}
return new ItemStack(Material.POTION, rewardQty);
}
}
return null;
}
use of org.bukkit.potion.PotionData in project acidisland by tastybento.
the class Challenges method createItem.
/**
* Creates an inventory item for the challenge
* @param challengeName
* @param player
* @return Control Panel item
*/
private CPItem createItem(String challengeName, Player player) {
CPItem item = null;
// Get the icon
ItemStack icon = null;
String iconName = getChallengeConfig().getString("challenges.challengeList." + challengeName + ".icon", "");
if (!iconName.isEmpty()) {
try {
// Split if required
String[] split = iconName.split(":");
if (split.length == 1) {
// Some material does not show in the inventory
if (iconName.equalsIgnoreCase("potato")) {
iconName = "POTATO_ITEM";
} else if (iconName.equalsIgnoreCase("brewing_stand")) {
iconName = "BREWING_STAND_ITEM";
} else if (iconName.equalsIgnoreCase("carrot")) {
iconName = "CARROT_ITEM";
} else if (iconName.equalsIgnoreCase("cauldron")) {
iconName = "CAULDRON_ITEM";
} else if (iconName.equalsIgnoreCase("lava") || iconName.equalsIgnoreCase("stationary_lava")) {
iconName = "LAVA_BUCKET";
} else if (iconName.equalsIgnoreCase("water") || iconName.equalsIgnoreCase("stationary_water")) {
iconName = "WATER_BUCKET";
} else if (iconName.equalsIgnoreCase("portal")) {
iconName = "OBSIDIAN";
} else if (iconName.equalsIgnoreCase("PUMPKIN_STEM")) {
iconName = "PUMPKIN";
} else if (iconName.equalsIgnoreCase("skull")) {
iconName = "SKULL_ITEM";
} else if (iconName.equalsIgnoreCase("COCOA")) {
iconName = "INK_SACK:3";
} else if (iconName.equalsIgnoreCase("NETHER_WARTS")) {
iconName = "NETHER_STALK";
}
if (StringUtils.isNumeric(iconName)) {
icon = new ItemStack(Integer.parseInt(iconName));
} else {
icon = new ItemStack(Material.valueOf(iconName));
}
// Check POTION for V1.9 - for some reason, it must be declared as WATER otherwise comparison later causes an NPE
if (icon.getType().name().contains("POTION")) {
if (!plugin.getServer().getVersion().contains("(MC: 1.8") && !plugin.getServer().getVersion().contains("(MC: 1.7")) {
PotionMeta potionMeta = (PotionMeta) icon.getItemMeta();
potionMeta.setBasePotionData(new PotionData(PotionType.WATER));
icon.setItemMeta(potionMeta);
}
}
} else if (split.length == 2) {
if (StringUtils.isNumeric(split[0])) {
icon = new ItemStack(Integer.parseInt(split[0]));
} else {
icon = new ItemStack(Material.valueOf(split[0]));
}
// Check POTION for V1.9 - for some reason, it must be declared as WATER otherwise comparison later causes an NPE
if (icon.getType().name().contains("POTION")) {
if (!plugin.getServer().getVersion().contains("(MC: 1.8") && !plugin.getServer().getVersion().contains("(MC: 1.7")) {
PotionMeta potionMeta = (PotionMeta) icon.getItemMeta();
try {
potionMeta.setBasePotionData(new PotionData(PotionType.valueOf(split[1].toUpperCase())));
} catch (Exception e) {
plugin.getLogger().severe("Challenges icon: Potion type of " + split[1] + " is unknown, setting to WATER. Valid types are:");
for (PotionType type : PotionType.values()) {
plugin.getLogger().severe(type.name());
}
potionMeta.setBasePotionData(new PotionData(PotionType.WATER));
}
icon.setItemMeta(potionMeta);
}
} else if (icon.getType().equals(Material.MONSTER_EGG)) {
// Handle monster egg icons
try {
EntityType type = EntityType.valueOf(split[1].toUpperCase());
if (Bukkit.getServer().getVersion().contains("(MC: 1.8") || Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
icon = new SpawnEgg(type).toItemStack();
} else {
try {
icon = new SpawnEgg1_9(type).toItemStack();
} catch (Exception ex) {
plugin.getLogger().severe("Monster eggs not supported with this server version.");
}
}
} catch (Exception e) {
Bukkit.getLogger().severe("Spawn eggs must be described by name. Try one of these (not all are possible):");
for (EntityType type : EntityType.values()) {
if (type.isSpawnable() && type.isAlive()) {
plugin.getLogger().severe(type.toString());
}
}
}
} else {
icon.setDurability(Integer.valueOf(split[1]).shortValue());
}
}
} catch (Exception e) {
// Icon was not well formatted
plugin.getLogger().warning("Error in challenges.yml - icon format is incorrect for " + challengeName + ":" + iconName);
plugin.getLogger().warning("Format should be 'icon: MaterialType:Damage' where Damage is optional");
}
}
if (icon == null) {
icon = new ItemStack(Material.PAPER);
}
// Handle spaces (AIR icon)
if (icon.getType() == Material.AIR) {
return new CPItem(icon, "");
}
String description = ChatColor.GREEN + ChatColor.translateAlternateColorCodes('&', getChallengeConfig().getString("challenges.challengeList." + challengeName + ".friendlyname", challengeName.substring(0, 1).toUpperCase() + challengeName.substring(1)));
// Remove extraneous info
ItemMeta im = icon.getItemMeta();
if (!plugin.getServer().getVersion().contains("1.7")) {
im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
im.addItemFlags(ItemFlag.HIDE_DESTROYS);
im.addItemFlags(ItemFlag.HIDE_PLACED_ON);
}
// Check if completed or not
boolean complete = false;
if (Settings.addCompletedGlow && plugin.getPlayers().checkChallenge(player.getUniqueId(), challengeName)) {
// Complete! Make the icon glow
im.addEnchant(Enchantment.ARROW_DAMAGE, 0, true);
if (!plugin.getServer().getVersion().contains("1.7")) {
im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
complete = true;
}
icon.setItemMeta(im);
boolean repeatable = false;
if (getChallengeConfig().getBoolean("challenges.challengeList." + challengeName + ".repeatable", false)) {
// Repeatable
repeatable = true;
}
// setting Settings.removeCompleteOntimeChallenges
if (!complete || ((complete && repeatable) || !Settings.removeCompleteOntimeChallenges)) {
// Store the challenge panel item and the command that will be
// called if it is activated.
item = new CPItem(icon, description, Settings.CHALLENGECOMMAND + " c " + challengeName, null);
// Get the challenge description, that changes depending on
// whether the challenge is complete or not.
List<String> lore = challengeDescription(challengeName, player);
item.setLore(lore);
}
return item;
}
use of org.bukkit.potion.PotionData in project Essentials by drtshock.
the class BasePotionDataProvider method createPotionItem.
@Override
public ItemStack createPotionItem(Material initial, int effectId) throws IllegalArgumentException {
ItemStack potion = new ItemStack(initial, 1);
if (effectId == 0) {
return potion;
}
int damageValue = getBit(effectId, 0) + 2 * getBit(effectId, 1) + 4 * getBit(effectId, 2) + 8 * getBit(effectId, 3);
PotionType type = damageValueToType.get(damageValue);
if (type == null) {
throw new IllegalArgumentException("Unable to process potion effect ID " + effectId + " with damage value " + damageValue);
}
boolean extended = getBit(effectId, 6) == 1;
boolean upgraded = getBit(effectId, 5) == 1;
boolean splash = getBit(effectId, 14) == 1;
if (splash && initial == Material.POTION) {
potion = new ItemStack(Material.SPLASH_POTION, 1);
}
PotionMeta meta = (PotionMeta) potion.getItemMeta();
PotionData data = new PotionData(type, extended, upgraded);
// this method is exclusive to recent 1.9+
meta.setBasePotionData(data);
potion.setItemMeta(meta);
return potion;
}
use of org.bukkit.potion.PotionData in project Glowstone by GlowstoneMC.
the class GlowMetaPotion method dataFromString.
/**
* Converts a Potion ID string to the PotionData of this item meta.
*
* @param string the Potion ID string
* @return the resultant PotionData
*/
private PotionData dataFromString(String string) {
PotionType type;
boolean extended = false, upgraded = false;
if (string.startsWith("minecraft:"))
string = string.replace("minecraft:", "");
if (string.startsWith("long_")) {
string = string.replace("long_", "");
extended = true;
} else if (string.startsWith("strong_")) {
string = string.replace("strong_", "");
upgraded = true;
}
type = PotionTypeTable.fromName(string);
return new PotionData(type, extended, upgraded);
}
Aggregations