public ItemBuilder setMainPotionEffect(PotionType type, boolean extendedDurability, int level, boolean splash) { if (! (meta instanceof PotionMeta)) return this; Potion potion = Potion.fromItemStack(stack); potion.setType(type); if (! type.isInstant()) potion.setHasExtendedDuration(extendedDurability); potion.setLevel(level); potion.setSplash(splash); potion.apply(stack); return this; }
/** * Turn an ItemStack with a Material of POTION into a functional potion * @param typeName PotionType string representing the potion type. (Matches Bukkit PotionType enum.) * @param upgraded Boolean specifying a level two potion if true * @param extended Is this an extended duration potion? */ public void addPotion(String typeName, boolean upgraded, boolean extended) { Material mat = this.item.getType(); Set<Material> types = new HashSet<>(); types.add(Material.POTION); types.add(Material.SPLASH_POTION); types.add(Material.LINGERING_POTION); types.add(Material.TIPPED_ARROW); if (!types.contains(mat)) return; try { PotionType type = PotionType.valueOf(typeName.toUpperCase()); PotionData pd = new PotionData(type, extended, upgraded); PotionMeta meta = (PotionMeta) this.item.getItemMeta(); meta.setBasePotionData(pd); this.item.setItemMeta(meta); } catch (Exception ex) { Bukkit.getLogger().warning(String.format("Kit configuration error: %s", ex.getMessage())); } }
@Override public void onLoad() { add(PotionType.UNCRAFTABLE, "Uncraftable", "None", "Default", "Def", "Uncraft", "UC"); add(PotionType.WATER, "Water", "Wat", "WA"); add(PotionType.MUNDANE, "Mundane", "Mun", "MU", "MD"); add(PotionType.THICK, "Thick", "Thi", "TH"); add(PotionType.AWKWARD, "Awkward", "Awk", "AW"); add(PotionType.NIGHT_VISION, "Night Vision", "NV", "NVision", "NightV", "Vision", "Night Vis", "NVis"); add(PotionType.INVISIBILITY, "Invisibility", "Invis", "Inv", "IN"); add(PotionType.JUMP, "Jump", "Jumping", "Leap", "Leaping", "JU", "LE"); add(PotionType.FIRE_RESISTANCE, "Fire Resistance", "FR", "FResistance", "Fire Resist", "Fire Res", "FResist", "FRes", "FireR"); add(PotionType.SPEED, "Speed", "SP"); add(PotionType.SLOWNESS, "Slowness", "SL", "Slow"); add(PotionType.WATER_BREATHING, "Water Breathing", "WBreathing", "WaterBreathing", "Water Breath", "WBreath", "WB"); add(PotionType.INSTANT_HEAL, "Instant Health", "IHealth", "Instant Heal", "IHeal", "Instant HP", "IHP", "IH"); add(PotionType.INSTANT_DAMAGE, "Instant Damage", "IDamage", "Instant Dmg", "IDmg", "Harming", "Harm", "ID"); add(PotionType.POISON, "Poison", "Poi", "Toxic", "PO"); add(PotionType.REGEN, "Regeneration", "Regen", "Reg", "RE"); add(PotionType.STRENGTH, "Strength", "Str", "ST"); add(PotionType.WEAKNESS, "Weakness", "Weak", "WE"); add(PotionType.LUCK, "Luck", "Lucky", "LU"); }
/** Handles potions' basic data and counts custom effects */ private void handlePotions(JsonWriter out, PotionMeta meta) throws IOException { PotionData base = meta.getBasePotionData(); if (base != null) { PotionType type = base.getType(); if (type != null) out.name("type").value( type.toString() ); out.name("extended").value( base.isExtended() ); out.name("upgraded").value( base.isUpgraded() ); } if ( meta.hasColor() ) out.name("colorR").value( meta.getColor().getRed() ) .name("colorG").value( meta.getColor().getGreen() ) .name("colorB").value( meta.getColor().getBlue() ); if ( meta.hasCustomEffects() ) out.name("customEffectCount").value( meta.getCustomEffects().size() ); }
public Turret(TurretType turretType, ArrayList<Upgrade> buyableUpgrades, ArrayList<Upgrade> conflicts, Integer fireRate, Double turretDamage, Double turretAccuracy, Double turretCost, Double turretRange, String turretName) { type = turretType; speed = fireRate; damage = turretDamage; accuracy = turretAccuracy; cost = turretCost; name = turretName; range = turretRange; unlockedPotionTypes.add(PotionType.POISON); if(buyableUpgrades != null) { possibleUpgrades = buyableUpgrades; } if(conflicts != null) { conflictingUpgrades = conflicts; } }
@Override public int getPotionId(PotionType type, int level, boolean isSplash, boolean isExtended) { PreCon.notNull(type); if (type == PotionType.WATER) return 0; int id = type.getDamageValue(); if (level > 1) { id |= 32; } if (isExtended) { id |= 64; } id |= isSplash ? 16384 : 8192; return id; }
@Override public boolean removeCustomEffect(PotionEffectType effect) { int effectId = effect.getId(); MobEffect existing = null; for (MobEffect mobEffect : getHandle().h) { if (MobEffectList.getId(mobEffect.getMobEffect()) == effectId) { existing = mobEffect; } } if (existing == null) { return false; } Validate.isTrue(getBasePotionData().getType() != PotionType.UNCRAFTABLE || getHandle().h.size() != 1, "Tipped Arrows must have at least 1 effect"); getHandle().h.remove(existing); getHandle().refreshEffects(); return true; }
public <T extends Arrow> T spawnArrow(Location loc, Vector velocity, float speed, float spread, Class<T> clazz) { Validate.notNull(loc, "Can not spawn arrow with a null location"); Validate.notNull(velocity, "Can not spawn arrow with a null velocity"); Validate.notNull(clazz, "Can not spawn an arrow with no class"); EntityArrow arrow; if (TippedArrow.class.isAssignableFrom(clazz)) { arrow = new EntityTippedArrow(world); ((EntityTippedArrow) arrow).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false))); } else if (SpectralArrow.class.isAssignableFrom(clazz)) { arrow = new EntitySpectralArrow(world); } else { arrow = new EntityTippedArrow(world); } arrow.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); arrow.shoot(velocity.getX(), velocity.getY(), velocity.getZ(), speed, spread); world.addEntity(arrow); return (T) arrow.getBukkitEntity(); }
public static PotionData toBukkit(String type) { if (type == null) { return new PotionData(PotionType.UNCRAFTABLE, false, false); } if (type.startsWith("minecraft:")) { type = type.substring(10); } PotionType potionType = null; potionType = extendable.inverse().get(type); if (potionType != null) { return new PotionData(potionType, true, false); } potionType = upgradeable.inverse().get(type); if (potionType != null) { return new PotionData(potionType, false, true); } potionType = regular.inverse().get(type); if (potionType != null) { return new PotionData(potionType, false, false); } return new PotionData(PotionType.UNCRAFTABLE, false, false); }
public static ItemStack splashPotion(PotionType type, boolean extended, boolean upgraded, String name, String... lores) { ItemStack potion = new ItemStack(Material.SPLASH_POTION, 1); PotionMeta meta = (PotionMeta) potion.getItemMeta(); meta.setBasePotionData(new PotionData(type, extended, upgraded)); potion.setItemMeta(meta); return potion; }
public PotionCustomItem(Material material, Config config, PlaceholderRegistry placeholders) { super(material, config, placeholders); type = config.getEnum("potion-type", PotionType.class); customColor = PlaceholderValue.colorValue(config.getString("color")); customEffects = new ArrayList<>(); Collection<Map<String, Object>> rawEffects = (Collection<Map<String, Object>>) config.getCollection("effects"); if(rawEffects != null) { for (Map<String, Object> e : rawEffects) customEffects.add(new PotionEffect(e)); } }
public static ItemStack createPotion(PotionType potionType, int level, String name) { Potion potion = new Potion(potionType); potion.setLevel(level); ItemStack itemStack = potion.toItemStack(1); ItemMeta meta = itemStack.getItemMeta(); meta.setDisplayName(name); itemStack.setItemMeta(meta); return itemStack; }
public ItemMaker addPotionType(PotionType type, int time, int amplifier) { PotionMeta itemMeta = (PotionMeta) this.itemStack.getItemMeta(); itemMeta.setMainEffect(type.getEffectType()); itemMeta.addCustomEffect(new PotionEffect(type.getEffectType(), time * 20, amplifier), true); this.itemStack.setItemMeta(itemMeta); return this; }
@Test public void itemWithTypedMetaMatches() throws Throwable { ImItemStack item = ItemStack.builder(Material.POTION) .meta(PotionMeta.class, meta -> meta.setBasePotionData(new PotionData(PotionType.LUCK, false, false))) .immutable(); assertMatches(item, item); }
@Test public void vanillaBrews() throws Exception { assertEquals(BENEFICIAL, classify(Bukkit.potionRegistry().get(Bukkit.key("healing")))); assertEquals(BENEFICIAL, classify(new PotionData(PotionType.INSTANT_HEAL, false, false))); assertEquals(HARMFUL, classify(Bukkit.potionRegistry().get(Bukkit.key("harming")))); assertEquals(HARMFUL, classify(new PotionData(PotionType.INSTANT_DAMAGE, false, false))); }
public static PotionEffect[] actualPotionEffects(@NotNull PotionMeta meta) { List<PotionEffect> effects = new ArrayList<>(); effects.addAll(meta.getCustomEffects()); if (meta.getBasePotionData().getType() != PotionType.UNCRAFTABLE) { effects.add(fromPotionData(meta.getBasePotionData())); } return effects.toArray(new PotionEffect[effects.size()]); }
/** * Drop player's potion effect on his death * * @param event Event */ @EventHandler public void onPlayerDeath(PlayerDeathEvent event) { for (PotionEffect potionEffect : event.getEntity().getActivePotionEffects()) { if (this.blacklist.contains(potionEffect.getType())) continue; if (PotionType.getByEffect(potionEffect.getType()) == null) continue; if(potionEffect.getDuration() > 10000) continue; Potion potion = new Potion(PotionType.getByEffect(potionEffect.getType()), potionEffect.getAmplifier() + 1); ItemStack stack = potion.toItemStack(1); PotionMeta meta = (PotionMeta) stack.getItemMeta(); meta.clearCustomEffects(); meta.addCustomEffect(new PotionEffect(potionEffect.getType(), potionEffect.getDuration(), potionEffect.getAmplifier()), true); stack.setItemMeta(meta); event.getDrops().add(stack); event.getEntity().removePotionEffect(potionEffect.getType()); } }
@Override public void read(DataInputStream input) throws IOException { PotionType type = PotionType.valueOf(input.readUTF()); boolean extended = input.readBoolean(); boolean upgraded = input.readBoolean(); setValue(new PotionData(type, extended, upgraded)); }
private boolean testValidity(ItemStack[] contents) { for (ItemStack stack : contents) { if (stack != null && stack.getType() == Material.POTION && stack.getDurability() != 0) { Potion potion = Potion.fromItemStack(stack); // Just to be safe, null check this. if (potion == null) continue; PotionType type = potion.getType(); // Mundane potions etc, can return a null type if (type == null) continue; // is 33s poison, allow if (type == PotionType.POISON && !potion.hasExtendedDuration() && potion.getLevel() == 1) { continue; } if (potion.getLevel() > getMaxLevel(type)) { return false; } } } return true; }
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getItem() != null && event.getItem().getType() == Material.POTION && Potion.fromItemStack(event.getItem()).getType() == PotionType.POISON && !this.game.isPvPActivated()) { event.getPlayer().sendMessage(ChatColor.RED + "Vous ne pouvez pas utiliser cet objet hors du PvP."); event.setCancelled(true); event.getPlayer().updateInventory(); } }
public static short guessData(final ThrownPotion p) { if (p.getEffects().size() == 1) { final PotionEffect e = p.getEffects().iterator().next(); final Potion d = new Potion(PotionType.getByEffect(e.getType())).splash(); return d.toDamageValue(); } return 0; }
public CustomPotion(String name, PotionType type, PotionEffect effect, String... lore) { super(Material.POTION, name, 0, lore); PotionMeta meta = (PotionMeta) getItemMeta(); meta.setBasePotionData(new PotionData(type)); meta.addCustomEffect(effect, true); setItemMeta(meta); }
@EventHandler public void fixTippedArrowBlacklist(ProjectileHitEvent e) { if (e.getEntity() instanceof TippedArrow && e.getEntity().getShooter() instanceof Player && !helper.getWorldGuard().hasPermission((Player) e.getEntity().getShooter(), "worldguard.override.potions")) { TippedArrow arrow = (TippedArrow) e.getEntity(); if (helper.isBlacklistedPotion(arrow.getBasePotionData(), e.getEntity().getLocation().getWorld())) { ((Player) arrow.getShooter()).sendMessage(ChatColor.RED + "Sorry, tipped arrows with " + arrow.getBasePotionData().getType().name() + " have no effect."); arrow.setBasePotionData(new PotionData(PotionType.AWKWARD)); } } }
/** * Determines whether an item is a water potion. * * @param item * @return true if the item is a water potion, false otherwise */ protected boolean isWaterPotion(ItemStack item) { if (plugin.getServerVersion() >= 9) { // Method getBasePotionData does not exist for versions prior to Minecraft 1.9. return ((PotionMeta) (item.getItemMeta())).getBasePotionData().getType() == PotionType.WATER; } return item.getDurability() == 0; }
private static PotionType potionTypeFromLegacy(PotionEffectType type) { if (type == PotionEffectType.NIGHT_VISION) { return PotionType.NIGHT_VISION; } else if (type == PotionEffectType.INVISIBILITY) { return PotionType.INVISIBILITY; } else if (type == PotionEffectType.JUMP) { return PotionType.JUMP; } else if (type == PotionEffectType.FIRE_RESISTANCE) { return PotionType.FIRE_RESISTANCE; } else if (type == PotionEffectType.SPEED) { return PotionType.SPEED; } else if (type == PotionEffectType.SLOW) { return PotionType.SLOWNESS; } else if (type == PotionEffectType.WATER_BREATHING) { return PotionType.WATER_BREATHING; } else if (type == PotionEffectType.HEALTH_BOOST) { return PotionType.INSTANT_HEAL; } else if (type == PotionEffectType.HARM) { return PotionType.INSTANT_DAMAGE; } else if (type == PotionEffectType.HARM) { return PotionType.INSTANT_DAMAGE; } else if (type == PotionEffectType.POISON) { return PotionType.POISON; } else if (type == PotionEffectType.REGENERATION) { return PotionType.REGEN; } else if (type == PotionEffectType.INCREASE_DAMAGE) { return PotionType.STRENGTH; } else if (type == PotionEffectType.WEAKNESS) { return PotionType.WEAKNESS; } else if (type == PotionEffectType.LUCK) { return PotionType.LUCK; } else { throw new IllegalArgumentException(type.getName() + " is not convertable."); } }
public static PotionType getPotionEffect(ItemStack itemStack) { if (itemStack.getItemMeta() instanceof PotionMeta) { if (Utils.getMajorVersion() < 9) { return Potion.fromItemStack(itemStack).getType(); } else { return ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().getType(); } } return null; }
/** * @param itemStack Potion Item whose base effect name should be looked up * @return Localized Name of the Base Potion Effect */ public static String getPotionEffectName(ItemStack itemStack) { if (itemStack == null) return null; if (!(itemStack.getItemMeta() instanceof PotionMeta)) return ""; PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta(); PotionType potionType; boolean upgraded; if (Utils.getMajorVersion() < 9) { potionType = Potion.fromItemStack(itemStack).getType(); upgraded = Potion.fromItemStack(itemStack).getLevel() == 2; } else { potionType = potionMeta.getBasePotionData().getType(); upgraded = potionMeta.getBasePotionData().isUpgraded(); } String potionEffectString = formatDefaultString(potionType.toString()); String upgradeString = upgraded ? "II" : ""; for (PotionEffectName potionEffectName : potionEffectNames) { if (potionEffectName.getEffect() == potionType) { potionEffectString = potionEffectName.getLocalizedName(); } } return potionEffectString + (upgradeString.length() > 0 ? " " + upgradeString : ""); }
/** * Parses a potion from configuration. * <p> * The basic format is <code>potion: <type>,<amount>,<level>,[splash]</code> * * @param string String to read * @return ItemStack from string, or null if parsing fails */ public static ItemStack readPotion(final String string) { // Normalize string String normalized = string.replaceAll("\\s", ""); normalized = normalized.substring(string.indexOf(":") + 1); String[] split = normalized.split(","); PotionType type = net.dmulloy2.types.PotionType.findPotion(split[0]); if (type == null) throw new NullPointerException("Null potion type \"" + split[0] + "\""); int amount = NumberUtil.toInt(split[1]); if (amount < 0) throw new IllegalArgumentException("Invalid amount " + amount); int level = NumberUtil.toInt(split[2]); if (level < 0) throw new IllegalArgumentException("Invalid level " + level); boolean splash = split.length > 3 && Util.toBoolean(split[3]); boolean extended = split.length > 4 && Util.toBoolean(split[4]); ItemStack potion = CompatUtil.createPotion(type, amount, level, splash, extended); // Parse meta parseItemMeta(potion, normalized); return potion; }
public ItemStack createPotion(PotionType poti, String nombre, Integer valor) { ItemStack poti2 = new Potion(poti).splash().toItemStack(3); ItemMeta meta = (ItemMeta) poti2.getItemMeta(); ArrayList<String> lore = new ArrayList<String>(); lore.add("" + valor + " gemas."); meta.setLore(lore); meta.setDisplayName(nombre); poti2.setItemMeta(meta); return poti2; }
private void handleTraps() { Player player = getPlayer(); if (Permissions.trapsBypass(player)) { return; } if (Misc.getRandom().nextBoolean()) { player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.Boom")); TNTPrimed tnt = (TNTPrimed) player.getWorld().spawnEntity(fishingCatch.getLocation(), EntityType.PRIMED_TNT); fishingCatch.setPassenger(tnt); Vector velocity = fishingCatch.getVelocity(); double magnitude = velocity.length(); fishingCatch.setVelocity(velocity.multiply((magnitude + 1) / magnitude)); tnt.setMetadata(mcMMO.tntsafeMetadataKey, mcMMO.metadataValue); tnt.setFuseTicks(3 * Misc.TICK_CONVERSION_FACTOR); } else { player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.Poison")); ThrownPotion thrownPotion = player.getWorld().spawn(fishingCatch.getLocation(), ThrownPotion.class); thrownPotion.setItem(new Potion(PotionType.POISON).splash().toItemStack(1)); fishingCatch.setPassenger(thrownPotion); } }
public void setType(String type) throws InstructionParseException { typeE = Existence.REQUIRED; try { this.type = PotionType.valueOf(type.toUpperCase()); } catch (IllegalArgumentException e) { throw new InstructionParseException("No such potion type: " + type); } }
private PotionType findPotion(String token){ token = token.replaceAll("[(potion|instant)_ ]", "").toLowerCase(); for(PotionType o: PotionType.values()) if(o.name().replaceAll("[(POTION|INSTANT)_ ]", "").equalsIgnoreCase(token)) return o; return null; }
public static PotionData deserializePotionData(Map<String, Object> serializedPotionData) { if (serializedPotionData != null && serializedPotionData.containsKey("Type")) { PotionType potionType = Utilities.getPotionType(ObjectUtilities.getObject(serializedPotionData, String.class, "Type").toUpperCase().replace(' ', '_')); if (potionType != null) { boolean extended = ObjectUtilities.getObject(serializedPotionData, Boolean.class, "Extended", false); boolean upgraded = ObjectUtilities.getObject(serializedPotionData, Boolean.class, "Upgraded", false); return new PotionData(potionType, extended, upgraded); } } return null; }
public static PotionType getPotionType(String name) { if (name != null) { for (PotionType potionType : PotionType.values()) { if (potionType != null && potionType.name().equals(name)) return potionType; } switch (name) { case "FATIGUE": return PotionType.WEAKNESS; case "HARM": case "HARMING": case "DAMAGE": return PotionType.INSTANT_DAMAGE; case "HEAL": case "HEALTH": case "HEALING": return PotionType.INSTANT_HEAL; case "LEAP": case "LEAPING": return PotionType.JUMP; case "REGENERATION": return PotionType.REGEN; case "SLOW": return PotionType.SLOWNESS; } } return null; }
/** * Get a simple potion name. * * @param type The potion type. */ public static String getSimple(PotionType type) { PreCon.notNull(type); StringBuilder buffer = buffer(); appendSimple(buffer, type); return buffer.toString(); }
public static ItemStack getPotionStack(PotionType type, int level, boolean isSplash, boolean isExtended) { PreCon.notNull(type); if (_handler == null) throw new UnsupportedOperationException("A potion NMS handler was not found."); return _handler.getPotionStack(type, level, isSplash, isExtended); }
@Override public ItemStack getPotionStack(PotionType type, int level, boolean isSplash, boolean isExtended) { PreCon.notNull(type); int id = getPotionId(type, level, isSplash, isExtended); ItemStack itemStack = new ItemStack(Material.POTION); itemStack.setDurability((short)id); return itemStack; }