当前位置: 首页>>代码示例>>Java>>正文


Java PotionData类代码示例

本文整理汇总了Java中org.bukkit.potion.PotionData的典型用法代码示例。如果您正苦于以下问题:Java PotionData类的具体用法?Java PotionData怎么用?Java PotionData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PotionData类属于org.bukkit.potion包,在下文中一共展示了PotionData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromPotionData

import org.bukkit.potion.PotionData; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:Syst3ms,项目名称:QuarSK,代码行数:27,代码来源:PotionUtils.java

示例2: addPotion

import org.bukkit.potion.PotionData; //导入依赖的package包/类
/**
 * 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()));
    }
}
 
开发者ID:redwallhp,项目名称:AthenaGM,代码行数:25,代码来源:MapInfoKitItem.java

示例3: handlePotions

import org.bukkit.potion.PotionData; //导入依赖的package包/类
/** 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() );
}
 
开发者ID:Gamealition,项目名称:SignShopExport,代码行数:25,代码来源:JsonItemMeta.java

示例4: potionMain

import org.bukkit.potion.PotionData; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:SupaHam,项目名称:SupaCommons,代码行数:27,代码来源:ItemBuilder.java

示例5: checkBase

import org.bukkit.potion.PotionData; //导入依赖的package包/类
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;
	}
}
 
开发者ID:Co0sh,项目名称:BetonQuest,代码行数:20,代码来源:PotionHandler.java

示例6: spawnArrow

import org.bukkit.potion.PotionData; //导入依赖的package包/类
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();
}
 
开发者ID:bergerkiller,项目名称:SpigotSource,代码行数:21,代码来源:CraftWorld.java

示例7: toBukkit

import org.bukkit.potion.PotionData; //导入依赖的package包/类
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);
}
 
开发者ID:bergerkiller,项目名称:SpigotSource,代码行数:23,代码来源:CraftPotionUtil.java

示例8: splashPotion

import org.bukkit.potion.PotionData; //导入依赖的package包/类
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;
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:8,代码来源:GuiUtil.java

示例9: processMeta

import org.bukkit.potion.PotionData; //导入依赖的package包/类
@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);
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:13,代码来源:PotionCustomItem.java

示例10: parseItem

import org.bukkit.potion.PotionData; //导入依赖的package包/类
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;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:51,代码来源:GlobalItemParser.java

示例11: itemWithTypedMetaMatches

import org.bukkit.potion.PotionData; //导入依赖的package包/类
@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);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:ItemMatcherTest.java

示例12: effects

import org.bukkit.potion.PotionData; //导入依赖的package包/类
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();
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:11,代码来源:PotionUtils.java

示例13: vanillaBrews

import org.bukkit.potion.PotionData; //导入依赖的package包/类
@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)));
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:PotionClassificationTest.java

示例14: read

import org.bukkit.potion.PotionData; //导入依赖的package包/类
@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));
}
 
开发者ID:OrigamiDream,项目名称:Leveled-Storage,代码行数:9,代码来源:PotionDataStorage.java

示例15: getPotion

import org.bukkit.potion.PotionData; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:GameBoxx,项目名称:GameBoxx,代码行数:15,代码来源:EItem.java


注:本文中的org.bukkit.potion.PotionData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。