mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 15:48:35 +00:00
Abstracted super pickaxe mode/tools and changed commands to /tree, /info, /none, /single, /area, and /recur.
This commit is contained in:
82
src/com/sk89q/worldedit/superpickaxe/AreaPickaxe.java
Normal file
82
src/com/sk89q/worldedit/superpickaxe/AreaPickaxe.java
Normal file
@ -0,0 +1,82 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.superpickaxe;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
|
||||
/**
|
||||
* A super pickaxe mode that will remove blocks in an area.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class AreaPickaxe implements SuperPickaxeMode {
|
||||
private static final BaseBlock air = new BaseBlock(0);
|
||||
private int range;
|
||||
|
||||
public AreaPickaxe(int range) {
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
||||
LocalPlayer player, LocalSession session, LocalWorld world,
|
||||
Vector clicked) {
|
||||
int ox = clicked.getBlockX();
|
||||
int oy = clicked.getBlockY();
|
||||
int oz = clicked.getBlockZ();
|
||||
int initialType = server.getBlockType(world, clicked);
|
||||
|
||||
if (initialType == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
EditSession editSession = new EditSession(server, world,
|
||||
session.getBlockChangeLimit());
|
||||
|
||||
try {
|
||||
for (int x = ox - range; x <= ox + range; x++) {
|
||||
for (int y = oy - range; y <= oy + range; y++) {
|
||||
for (int z = oz - range; z <= oz + range; z++) {
|
||||
Vector pos = new Vector(x, y, z);
|
||||
if (server.getBlockType(world, pos) == initialType) {
|
||||
if (config.superPickaxeManyDrop) {
|
||||
server.simulateBlockMine(world, pos);
|
||||
}
|
||||
|
||||
editSession.setBlock(pos, air);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
52
src/com/sk89q/worldedit/superpickaxe/QueryTool.java
Normal file
52
src/com/sk89q/worldedit/superpickaxe/QueryTool.java
Normal file
@ -0,0 +1,52 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.superpickaxe;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.*;
|
||||
|
||||
/**
|
||||
* Plants a tree.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class QueryTool implements SuperPickaxeMode {
|
||||
|
||||
@Override
|
||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
||||
LocalPlayer player, LocalSession session, LocalWorld world,
|
||||
Vector clicked) {
|
||||
BaseBlock block = (new EditSession(server, world, 0)).rawGetBlock(clicked);
|
||||
|
||||
player.print("\u00A79@" + clicked + ": " + "\u00A7e"
|
||||
+ "Type: " + block.getID() + "\u00A77" + " ("
|
||||
+ BlockType.fromID(block.getID()).getName() + ") "
|
||||
+ "\u00A7f"
|
||||
+ "[" + block.getData() + "]");
|
||||
|
||||
if (block instanceof MobSpawnerBlock) {
|
||||
player.printRaw("\u00A7e" + "Mob Type: "
|
||||
+ ((MobSpawnerBlock)block).getMobType());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
119
src/com/sk89q/worldedit/superpickaxe/RecursivePickaxe.java
Normal file
119
src/com/sk89q/worldedit/superpickaxe/RecursivePickaxe.java
Normal file
@ -0,0 +1,119 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.superpickaxe;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
|
||||
/**
|
||||
* A pickaxe mode that recursively finds adjacent blocks within range of
|
||||
* an initial block and of the same type.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class RecursivePickaxe implements SuperPickaxeMode {
|
||||
private static final BaseBlock air = new BaseBlock(0);
|
||||
private int range;
|
||||
|
||||
public RecursivePickaxe(int range) {
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
||||
LocalPlayer player, LocalSession session, LocalWorld world,
|
||||
Vector clicked) {
|
||||
int initialType = server.getBlockType(world, clicked);
|
||||
|
||||
if (initialType == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
EditSession editSession = new EditSession(server, world,
|
||||
session.getBlockChangeLimit());
|
||||
|
||||
try {
|
||||
recurse(server, editSession, world, clicked.toBlockVector(),
|
||||
clicked, range, initialType, new HashSet<BlockVector>(),
|
||||
config.superPickaxeManyDrop);
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method.
|
||||
*
|
||||
* @param server
|
||||
* @param superPickaxeManyDrop
|
||||
* @param world
|
||||
* @param pos
|
||||
* @param origin
|
||||
* @param size
|
||||
* @param initialType
|
||||
* @param visited
|
||||
*/
|
||||
private void recurse(ServerInterface server, EditSession editSession,
|
||||
LocalWorld world, BlockVector pos,
|
||||
Vector origin, int size, int initialType,
|
||||
Set<BlockVector> visited, boolean drop)
|
||||
throws MaxChangedBlocksException {
|
||||
|
||||
if (origin.distance(pos) > size || visited.contains(pos)) {
|
||||
return;
|
||||
}
|
||||
|
||||
visited.add(pos);
|
||||
|
||||
if (editSession.getBlock(pos).getID() == initialType) {
|
||||
if (drop) {
|
||||
server.simulateBlockMine(world, pos);
|
||||
}
|
||||
editSession.setBlock(pos, air);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
recurse(server, editSession, world, pos.add(1, 0, 0).toBlockVector(),
|
||||
origin, size, initialType, visited, drop);
|
||||
recurse(server, editSession, world, pos.add(-1, 0, 0).toBlockVector(),
|
||||
origin, size, initialType, visited, drop);
|
||||
recurse(server, editSession, world, pos.add(0, 0, 1).toBlockVector(),
|
||||
origin, size, initialType, visited, drop);
|
||||
recurse(server, editSession, world, pos.add(0, 0, -1).toBlockVector(),
|
||||
origin, size, initialType, visited, drop);
|
||||
recurse(server, editSession, world, pos.add(0, 1, 0).toBlockVector(),
|
||||
origin, size, initialType, visited, drop);
|
||||
recurse(server, editSession, world, pos.add(0, -1, 0).toBlockVector(),
|
||||
origin, size, initialType, visited, drop);
|
||||
}
|
||||
|
||||
}
|
52
src/com/sk89q/worldedit/superpickaxe/SinglePickaxe.java
Normal file
52
src/com/sk89q/worldedit/superpickaxe/SinglePickaxe.java
Normal file
@ -0,0 +1,52 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.superpickaxe;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
|
||||
/**
|
||||
* A super pickaxe mode that removes one block.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class SinglePickaxe implements SuperPickaxeMode {
|
||||
@Override
|
||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
||||
LocalPlayer player, LocalSession session, LocalWorld world,
|
||||
Vector clicked) {
|
||||
|
||||
if (server.getBlockType(world, clicked) == BlockID.BEDROCK
|
||||
&& !player.canDestroyBedrock()) {
|
||||
return true;
|
||||
} else if (server.getBlockType(world, clicked) == BlockID.TNT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config.superPickaxeDrop) {
|
||||
server.simulateBlockMine(world, clicked);
|
||||
}
|
||||
|
||||
server.setBlockType(world, clicked, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
42
src/com/sk89q/worldedit/superpickaxe/SuperPickaxeMode.java
Normal file
42
src/com/sk89q/worldedit/superpickaxe/SuperPickaxeMode.java
Normal file
@ -0,0 +1,42 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.superpickaxe;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
/**
|
||||
* Represents a super pickaxe mode.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public interface SuperPickaxeMode {
|
||||
/**
|
||||
* Perform the action. Should return true to deny the default
|
||||
* action.
|
||||
*
|
||||
* @param player
|
||||
* @param session
|
||||
* @param clicked
|
||||
* @return true to deny
|
||||
*/
|
||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
||||
LocalPlayer player, LocalSession session, LocalWorld world,
|
||||
Vector clicked);
|
||||
}
|
49
src/com/sk89q/worldedit/superpickaxe/TreePlanter.java
Normal file
49
src/com/sk89q/worldedit/superpickaxe/TreePlanter.java
Normal file
@ -0,0 +1,49 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.superpickaxe;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
/**
|
||||
* Plants a tree.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class TreePlanter implements SuperPickaxeMode {
|
||||
|
||||
@Override
|
||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
||||
LocalPlayer player, LocalSession session, LocalWorld world,
|
||||
Vector clicked) {
|
||||
EditSession editSession =
|
||||
new EditSession(server, world, session.getBlockChangeLimit());
|
||||
|
||||
try {
|
||||
if (!server.generateTree(editSession, player.getWorld(), clicked)) {
|
||||
player.printError("Notch won't let you put a tree there.");
|
||||
}
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user