Advertisement
kqleid

Untitled

Jul 21st, 2019
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. package me.kqleid.cutall;
  2.  
  3. import java.util.*;
  4.  
  5. import org.bukkit.*;
  6. import org.bukkit.block.*;
  7. import org.bukkit.entity.*;
  8. import org.bukkit.event.*;
  9. import org.bukkit.event.block.*;
  10. import org.bukkit.inventory.*;
  11. import org.bukkit.plugin.java.*;
  12.  
  13. public class CutAll extends JavaPlugin implements Listener{
  14.     public static boolean upper, creative;
  15.  
  16.     public void onEnable() {
  17.         this.getServer().getPluginManager().registerEvents(this, this);
  18.         saveDefaultConfig();
  19.  
  20.         upper = getConfig().getBoolean("onlyupper");
  21.         creative = getConfig().getBoolean("creative");
  22.     }
  23.  
  24.     @EventHandler
  25.     public void onBreak(BlockBreakEvent e) {
  26.         Player p = e.getPlayer();
  27.         Location loc = e.getBlock().getLocation();
  28.         ItemStack item = p.getInventory().getItemInMainHand();
  29.  
  30.         if(p.getGameMode() == GameMode.CREATIVE && !creative) return;
  31.  
  32.         if(item.getType().toString().contains("_AXE")) {
  33.             if(isLog(loc)) {
  34.                 Deque<Block> queue = new ArrayDeque<Block>();
  35.                 queue.push(loc.getBlock());
  36.  
  37.                 boolean bool = true;
  38.  
  39.                 while (queue.size() != 0){
  40.                     Block b = queue.pop();
  41.                     Location l = b.getLocation();
  42.  
  43.                     if(b.getType() == Material.AIR) continue;
  44.  
  45.                     if(!bool) {
  46.                         b.getDrops().stream().map(x -> l.getWorld().dropItemNaturally(loc, x)).forEach(x -> x.teleport(loc));
  47.                         l.getBlock().setType(Material.AIR);
  48.                     }else{
  49.                         bool = false;
  50.                     }
  51.  
  52.                     for(int x = -1; x <= 1; x++){
  53.                         for(int y = -1; y <= 1; y++){
  54.                             for(int z = -1; z <= 1; z++){
  55.                                 if(x != 0 || y != 0 || z != 0){
  56.                                     if(upper && ((loc.getBlockY() + y < loc.getBlockY()) && y == -1)) continue;
  57.  
  58.                                     Location tmp = new Location(l.getWorld(), x + l.getBlockX(), y + l.getBlockY(), z + l.getBlockZ());
  59.  
  60.                                     if(loc.getBlockX() == tmp.getBlockX() && loc.getBlockY() == tmp.getBlockY() && loc.getBlockZ() == tmp.getBlockZ()) continue;
  61.  
  62.                                     if(isLog(tmp)){
  63.                                         queue.push(tmp.getBlock());
  64.                                     }
  65.                                 }
  66.                             }
  67.                         }
  68.                     }
  69.                 }
  70.             }
  71.         }
  72.     }
  73.  
  74.     public static boolean isLog(Location loc) {
  75.         if(loc.getBlock().getType() == Material.LOG || loc.getBlock().getType() == Material.LOG_2){
  76.             return true;
  77.         }else{
  78.             return false;
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement