本文整理汇总了Java中org.bukkit.potion.Potion.toItemStack方法的典型用法代码示例。如果您正苦于以下问题:Java Potion.toItemStack方法的具体用法?Java Potion.toItemStack怎么用?Java Potion.toItemStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.potion.Potion
的用法示例。
在下文中一共展示了Potion.toItemStack方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPotion
import org.bukkit.potion.Potion; //导入方法依赖的package包/类
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;
}
示例2: onPlayerDeath
import org.bukkit.potion.Potion; //导入方法依赖的package包/类
/**
* 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());
}
}
示例3: setPotion
import org.bukkit.potion.Potion; //导入方法依赖的package包/类
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
ItemStack chestItem) {
// Try some backwards compatibility with new 1.9 schematics
Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
if (cont != null) {
if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
StringTag stringTag = ((StringTag)contents.get("Potion"));
if (stringTag != null) {
String tag = stringTag.getValue().replace("minecraft:", "");
PotionType type = null;
boolean strong = tag.contains("strong");
boolean _long = tag.contains("long");
//Bukkit.getLogger().info("tag = " + tag);
if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
type = PotionType.FIRE_RESISTANCE;
}else if(tag.equals("harming") || tag.equals("strong_harming")){
type = PotionType.INSTANT_DAMAGE;
}else if(tag.equals("healing") || tag.equals("strong_healing")){
type = PotionType.INSTANT_HEAL;
}else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
type = PotionType.INVISIBILITY;
}else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
type = PotionType.JUMP;
}else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
type = PotionType.NIGHT_VISION;
}else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
type = PotionType.POISON;
}else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
type = PotionType.REGEN;
}else if(tag.equals("slowness") || tag.equals("long_slowness")){
type = PotionType.SLOWNESS;
}else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
type = PotionType.SPEED;
}else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
type = PotionType.STRENGTH;
}else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
type = PotionType.WATER_BREATHING;
}else if(tag.equals("water")){
type = PotionType.WATER;
}else if(tag.equals("weakness") || tag.equals("long_weakness")){
type = PotionType.WEAKNESS;
}else{
return chestItem;
}
Potion potion = new Potion(type);
potion.setHasExtendedDuration(_long);
potion.setLevel(strong ? 2 : 1);
chestItem = potion.toItemStack(chestItem.getAmount());
}
}
}
return chestItem;
}
示例4: setPotion
import org.bukkit.potion.Potion; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
ItemStack chestItem) {
// Try some backwards compatibility with new 1.9 schematics
Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) itemTags).getValue().get("tag").getValue();
StringTag stringTag = ((StringTag)contents.get("Potion"));
if (stringTag != null) {
String tag = stringTag.getValue().replace("minecraft:", "");
PotionType type = null;
boolean strong = tag.contains("strong");
boolean _long = tag.contains("long");
//Bukkit.getLogger().info("tag = " + tag);
if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
type = PotionType.FIRE_RESISTANCE;
}else if(tag.equals("harming") || tag.equals("strong_harming")){
type = PotionType.INSTANT_DAMAGE;
}else if(tag.equals("healing") || tag.equals("strong_healing")){
type = PotionType.INSTANT_HEAL;
}else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
type = PotionType.INVISIBILITY;
}else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
type = PotionType.JUMP;
}else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
type = PotionType.NIGHT_VISION;
}else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
type = PotionType.POISON;
}else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
type = PotionType.REGEN;
}else if(tag.equals("slowness") || tag.equals("long_slowness")){
type = PotionType.SLOWNESS;
}else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
type = PotionType.SPEED;
}else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
type = PotionType.STRENGTH;
}else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
type = PotionType.WATER_BREATHING;
}else if(tag.equals("water")){
type = PotionType.WATER;
}else if(tag.equals("weakness") || tag.equals("long_weakness")){
type = PotionType.WEAKNESS;
}else{
return chestItem;
}
Potion potion = new Potion(type);
potion.setHasExtendedDuration(_long);
potion.setLevel(strong ? 2 : 1);
chestItem = potion.toItemStack(chestItem.getAmount());
}
return chestItem;
}
示例5: parseItemStack
import org.bukkit.potion.Potion; //导入方法依赖的package包/类
@Nullable
private ItemStack parseItemStack() throws InvalidItemStackStringException {
_buffer.setLength(0);
if (current() == ',')
next();
if (!canParse())
return null;
skipEmpty();
ItemStack stack;
Material material;
short data = 0;
int amount = 1;
Potion potion;
List<ItemMetaValue> metaObjects = new ArrayList<>(15);
String rawMaterial = parseMaterial();
if (rawMaterial.isEmpty())
return null;
material = Converters.MATERIAL.convert(rawMaterial);
if (material == null) {
throw new InvalidItemStackStringException(_itemString);
}
if (current() == ':') {
next();
data = parseData();
}
if (current() == ';') {
next();
amount = parseAmount();
}
if (current() == '{') {
next();
parseMeta(metaObjects);
}
// handle special cases
if (material == Material.POTION && (potion = Converters.POTION.convert(data)) != null) {
stack = potion.toItemStack(amount);
}
else {
// set stack data
stack = new ItemStack(material, amount);
stack.setDurability(data);
}
for (ItemMetaValue meta : metaObjects) {
IItemMetaHandler handler = Nucleus.getItemMetaHandlers().getHandler(meta.getName());
if (handler == null)
continue;
handler.apply(stack, meta);
}
return stack;
}