Java 类org.bukkit.potion.PotionData 实例源码

项目:QuarSK    文件:PotionUtils.java   
@NotNull
public static PotionEffect fromPotionData(@NotNull PotionData data) {
    PotionEffectType type = data.getType().getEffectType();
    if (type == PotionEffectType.HEAL || type == PotionEffectType.HARM) {
        return new PotionEffect(type, 1, data.isUpgraded() ? 2 : 1);
    } else if (type == PotionEffectType.REGENERATION || type == PotionEffectType.POISON) {
        if (data.isExtended()) {
            return new PotionEffect(type, 1800, 1);
        } else if (data.isUpgraded()) {
            return new PotionEffect(type, 440, 2);
        } else {
            return new PotionEffect(type, 900, 1);
        }
    } else if (type == PotionEffectType.NIGHT_VISION || type == PotionEffectType.INVISIBILITY
               || type == PotionEffectType.FIRE_RESISTANCE || type == PotionEffectType.WATER_BREATHING) {
        return new PotionEffect(type, data.isExtended() ? 9600 : 3600, 1);
    } else if (type == PotionEffectType.WEAKNESS || type == PotionEffectType.SLOW) {
        return new PotionEffect(type, data.isExtended() ? 4800 : 1800, 1);
    } else if (data.isExtended()) {
        return new PotionEffect(type, 9600, 1);
    } else if (data.isUpgraded()) {
        return new PotionEffect(type, 1800, 2);
    } else {
        return new PotionEffect(type, 3600, 1);
    }
}
项目:AthenaGM    文件:MapInfoKitItem.java   
/**
 * 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()));
    }
}
项目:SignShopExport    文件:JsonItemMeta.java   
/** 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() );
}
项目:SupaCommons    文件:ItemBuilder.java   
/**
 * Sets this item's main effect, assuming it is a potion.
 * <p />
 * <b>UNSAFE</b>
 *
 * @param effectType effect type to set
 *
 * @return this item builder instance, for chaining
 * @see ItemBuilder#potionMain(PotionData) 
 */
