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


Java Potion类代码示例

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


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

示例1: setMainPotionEffect

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

示例2: onPlayerItemConsumeEvent

import org.bukkit.potion.Potion; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event)
{
	Player player = event.getPlayer();
	
	if (!WorldGuardUtils.hasBypass(player))
	{
		ItemMeta itemMeta = event.getItem().getItemMeta();
		if (itemMeta instanceof PotionMeta)
		{
			WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
		}
		else
		{
			Material material = event.getItem().getType();
			if (material == Material.MILK_BUCKET)
			{
				WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkMilk(player);
			}
		}
	}
}
 
开发者ID:isokissa3,项目名称:WorldGuardExtraFlagsPlugin,代码行数:23,代码来源:PlayerListener.java

示例3: LuckyPotion

import org.bukkit.potion.Potion; //导入依赖的package包/类
public void LuckyPotion(BlockBreakEvent event){
    Location loc = event.getBlock().getLocation();
    World world = loc.getWorld();
    ItemStack energyPotion = new ItemStack(Material.POTION, 1);
    PotionMeta energyPotionMeta = (PotionMeta) energyPotion.getItemMeta();
    energyPotionMeta.setDisplayName("§6Lucky Potion");
    List<String> lore = new ArrayList<String>();
    lore.add("§6"+ LuckyBlocksMainController.instance.language.getString("POTION_DURATION"));
    energyPotionMeta.setLore(lore);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.SPEED, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.ABSORPTION, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HEAL, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.JUMP, 20*60, 3), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 20*60, 3), true);
    energyPotion.setItemMeta(energyPotionMeta);
    Potion po = new Potion((byte) 8258);
    po.apply(energyPotion);
    world.dropItemNaturally(loc,energyPotion);
}
 
开发者ID:josegrobles,项目名称:LuckyBlocksBukkit,代码行数:23,代码来源:LuckyBlocksActionController.java

示例4: denyPotion

import org.bukkit.potion.Potion; //导入依赖的package包/类
public static boolean denyPotion(ItemStack result, Player p){
	List<String> Pots = RPConfig.getStringList("server-protection.deny-potions");
	if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))){
		String potname = "";
		if (RedProtect.get().version >= 190){
			PotionMeta pot = (PotionMeta) result.getItemMeta();
			potname = pot.getBasePotionData().getType().name();
		}
		if (RedProtect.get().version <= 180 && Potion.fromItemStack(result) != null){
			potname = Potion.fromItemStack(result).getType().name();
		}    		
		if (Pots.contains(potname)){    			
			RPLang.sendMessage(p, "playerlistener.denypotion");
			return true;
		}        	    		
	}
	return false;
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:19,代码来源:RPUtil.java

示例5: onConsumePotion

import org.bukkit.potion.Potion; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onConsumePotion(PlayerItemConsumeEvent event) {
    if (Settings.INDICATOR_ENABLE.getValue("potion")) {
        if (event.getItem().getType() == Material.POTION) {
            Potion potion = Potion.fromItemStack(event.getItem());
            if (potion != null) {
                this.showPotionHologram(event.getPlayer(), potion.getEffects());
            }
        } else if (event.getItem().getType() == Material.GOLDEN_APPLE) {
            String msg = Settings.INDICATOR_FORMAT.getValue("potion", "goldenapple");
            if (event.getItem().getDurability() == 1) {
                msg = Settings.INDICATOR_FORMAT.getValue("potion", "godapple");
            }
            Location l = event.getPlayer().getLocation().clone();
            l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("potion"));
            HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("potion"), true, msg.replace("%effect%", "Golden Apple"));
        }
    }
}
 
开发者ID:DSH105,项目名称:HoloAPI,代码行数:20,代码来源:IndicatorListener.java

示例6: onConvert

import org.bukkit.potion.Potion; //导入依赖的package包/类
@Nullable
@Override
protected Potion onConvert(@Nullable Object value) {

    if (value instanceof String) {
        value = TextUtils.parseShort((String) value, Short.MIN_VALUE);
        if (value == new Short(Short.MIN_VALUE))
            return null;
    }
    else if (value instanceof Number) {
        value = ((Number)value).shortValue();
    }

    if (value instanceof Short) {
        return new Potion((Short) value);
    }

    return null;
}
 
开发者ID:JCThePants,项目名称:NucleusFramework,代码行数:20,代码来源:PotionConverter.java

示例7: onPlayerConsume

import org.bukkit.potion.Potion; //导入依赖的package包/类
/**
 * Checks to see if the player is attempting to drink a potion, and checks
 * the potion to see if it is allowed.
 *
 * @param event The PlayerItemConsumeEvent involving the player.
 */
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerConsume(PlayerItemConsumeEvent event) {
    if (event.getItem().getType() != Material.POTION) {
        return;
    }
    // Check the type of potion in the player's hand
    Potion potion = Potion.fromItemStack(event.getItem());
    Collection<PotionEffect> effects = potion.getEffects();

    for (PotionEffect e : effects) {
        if (!(Util.canUsePotion(event.getPlayer(), e.getType()))) {
            // If we get here, we cancel this event and all is done.
            event.setCancelled(true);
            event.getPlayer().sendMessage(ChatColor.RED + "You cannot use that potion here!");
            Util.removeDisallowedEffects(event.getPlayer());
            return; // We don't need to check any more.
        }
    }
}
 
开发者ID:Tribalforge,项目名称:AntiPotionField,代码行数:26,代码来源:PlayerEventRegionsHandler.java

示例8: potionToNBTEffectsList

import org.bukkit.potion.Potion; //导入依赖的package包/类
public static NBTTagList potionToNBTEffectsList(ItemStack potion) {
	NBTTagCompound tag = getItemStackTag(potion);
	if (tag.hasKey("CustomPotionEffects")) {
		return tag.getList("CustomPotionEffects").clone();
	}
	// Fallback to default potion effect.
	Collection<PotionEffect> effects = Potion.fromItemStack(potion).getEffects();
	NBTTagList effectList = new NBTTagList();
	for (PotionEffect effect : effects) {
		NBTTagCompound effectTag = new NBTTagCompound();
		effectTag.setByte("Id", (byte)effect.getType().getId());
		effectTag.setByte("Amplifier", (byte)effect.getAmplifier());
		effectTag.setInt("Duration", effect.getDuration());
		effectList.add(effectTag);
	}
	return effectList;
}
 
开发者ID:goncalomb,项目名称:BKgLib,代码行数:18,代码来源:NBTUtils.java

示例9: 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;
}
 
开发者ID:WarzoneMC,项目名称:Warzone,代码行数:12,代码来源:ItemFactory.java

示例10: parseItem

import org.bukkit.potion.Potion; //导入依赖的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: setUp

import org.bukkit.potion.Potion; //导入依赖的package包/类
@Before
public void setUp() {
    CraftBukkitRuntime.load();
    if(Potion.getBrewer() == null) {
        Potion.setPotionBrewer(new CraftPotionBrewer());
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:PotionClassificationTest.java

示例12: 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());
    }
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:33,代码来源:DropMyEffectsModule.java

示例13: testValidity

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

示例14: onPlayerInteract

import org.bukkit.potion.Potion; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:SamaGames,项目名称:DoubleRunner,代码行数:12,代码来源:DoubleRunnerGameLoop.java

示例15: guessData

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


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