|
@@ -1,5 +1,7 @@
|
|
|
package com.gmail.nossr50;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
import org.bukkit.Location;
|
|
|
import org.bukkit.Material;
|
|
|
import org.bukkit.block.Block;
|
|
@@ -7,6 +9,8 @@ import org.bukkit.entity.Player;
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
public class mcWoodCutting {
|
|
|
+ int w = 0;
|
|
|
+ private boolean isdone = false;
|
|
|
private static mcMMO plugin;
|
|
|
public mcWoodCutting(mcMMO instance) {
|
|
|
plugin = instance;
|
|
@@ -31,11 +35,62 @@ public class mcWoodCutting {
|
|
|
}
|
|
|
}
|
|
|
public void treeFeller(Block block){
|
|
|
- Location loc = block.getLocation();
|
|
|
int radius = 1;
|
|
|
- int typeid = 17;
|
|
|
- if(mcm.getInstance().isBlockAround(loc, radius, typeid)){
|
|
|
-
|
|
|
+ ArrayList<Block> blocklist = new ArrayList<Block>();
|
|
|
+ ArrayList<Block> toAdd = new ArrayList<Block>();
|
|
|
+ if(block != null)
|
|
|
+ blocklist.add(block);
|
|
|
+ while(isdone == false){
|
|
|
+ addBlocksToTreeFelling(blocklist, toAdd, radius);
|
|
|
+ }
|
|
|
+ //This needs to be a hashmap too!
|
|
|
+ isdone = false;
|
|
|
+ /*
|
|
|
+ * Add blocks from the temporary 'toAdd' array list into the 'treeFeller' array list
|
|
|
+ * We use this temporary list to prevent concurrent modification exceptions
|
|
|
+ */
|
|
|
+ for(Block x : toAdd){
|
|
|
+ if(!mcConfig.getInstance().isTreeFellerWatched(x))
|
|
|
+ mcConfig.getInstance().addTreeFeller(x);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void addBlocksToTreeFelling(ArrayList<Block> blocklist, ArrayList<Block> toAdd, Integer radius){
|
|
|
+ int u = 0;
|
|
|
+ for (Block x : blocklist){
|
|
|
+ u++;
|
|
|
+ if(toAdd.contains(x))
|
|
|
+ continue;
|
|
|
+ w = 0;
|
|
|
+ Location loc = x.getLocation();
|
|
|
+ int vx = x.getX();
|
|
|
+ int vy = x.getY();
|
|
|
+ int vz = x.getZ();
|
|
|
+ /*
|
|
|
+ * Run through the blocks around the broken block to see if they qualify to be 'felled'
|
|
|
+ */
|
|
|
+ for (int cx = -radius; cx <= radius; cx++) {
|
|
|
+ for (int cy = -radius; cy <= radius; cy++) {
|
|
|
+ for (int cz = -radius; cz <= radius; cz++) {
|
|
|
+ Block blocktarget = loc.getWorld().getBlockAt(vx + cx, vy + cy, vz + cz);
|
|
|
+ if (!blocklist.contains(blocktarget) && !toAdd.contains(blocktarget) && (blocktarget.getTypeId() == 17 || blocktarget.getTypeId() == 18)) {
|
|
|
+ toAdd.add(blocktarget);
|
|
|
+ w++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ * Add more blocks to blocklist so they can be 'felled'
|
|
|
+ */
|
|
|
+ for(Block xx : toAdd){
|
|
|
+ if(!blocklist.contains(xx))
|
|
|
+ blocklist.add(xx);
|
|
|
+ }
|
|
|
+ if(u >= blocklist.size()){
|
|
|
+ isdone = true;
|
|
|
+ } else {
|
|
|
+ isdone = false;
|
|
|
}
|
|
|
}
|
|
|
}
|