@Deprecated
public ItemBuilder potionMain(PotionEffectType effectType) {
  if (isPotionMeta()) {
    try {
      PotionMeta potionMeta = (PotionMeta) this.itemMeta;
      if (potionMeta.setMainEffect(effectType) == false) {
        potionMeta.setBasePotionData(new PotionData(potionTypeFromLegacy(effectType), false, false));
      }
    } catch (Exception e) {
      if (!this.failSilently) {
        e.printStackTrace();
      }
    }
  }
  return this;
}
项目:BetonQuest    文件:PotionHandler.java   
public boolean checkBase(PotionData base) {
    switch (typeE) {
    case WHATEVER:
        return true;
    case REQUIRED:
        if (base.getType() != type) {
            return false;
        }
        if (extendedE == Existence.REQUIRED && base.isExtended() != extended) {
            return false;
        }
        if (upgradedE == Existence.REQUIRED && base.isUpgraded() != upgraded) {
            return false;
        }
        return true;
    default:
        return false;
    }
}
项目:SpigotSource    文件:CraftWorld.java   
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();
}
项目:SpigotSource    文件:CraftPotionUtil.java   
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);
}
项目:uppercore    文件:GuiUtil.java   
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;
}
项目:uppercore    文件:PotionCustomItem.java   
@Override
public void processMeta(Player player, ItemMeta m) {
    super.processMeta(player, m);
    PotionMeta meta = (PotionMeta) m;
    if(type != null)
        meta.setBasePotionData(new PotionData(type));
    if(customColor != null)
        meta.setColor(customColor.resolve(player));
    meta.clearCustomEffects();
    for(PotionEffect e : customEffects)
        meta.addCustomEffect(e, true);
}
项目:ProjectAres    文件:GlobalItemParser.java   
public ItemStack parseItem(Element el, Material type, short damage) throws InvalidXMLException {
    int amount = XMLUtils.parseNumber(el.getAttribute("amount"), Integer.class, 1);

    // If the item is a potion with non-zero damage, and there is
    // no modern potion ID, decode the legacy damage value.
    final Potion legacyPotion;
    if(type == Material.POTION && damage > 0 && el.getAttribute("potion") == null) {
        try {
            legacyPotion = Potion.fromDamage(damage);
        } catch(IllegalArgumentException e) {
            throw new InvalidXMLException("Invalid legacy potion damage value " + damage + ": " + e.getMessage(), el, e);
        }

        // If the legacy splash bit is set, convert to a splash potion
        if(legacyPotion.isSplash()) {
            type = Material.SPLASH_POTION;
            legacyPotion.setSplash(false);
        }

        // Potions always have damage 0
        damage = 0;
    } else {
        legacyPotion = null;
    }

    ItemStack itemStack = new ItemStack(type, amount, damage);
    if(itemStack.getType() != type) {
        throw new InvalidXMLException("Invalid item/block", el);
    }

    final ItemMeta meta = itemStack.getItemMeta();
    if(meta != null) { // This happens if the item is "air"
        parseItemMeta(el, meta);

        // If we decoded a legacy potion, apply it now, but only if there are no custom effects.
        // This emulates the old behavior of custom effects overriding default effects.
        if(legacyPotion != null) {
            final PotionMeta potionMeta = (PotionMeta) meta;
            if(!potionMeta.hasCustomEffects()) {
                potionMeta.setBasePotionData(new PotionData(legacyPotion.getType(),
                                                            legacyPotion.hasExtendedDuration(),
                                                            legacyPotion.getLevel() == 2));
            }
        }

        itemStack.setItemMeta(meta);
    }

    return itemStack;
}
项目:ProjectAres    文件:ItemMatcherTest.java   
@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);
}
项目:ProjectAres    文件:PotionUtils.java   
public static Collection<PotionEffect> effects(@Nullable PotionData potion, @Nullable Collection<PotionEffect> customEffects) {
    final ImmutableList.Builder<PotionEffect> builder = ImmutableList.builder();
    if(potion != null) {
        builder.addAll(effects(potion));
    }
    if(customEffects != null) {
        builder.addAll(customEffects);
    }
    return builder.build();
}
项目:ProjectAres    文件:PotionClassificationTest.java   
@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)));
}
项目:Leveled-Storage    文件:PotionDataStorage.java   
@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));
}
项目:GameBoxx    文件:EItem.java   
/**
 * Get the {@link PotionData} from the potion item.
 * <p/>
 * Items: {@link Material#POTION}, {@link Material#SPLASH_POTION}, {@link Material#LINGERING_POTION}
 *
 * @return {@link PotionData}. ({@code null} when no potion or no data)
 */
public PotionData getPotion() {
    ItemMeta meta = getItemMeta();
    if (meta instanceof PotionMeta) {
        return ((PotionMeta)meta).getBasePotionData();
    }
    return null;
}
项目:GameBoxx    文件:EItem.java   
/**
 * Set the base {@link PotionData} on the potion item.
 * <p/>
 * Items: {@link Material#POTION}, {@link Material#SPLASH_POTION}, {@link Material#LINGERING_POTION}
 *
 * @param data The {@link PotionData} to set.
 * @return this instance
 */
