Solved Potion With Multiple Effects

Discussion in 'Plugin Development' started by Lawlzki, Apr 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline


  2. Offline


    If you want to do this in java coming off of say a command or event then you could do something like this.

    1. @EventHandler
    2. public void effect(PlayerJoinEvent event){
    3. Player player = event.getPlayer();
    4. player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 100, 1));
    5. player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1));
    6. player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 100, 1));
    7. }

    This would add night vision, blindness, and confusion to a player who joined for 100 ticks each.

    Doing it in game I think deals with item meta of a potion.
  3. Offline


  4. Offline


  5. Offline


    CreepahMC Well, when i put poMeta.addCustomEffect(PotionEffectType.SPEED, false)

    poMeta is the potion Meta

    It comes up with an error " The method addCustomEffect(PotionEffectType, boolean) is undefined for the type ItemStack"


    1. ItemMeta poMeta = po.getItemMeta();
    2. poMeta.setDisplayName(ChatColor.GOLD + "Swag" + ChatColor.DARK_PURPLE + "Potion");
    3. poMeta.addCustomEffect(PotionEffectType.SPEED, false);
    4. po.setItemMeta(poMeta);
    5. inv.addItem(po);
  6. Offline


    Try something like this:

    1. ItemStack buffedPotion = new ItemStack(Material.POTION);
    2. PotionMeta potionMeta = (PotionMeta) buffedPotion.getItemMeta();
    3. potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.CONFUSION, 100, 1), true);
    4. buffedPotion.setItemMeta(potionMeta);

    Adds confusion for 100 ticks. You can change the potion effect and time. The 1 is the potion data for an example would define the level (speed 1, 2, or 3).

    Can't test on a server so tell me if there's any errors.

    Change your meta line to this.

    1. poMeta.addCustomEffect(new PotionEffect(PotionEffectType.SPEED, 100, 1), true);

    Edit: Changed Confusion to Speed in code above.
  7. Offline


    Did you actually look at the explanation? Or the JavaDoc link I posted?
  8. Offline


    Sorry but I got it now thanks for the help though
  9. Offline


    What resolved it?
  10. Offline


    I Changed ItemMeta to PotionMeta at the beginning. Lol...
Thread Status:
Not open for further replies.

Share This Page