Crafting mundane potion & event handler

Discussion in 'Plugin Development' started by blizzblang, Feb 5, 2013.

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

    blizzblang

    Code:
    package blizzblang.com;
     
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.List;
     
    import net.minecraft.server.v1_4_R1.Item;
     
    import org.bukkit.Material;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.ThrownPotion;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PotionSplashEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapelessRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.material.MaterialData;
    import org.bukkit.metadata.MetadataValue;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.Potion;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionType;
     
    public class main extends JavaPlugin implements Listener{
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
     
            ItemStack potion = new ItemStack(373,1);
            potion.setDurability((short) 16431);
            final ShapelessRecipe glass = new ShapelessRecipe(potion);
                glass.addIngredient(Material.MILK_BUCKET);
                glass.addIngredient(Material.GLASS_BOTTLE);
                getServer().addRecipe(glass);
        }
       
        public void onDisable(){
           
        }
        @EventHandler
        public void potionsplash(PotionSplashEvent event) {
            getLogger().info(event.getPotion().getType().getName());
            if(event.getPotion().getType().getName() == "Sparkling potion") // this part needs to be fixed also
            {
                Collection<LivingEntity> affected = event.getAffectedEntities();
                for(LivingEntity ent : affected)
                {
                    for (PotionEffect effect : ent.getActivePotionEffects())
                    {
                        ent.removePotionEffect(effect.getType());
                    }
               
                }
            }
        }
    }
    
    So the goal of this plugin is to create a 'splash potion of milk'. So i have a crafting recipie to create a mundane splash potion, or just an unused one. Ive tried multiple methods, but they always come out as just water bottles. Another issue is that My event handler doesn't seem to work either, the logger doesn't display the potion name like it should. I appreciate any help or tips. Thanks in advance :).
     
  2. Offline

    valon750

    blizzblang

    For crafting the mundane splash potion, you'll be needing this :)

    Code:
    new ItemStack(Material.POTION, 1, (short)16384);
    This is what I have for when I'm only using a single .java file:

    Code:
            getLogger().info("Plugins Enabled");
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            saveConfig();
    Obviously you don't need everything if you're not using a config :)
     
  3. Offline

    blizzblang

    So i got the crafting recipe to work, but when the mundane potion hits the ground, the server doesn't call the PotionSplashEvent for it. It works for any other splash potion though.
     
Thread Status:
Not open for further replies.

Share This Page