Solved How to add potion effects to player if they are wearing a custom item?

Discussion in 'Plugin Development' started by superorigamis, May 6, 2020.

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

    superorigamis

    Code:
    package Recipe;
    import java.util.Arrays;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Recipe extends JavaPlugin{
        public void onEnable(){
            ItemStack hhh= new ItemStack(Material.DIAMOND_CHESTPLATE, 1);
            ItemMeta meta=hhh.getItemMeta();
            String display="SpeedPlate";
            meta.setDisplayName(display);
            meta.setLore(Arrays.asList("You get","speed 2"));
            hhh.setItemMeta(meta);
            ShapedRecipe recipe=new ShapedRecipe(hhh);
            recipe.shape("   ","   "," N ");
            recipe.setIngredient('N',Material.NETHER_STAR);
            Bukkit.getServer().addRecipe(recipe);
        }
    }
    
    I wrote this code to add custom item with displayname of SpeedPlate. I also added a custom recipe for it. I want to give player speed effect if player wears it. I am new to java so i would appretciate simple solutions.
     
  2. Offline

    KarimAKL

    @superorigamis Listen to events that could cause the player to equip/unequip the item, then add/remove the effect.
     
  3. Offline

    NiekZndt

    As far ias I know there sadly isn't a very simple way to add potion effects to armor however it is possible. This thread can help you with your problem:
    https://bukkit.org/threads/adding-effects-to-armor.325722/
    It can be cool to experiment with but for a starting project you could also add enchantments with:
    Code:
    hhh.addEnchant(Enchantment, arg1, arg2)
    Hope this can help you out
     
Thread Status:
Not open for further replies.

Share This Page