use of org.bukkit.inventory.meta.PotionMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemPotion method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("potion_effects")) {
dList data = mechanism.getValue().asType(dList.class);
String[] d1 = data.get(0).split(",");
PotionMeta meta = (PotionMeta) item.getItemStack().getItemMeta();
meta.setBasePotionData(new PotionData(PotionType.valueOf(d1[0].toUpperCase()), CoreUtilities.toLowerCase(d1[2]).equals("true"), CoreUtilities.toLowerCase(d1[1]).equals("true")));
meta.clearCustomEffects();
for (int i = 1; i < data.size(); i++) {
String[] d2 = data.get(i).split(",");
meta.addCustomEffect(new PotionEffect(PotionEffectType.getByName(d2[0].toUpperCase()), new Element(d2[2]).asInt(), new Element(d2[1]).asInt(), new Element(d2[3]).asBoolean(), new Element(d2[4]).asBoolean(), d2.length > 5 ? dColor.valueOf(d2[5].replace("&comma", ",")).getColor() : null), false);
}
item.getItemStack().setItemMeta(meta);
}
if (mechanism.matches("potion")) {
String[] data = mechanism.getValue().asString().split(",", 4);
if (data.length < 4) {
if (mechanism.getValue().isInt()) {
item.getItemStack().setDurability((short) mechanism.getValue().asInt());
} else {
dB.echoError("Invalid effect format, use name,amplifier,extended,splash.");
}
} else {
Element data1 = new Element(data[1]);
Element data2 = new Element(data[2]);
Element data3 = new Element(data[3]);
PotionType type;
try {
type = PotionType.valueOf(data[0].toUpperCase());
} catch (Exception ex) {
dB.echoError("Invalid potion effect type '" + data[0] + "'");
return;
}
if (type == null) {
dB.echoError("Invalid potion effect type '" + data[0] + "'");
return;
}
if (!data1.isInt()) {
dB.echoError("Cannot apply effect '" + data[0] + "': '" + data[1] + "' is not a valid integer!");
return;
}
if (!data2.isBoolean()) {
dB.echoError("Cannot apply effect '" + data[0] + "': '" + data[2] + "' is not a valid boolean!");
return;
}
if (!data3.isBoolean()) {
dB.echoError("Cannot apply effect '" + data[0] + "': '" + data[3] + "' is not a valid boolean!");
return;
}
Potion pot = new Potion(type);
int d1 = data1.asInt();
if (d1 >= 1 && d1 <= pot.getType().getMaxLevel()) {
pot.setLevel(d1);
}
if (!pot.getType().isInstant()) {
pot.setHasExtendedDuration(data2.asBoolean());
}
pot.setSplash(data3.asBoolean());
item.setDurability((short) 0);
pot.apply(item.getItemStack());
}
}
}
use of org.bukkit.inventory.meta.PotionMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemPotion method getPropertyString.
@Override
public String getPropertyString() {
if (!item.getItemStack().hasItemMeta()) {
return null;
}
if (!(item.getItemStack().getItemMeta() instanceof PotionMeta)) {
return null;
}
PotionMeta meta = (PotionMeta) item.getItemStack().getItemMeta();
dList effects = new dList();
effects.add(meta.getBasePotionData().getType() + "," + meta.getBasePotionData().isUpgraded() + "," + meta.getBasePotionData().isExtended());
for (PotionEffect pot : meta.getCustomEffects()) {
StringBuilder sb = new StringBuilder();
sb.append(pot.getType().getName()).append(",").append(pot.getAmplifier()).append(",").append(pot.getDuration()).append(",").append(pot.isAmbient()).append(",").append(pot.hasParticles());
if (pot.getColor() != null) {
sb.append(",").append(new dColor(pot.getColor()).identify().replace(",", "&comma"));
}
effects.add(sb.toString());
}
return effects.identify();
}
use of org.bukkit.inventory.meta.PotionMeta in project InfernalMobs by NyaaCat.
the class AbilityPotions method onPlayerAttack.
@Override
public void onPlayerAttack(LivingEntity mobEntity, Mob mob, Player attacker, boolean isDirectAttack, EntityDamageByEntityEvent ev) {
if (Helper.possibility(0.3))
return;
Vector velocity = attacker.getEyeLocation().toVector().subtract(mobEntity.getEyeLocation().toVector());
velocity.multiply(1D / 15D);
velocity.add(new Vector(0, 0.2, 0));
ThrownPotion t = mobEntity.launchProjectile(ThrownPotion.class, velocity);
ItemStack item = new ItemStack(Material.SPLASH_POTION);
PotionMeta pm = (PotionMeta) item.getItemMeta();
PotionEffect effect = Helper.randomItem(POTION_EFFECTS);
pm.addCustomEffect(effect, false);
pm.setColor(effect.getColor());
item.setItemMeta(pm);
t.setItem(item);
}
use of org.bukkit.inventory.meta.PotionMeta 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.inventory.meta.PotionMeta 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;
}
Aggregations