1.16.5 Plugin that helps you stripmine!

Discussion in 'Spigot Plugin Development' started by DenDennisCool, Jul 8, 2021.

  1. Hey guys, I coded my a plugin so that whenever you go near Diamond or Ancient Debris you hear a sound from where it came from. At any point you can switch a lever to disable the sound. I kinda just wanted to share this since I'm happy about my first java code, and maybe someone can comment on my code for improvements.

    Video showcasing how it works:


    Code (Java):

        @EventHandler
        public void interact(PlayerInteractEvent e) {
            if(e.getClickedBlock().toString().toLowerCase().contains("lever")) {
                sound = !sound;
            }
        }
       
        @EventHandler
        public void moveEvent(PlayerMoveEvent e) {
            Player player = e.getPlayer();
            Location loc = e.getPlayer().getLocation();
            World world = loc.getWorld();
            for (int x = -12; x <= 12; x++) {
                for (int z = -12; z <= 12; z++) {
                    for (int y = -7; y <= 7; y++) {
                       Material material = player.getLocation().add(x, y, z).getBlock().getType();
                        if (material == Material.DIAMOND_ORE || material == Material.ANCIENT_DEBRIS) {
                      //  if you want to reduce the spam noise  if (Math.floor(Math.random()*3) == 2) {
                          boolean lessThanFour = (Math.abs(loc.getX() - loc.add(x,y,z).getX()) < 4 && Math.abs(loc.getY() - loc.add(x,y,z).getY()) < 4 && Math.abs(loc.getZ() - loc.add(x,y,z).getZ()) < 4);
                          boolean lessThanEight = (Math.abs(loc.getX() - loc.add(x,y,z).getX()) < 8 && Math.abs(loc.getY() - loc.add(x,y,z).getY()) < 8 && Math.abs(loc.getZ() - loc.add(x,y,z).getZ()) < 8);
                            if(lessThanFour && sound) {
                                world.playSound(loc.add(x,y,z), Sound.BLOCK_NOTE_BLOCK_HARP, 10, 5);
                                lessThanEight = false;
                            } else
                                if(lessThanEight && sound) {
                                    world.playSound(loc.add(x,y,z), Sound.BLOCK_NOTE_BLOCK_HARP, 5, 1);
                               
                                } else
                                if(sound) {    
                                    world.playSound(loc.add(x,y,z), Sound.BLOCK_NOTE_BLOCK_BASS, 5, 1);
                                }
                     //  }    
                     }
                   }
                }
            }
        }
     
     
    • Like Like x 2
  2. Nice, I remember my first plugins. As for the suggestions, for the interact event listener. Instead of using toString and such, check the blocks type using the Material enum.
     
    • Informative Informative x 2
  3. Thats cool. Might it be better to use BlockBreakEvent? Doesnt really matter if its just for your personal server, but if its a public one with lots of players, I think PlayerMoveEvent might be a little heavy for that.
     
  4. This is quite cool! I hope you already published the resource?
     
  5. What do you mean by this?
     
  6. You can publish the plugin so anyone could download it.