Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.kqleid.cutall;
- import java.util.*;
- import org.bukkit.*;
- import org.bukkit.block.*;
- import org.bukkit.entity.*;
- import org.bukkit.event.*;
- import org.bukkit.event.block.*;
- import org.bukkit.inventory.*;
- import org.bukkit.plugin.java.*;
- public class CutAll extends JavaPlugin implements Listener{
- public static boolean upper, creative;
- public void onEnable() {
- this.getServer().getPluginManager().registerEvents(this, this);
- saveDefaultConfig();
- upper = getConfig().getBoolean("onlyupper");
- creative = getConfig().getBoolean("creative");
- }
- @EventHandler
- public void onBreak(BlockBreakEvent e) {
- Player p = e.getPlayer();
- Location loc = e.getBlock().getLocation();
- ItemStack item = p.getInventory().getItemInMainHand();
- if(p.getGameMode() == GameMode.CREATIVE && !creative) return;
- if(item.getType().toString().contains("_AXE")) {
- if(isLog(loc)) {
- Deque<Block> queue = new ArrayDeque<Block>();
- queue.push(loc.getBlock());
- boolean bool = true;
- while (queue.size() != 0){
- Block b = queue.pop();
- Location l = b.getLocation();
- if(b.getType() == Material.AIR) continue;
- if(!bool) {
- b.getDrops().stream().map(x -> l.getWorld().dropItemNaturally(loc, x)).forEach(x -> x.teleport(loc));
- l.getBlock().setType(Material.AIR);
- }else{
- bool = false;
- }
- for(int x = -1; x <= 1; x++){
- for(int y = -1; y <= 1; y++){
- for(int z = -1; z <= 1; z++){
- if(x != 0 || y != 0 || z != 0){
- if(upper && ((loc.getBlockY() + y < loc.getBlockY()) && y == -1)) continue;
- Location tmp = new Location(l.getWorld(), x + l.getBlockX(), y + l.getBlockY(), z + l.getBlockZ());
- if(loc.getBlockX() == tmp.getBlockX() && loc.getBlockY() == tmp.getBlockY() && loc.getBlockZ() == tmp.getBlockZ()) continue;
- if(isLog(tmp)){
- queue.push(tmp.getBlock());
- }
- }
- }
- }
- }
- }
- }
- }
- }
- public static boolean isLog(Location loc) {
- if(loc.getBlock().getType() == Material.LOG || loc.getBlock().getType() == Material.LOG_2){
- return true;
- }else{
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement