Random Drops 1.0

Random Drops is a fun plugin that makes item drops after breaking a block random!

  1. floppyonyt
    Native Minecraft Version:
    1.15
    Tested Minecraft Versions:
    • 1.11
    • 1.12
    • 1.13
    • 1.14
    • 1.15
    Source Code:
    https://github.com/FloppyMC/Spigot-Plugins/wiki/Random-Drops
    Contributors:
    Inspired by CodedRed. All rights go to him!
    random drops desc logo.png RANDOM DROPS

    Random Drops is a fun plugin that makes item drops after you break a block random!
    It is my first plugin and it is also inspired from CodedRed so all rights go to him!


    -CONFIG
    Code (Text):

    reload:
      message:
        - "&b&oReloaded"
        - "&c&lRandomBlock!"
     
    blocks:
      DIRT:
        - DIRT
        - DIRT
        - DIRT
        - DIAMOND
        - FLINT
        - SAND
      SAND:
        - SAND
        - DIRT
      GRAVEL:
        - IRON_INGOT
    -COMMANDS

    /randomblock reload - Reloads the plugin


    -MEDIA


    FloppyMC: https://www.youtube.com/channel/UCkV6ozjIbWb6e1RAMnqF2QA/about?view_as=subscriber

    CodedRed: https://www.youtube.com/channel/UC_kPUW3XPrCCRT9a4Pnf1Tg


    -SOURCE CODE

    Code (Text):
    package me.Floppy.RandomBlock;[/B]

    import java.util.Random;

    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;

    import net.md_5.bungee.api.ChatColor;

    public class Main extends JavaPlugin implements Listener {
        @Override
        public void onEnable() {
            this.saveDefaultConfig();
            this.getServer().getPluginManager().registerEvents(this, this);
        }
       @Override
        public void onDisable( ) {

        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (label.equalsIgnoreCase("randomblock")) {
                if (!sender.hasPermission("randomblock.reload")) {
                    sender.sendMessage(ChatColor.RED + "You cannot run this command");
                    return true;
                }
                if (args.length == 0) {
                    // /randomblock
                    sender.sendMessage(ChatColor.RED + "Ussage: /randomblock reload");
                    return true;
                }
                if (args.length > 0) {
                    // /randomblock reload
                    if (args[0].equalsIgnoreCase("reload")) {
                        for (String msg : this.getConfig().getStringList("reload.message")) {
                            sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
                                msg));
                        }
                        this.reloadConfig();
                    }
                }
            }
            return false;
        }
        @EventHandler
        public void onBlockBreak(BlockBreakEvent event) {
            this.getConfig().getConfigurationSection("blocks").getKeys(false).forEach(key -> {
                // dirt
                if (key.equalsIgnoreCase(event.getBlock().getType().toString())) {
                    ItemStack[] items =  new ItemStack[this.getConfig().getStringList("blocks." + key).size()];
                    ItemStack item = null;
                    int position = 0;
                    Random r = new Random();
                    for (String i : this.getConfig().getStringList("blocks." + key)) {
                        // DIRT DIR
                        try {
                            item = new ItemStack(Material.matchMaterial(i), r.nextInt(16) + 1);
                        } catch(Exception e)  {
                            item = new ItemStack(Material.matchMaterial(key));
                        }
                        items[position] = item;
                        position++;
                    }
                    int num = r.nextInt(items.length);
                    event.setDropItems(false);
                    World world = event.getPlayer().getWorld();
                    world.dropItemNaturally(event.getBlock().getLocation(), items[num]);
                }
            });
        }
    }


    GreenProfit likes this.

Recent Reviews

  1. GreenProfit
    GreenProfit
    5/5,
    Version: 1.0
    Best drop randomizer for minecraf. Too bad there isnt a 1.16 version but if you dont own a server that runs on 1.16 you are all good