2014-04-03 02:08:50 +00:00
|
|
|
package com.sk89q.worldedit.command.tool;
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.object.mask.IdMask;
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalConfiguration;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.Vector;
|
2014-06-28 02:55:38 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
|
|
|
import com.sk89q.worldedit.extension.platform.Platform;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.function.block.BlockReplace;
|
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
|
|
|
import com.sk89q.worldedit.function.operation.Operations;
|
|
|
|
import com.sk89q.worldedit.function.visitor.RecursiveVisitor;
|
2014-06-28 02:55:38 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A pickaxe mode that recursively finds adjacent blocks within range of
|
|
|
|
* an initial block and of the same type.
|
|
|
|
*/
|
|
|
|
public class RecursivePickaxe implements BlockTool {
|
|
|
|
private double range;
|
|
|
|
|
|
|
|
public RecursivePickaxe(double range) {
|
|
|
|
this.range = range;
|
|
|
|
}
|
|
|
|
|
2014-06-28 02:55:38 +00:00
|
|
|
@Override
|
|
|
|
public boolean canUse(Actor player) {
|
2014-04-03 02:08:50 +00:00
|
|
|
return player.hasPermission("worldedit.superpickaxe.recursive");
|
|
|
|
}
|
|
|
|
|
2014-06-28 02:55:38 +00:00
|
|
|
@Override
|
|
|
|
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
2014-06-29 22:36:41 +00:00
|
|
|
World world = (World) clicked.getExtent();
|
2018-08-12 14:03:07 +00:00
|
|
|
final Vector pos = clicked.toVector();
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
EditSession editSession = session.createEditSession(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
BlockStateHolder block = editSession.getBlock(pos);
|
|
|
|
if (block.getBlockType().getMaterial().isAir()) {
|
2014-04-03 02:08:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
if (block.getBlockType() == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
|
2014-04-03 02:08:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-23 07:33:00 +00:00
|
|
|
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
final int radius = (int) range;
|
|
|
|
final BlockReplace replace = new BlockReplace(editSession, (editSession.nullBlock));
|
|
|
|
editSession.setMask((Mask) null);
|
|
|
|
RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius, editSession);
|
|
|
|
visitor.visit(pos);
|
|
|
|
Operations.completeBlindly(visitor);
|
|
|
|
|
|
|
|
editSession.flushQueue();
|
|
|
|
session.remember(editSession);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
public static Class<?> inject() {
|
|
|
|
return RecursivePickaxe.class;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|