public EItem setPotion(PotionData data) {
    ItemMeta meta = getItemMeta();
    if (meta instanceof PotionMeta) {
        ((PotionMeta)meta).setBasePotionData(data);
        setItemMeta(meta);
    }
    return this;
}
项目:CS-CoreLib    文件:CustomPotion.java   
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);
}
项目:WorldGuardFix    文件:Listeners.java   
@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));
        }
    }
}
项目:WorldGuardFix    文件:Listeners.java   
@EventHandler
public void disableBlacklistedPotionUse(UseItemEvent e) {

    boolean wasCancelled = e.isCancelled();
    Material material = e.getItemStack().getType();

    if (material.equals(Material.POTION)
            || material.equals(Material.SPLASH_POTION)
            || material.equals(Material.LINGERING_POTION)) {

        Player p = e.getCause().getFirstPlayer();
        if (p != null && helper.getWorldGuard().hasPermission(p, "worldguard.override.potions")) return;

        PotionData potionType = ((PotionMeta) e.getItemStack().getItemMeta()).getBasePotionData();
        if (helper.isBlacklistedPotion(potionType, e.getWorld())) {

            e.setCancelled(true);
            if (e.getOriginalEvent() instanceof Cancellable)
                ((Cancellable) e.getOriginalEvent()).setCancelled(true);

            if (p != null && !wasCancelled) {
                p.sendMessage(ChatColor.RED + "Sorry, potions with "
                        + potionType.getType().name() + " can't be used.");
                p.updateInventory();
            }
        }
    }
}
项目:SupaCommons    文件:ItemBuilder.java   
/**
 * Sets this item's base potion data, assuming it is a potion.
 * <p />
 * <b>UNSAFE</b>
 *
 * @param data data to set
 *
 * @return this item builder instance, for chaining
 */
