How do I make this plugin

Discussion in 'Plugin Development' started by Masterrboi, Mar 10, 2021.

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

    Masterrboi

    Hello, I wish to make a plugin in Minecraft java 1.16.5. The plugin is whenever you break a block, you get a random enchant on my armor or my tools. Does anybody know how to make this, because I am very new to Java coding, I have been doing this for a week or so, and I can't seem to get how I would do this.
     
  2. Offline

    Kars

  3. Offline

    Masterrboi

    Yes, but I how do I add the enchantment. Here is my code.

    Code:
    package com.Master.Wolf;
    
    import java.util.Random;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.CaveSpider;
    import org.bukkit.entity.Creeper;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.inventory.EquipmentSlot;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.minecraft.server.v1_16_R3.Enchantment;
    import net.minecraft.server.v1_16_R3.Enchantments;
    import net.minecraft.server.v1_16_R3.PlayerInventory;
    
    
    public class WolfPig extends JavaPlugin implements Listener{
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this,this);
        }
    
        public void onDisable(){
       
        }
        @EventHandler
        public void pigDropEvent(BlockBreakEvent event){
            Block b = event.getBlock();
            class PoolItem {
                private final Material material;
                private final int amount;
    
                public PoolItem(Material material, int amount){
                this.material = material;
                this.amount = amount;
                }
    
                public PoolItem(Enchantment silkTouch) {
                   
                }
    
                public Material getMaterial() {
                return this.material;
                }
    
                public int getAmount() {
                return this.amount;
                }
                }
           
                if (b instanceof Creeper) {
    
                PoolItem[] itemPool = new PoolItem[]{
                new PoolItem(Enchantments.CHANNELING),
                new PoolItem(Enchantments.DAMAGE_ALL),
                new PoolItem(Enchantments.DAMAGE_ARTHROPODS),
                new PoolItem(Enchantments.DAMAGE_UNDEAD),
                new PoolItem(Enchantments.DEPTH_STRIDER),
                new PoolItem(Enchantments.DIG_SPEED),
                new PoolItem(Enchantments.DURABILITY),
                new PoolItem(Enchantments.FIRE_ASPECT),
                new PoolItem(Enchantments.FROST_WALKER),
                new PoolItem(Enchantments.IMPALING),
                new PoolItem(Enchantments.KNOCKBACK),
                new PoolItem(Enchantments.LOOT_BONUS_BLOCKS),
                new PoolItem(Enchantments.LOOT_BONUS_MOBS),
                new PoolItem(Enchantments.LOYALTY),
                new PoolItem(Enchantments.LUCK),
                new PoolItem(Enchantments.LURE),
                new PoolItem(Enchantments.MENDING),
                new PoolItem(Enchantments.MULTISHOT),
                new PoolItem(Enchantments.OXYGEN),
                new PoolItem(Enchantments.PIERCING),
                new PoolItem(Enchantments.PROTECTION_ENVIRONMENTAL),
                new PoolItem(Enchantments.PROTECTION_EXPLOSIONS),
                new PoolItem(Enchantments.PROTECTION_FALL),
                new PoolItem(Enchantments.PROTECTION_FIRE),
                new PoolItem(Enchantments.PROTECTION_PROJECTILE),
                new PoolItem(Enchantments.QUICK_CHARGE),
                new PoolItem(Enchantments.RIPTIDE),
                new PoolItem(Enchantments.SOUL_SPEED),
                new PoolItem(Enchantments.THORNS),
                new PoolItem(Enchantments.SWEEPING),
                new PoolItem(Enchantments.WATER_WORKER),
               
                };
    
                Random rdm = new Random();
    
                PoolItem randomPoolItem = itemPool[rdm.nextInt(itemPool.length)];
    
                ItemStack itemToDrop = new ItemStack(randomPoolItem.getMaterial(), randomPoolItem.getAmount());
    
                event.getPlayer().getInventory().getItem(1).addEnchantments(randomPoolItem);
                }
           
       
        }
    
    }
     
    Last edited by a moderator: Mar 11, 2021
  4. Online

    timtower Administrator Administrator Moderator

  5. Offline

    Kars

    There's literally a link for that in my last reply.
     
  6. Offline

    davidclue

    He is the first person I've seen that has 1-week experience with Java and already using NMS.
     
  7. Offline

    KarimAKL

    But he probably should not use it.
     
  8. Offline

    Strahan

    Definitely not. NMS has it's place, and this is not it. Sounds like a case of just choosing the wrong import then rolling with it most likely.
     
    KarimAKL likes this.
  9. Online

    timtower Administrator Administrator Moderator

    @Masterrboi Removed 2 additional threads on this from you.
    Don't make multiple threads for the same thing.
     
  10. Offline

    Masterrboi

    I still do not understand how to add a Random enchant to a Random Item in your inventory.
     
  11. Offline

    Kars

    Have a list of items and enchantments and select them using the random number generator.
     
  12. Offline

    Masterrboi

    So do I add every single item in the game into a list?
     
  13. Online

    timtower Administrator Administrator Moderator

    Items that you want to add: yes
     
Thread Status:
Not open for further replies.

Share This Page