public ItemBuilder potionMain(PotionData data) {
  if (isPotionMeta()) {
    try {
      ((PotionMeta) this.itemMeta).setBasePotionData(data);
    } catch (Exception e) {
      if (!this.failSilently) {
        e.printStackTrace();
      }
    }
  }
  return this;
}
项目:KingKits    文件:ItemUtilities.java   
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;
}
项目:KingKits    文件:ItemUtilities.java   
public static Map<String, Object> serializePotionData(PotionData potionData) {
    Map<String, Object> serializedPotionData = new LinkedHashMap<>();
    if (potionData != null) {
        serializedPotionData.put("Type", StringUtilities.capitalizeFully(potionData.getType().toString().replace('_', ' ')));
        serializedPotionData.put("Extended", potionData.isExtended());
        serializedPotionData.put("Upgraded", potionData.isUpgraded());
    }
    return serializedPotionData;
}
项目:SpigotSource    文件:CraftPotionUtil.java   
public static String fromBukkit(PotionData data) {
    if (data.isUpgraded()) {
        return upgradeable.get(data.getType());
    }
    if (data.isExtended()) {
        return extendable.get(data.getType());
    }
    return regular.get(data.getType());
}
项目:SpigotSource    文件:CraftPotionBrewer.java   
public Collection<PotionEffect> getEffects(PotionType damage, boolean upgraded, boolean extended) {
    if (cache.containsKey(damage))
        return cache.get(damage);

    List<MobEffect> mcEffects = PotionRegistry.a(CraftPotionUtil.fromBukkit(new PotionData(damage, extended, upgraded))).a();

    ImmutableList.Builder<PotionEffect> builder = new ImmutableList.Builder<PotionEffect>();
    for (MobEffect effect : mcEffects) {
        builder.add(CraftPotionUtil.toBukkit(effect));
    }

    cache.put(damage, builder.build());

    return cache.get(damage);
}
项目:TNE-Bukkit    文件:SerialPotionData.java   
@Override
public ItemStack build(ItemStack stack) {
  if(valid) {
    PotionMeta meta = (PotionMeta)stack.getItemMeta();
    if(color != null) meta.setColor(color);
    customEffects.forEach((effect)->meta.addCustomEffect(effect, true));
    PotionData data = new PotionData(PotionType.valueOf(type), extended, upgraded);
    meta.setBasePotionData(data);
    stack.setItemMeta(meta);
  }
  return stack;
}
项目:ProjectAres    文件:PotionUtils.java   
public static Collection<PotionEffect> effects(PotionData data) {
    return Potion.getBrewer().getEffects(data.getType(), data.isUpgraded(), data.isExtended());
}
项目:QuarSK    文件:PotionUtils.java   
@NotNull
public static PotionData emptyPotionData() {
    return new PotionData(PotionType.WATER);
}
项目:Leveled-Storage    文件:PotionDataStorage.java   
public PotionDataStorage(PotionData potionData) {
    this.potionData = potionData;
}
项目:Leveled-Storage    文件:PotionDataStorage.java   
@Override
public PotionData getValue() {
    return potionData;
}
项目:Leveled-Storage    文件:PotionDataStorage.java   
@Override
public void setValue(PotionData value) {
    potionData = value;
}
项目:Leveled-Storage    文件:PotionDataStorage.java   
@Override
public StorageObject delegate() {
    return new PotionDataStorage(new PotionData(potionData.getType(), potionData.isExtended(), potionData.isUpgraded()));
}
项目:WorldGuardFix    文件:WorldGuardHelper.java   
public boolean isBlacklistedPotion(PotionData meta, World world) {
    return wg.getGlobalStateManager().get(world).blockPotions.contains(meta.getType().getEffectType());
}
项目:Pokkit    文件:PokkitPotionMeta.java   
@Override
public PotionData getBasePotionData() {
    return new PotionData(PotionType.AWKWARD);
}
项目:Pokkit    文件:PokkitPotionMeta.java   
@Override
public void setBasePotionData(PotionData data) {
    return;
}
项目:Ultra-Hardcore-1.8    文件:UhcDmg.java   
private String gPD(PotionData a, boolean b) {
    switch (a.getType()) {
    case AWKWARD:
        return "Awkward " + (b ? "II" : "I");
    case FIRE_RESISTANCE:
        return "Fire Fesistance " + (b ? "II" : "I");
    case INSTANT_DAMAGE:
        return "Instant Damage " + (b ? "II" : "I");
    case INSTANT_HEAL:
        return "Instant Heal " + (b ? "II" : "I");
    case INVISIBILITY:
        return "Invisibility " + (b ? "II" : "I");
    case JUMP:
        return "Jump " + (b ? "II" : "I");
    case LUCK:
        return "Luck " + (b ? "II" : "I");
    case MUNDANE:
        return "Mundane " + (b ? "II" : "I");
    case NIGHT_VISION:
        return "Night Vision " + (b ? "II" : "I");
    case POISON:
        return "poison " + (b ? "II" : "I");
    case REGEN:
        return "Regen " + (b ? "II" : "I");
    case SLOWNESS:
        return "Slowness " + (b ? "II" : "I");
    case SPEED:
        return "Speed " + (b ? "II" : "I");
    case STRENGTH:
        return "Strength " + (b ? "II" : "I");
    case THICK:
        return "Thick " + (b ? "II" : "I");
    case WATER:
        return "Water " + (b ? "II" : "I");
    case WATER_BREATHING:
        return "Water Breathing " + (b ? "II" : "I");
    case WEAKNESS:
        return "Weakness " + (b ? "II" : "I");
    case UNCRAFTABLE:
        return "Dragon Breath " + (b ? "II" : "I");
    default:
        return "Unknown 0x7";
    }
}
项目:BetonQuest    文件:PotionHandler.java   
public PotionData getBase() {
    return new PotionData(type, extended, upgraded);
}
项目:BetonQuest    文件:QuestItem.java   
/**
 * @return the base data of the potion
 */
public PotionData getBaseEffect() {
    return potion.getBase();
}
项目:SpigotSource    文件:CraftTippedArrow.java   
@Override
public void setBasePotionData(PotionData data) {
    Validate.notNull(data, "PotionData cannot be null");
    Validate.isTrue(data.getType() != PotionType.UNCRAFTABLE || !getHandle().h.isEmpty(), "Tipped Arrows must have at least 1 effect");
    getHandle().setType(CraftPotionUtil.fromBukkit(data));
}
项目:SpigotSource    文件:CraftTippedArrow.java   
@Override
public PotionData getBasePotionData() {
    return CraftPotionUtil.toBukkit(getHandle().getType());
}
项目:SpigotSource    文件:CraftAreaEffectCloud.java   
@Override
public void setBasePotionData(PotionData data) {
    Validate.notNull(data, "PotionData cannot be null");
    getHandle().setType(CraftPotionUtil.fromBukkit(data));
}