3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-26 02:50:06 +01:00

Removed and reimplemented mrapple's selection at a distance. It is now a brush tool, meaning it can be bound as other tools can and it subject to Nichts' /range command, so you can select points in midair.

Dieser Commit ist enthalten in:
Wizjany 2011-08-06 10:22:02 -04:00
Ursprung 5ac943368a
Commit 02e24ed824
8 geänderte Dateien mit 212 neuen und 59 gelöschten Zeilen

Datei anzeigen

@ -294,6 +294,9 @@ commands:
none: none:
description: Turn off all superpickaxe alternate modes description: Turn off all superpickaxe alternate modes
usage: /<command> usage: /<command>
farwand:
description: Wand tool at a distance
usage: /<command>
tree: tree:
description: Tree generator tool description: Tree generator tool
usage: /<command> [type] usage: /<command> [type]

Datei anzeigen

@ -879,19 +879,17 @@ public class WorldEdit {
} }
/** /**
* Called on left click (not on a block). * Called on arm swing.
* *
* @param player * @param player
* @return * @return
*/ */
public boolean handleLeftClick(LocalPlayer player) { public boolean handleArmSwing(LocalPlayer player) {
LocalSession session = getSession(player); LocalSession session = getSession(player);
WorldVector pos = player.getSolidBlockTrace(config.navigationWandMaxDistance); if (player.getItemInHand() == config.navigationWand
if (player.getItemInHand() == config.wandItem) {
return selectFirstPoint(player, session, pos);
} else if (player.getItemInHand() == config.navigationWand
&& config.navigationWandMaxDistance > 0 && config.navigationWandMaxDistance > 0
&& player.hasPermission("worldedit.navigation.jumpto")) { && player.hasPermission("worldedit.navigation.jumpto")) {
WorldVector pos = player.getSolidBlockTrace(config.navigationWandMaxDistance);
if (pos != null) { if (pos != null) {
player.findFreePosition(pos); player.findFreePosition(pos);
} else { } else {
@ -899,6 +897,13 @@ public class WorldEdit {
} }
} }
Tool tool = session.getTool(player.getItemInHand());
if (tool != null && tool instanceof DoubleActionTraceTool) {
if (tool.canUse(player)) {
((DoubleActionTraceTool) tool).actSecondary(server, config, player, session);
return true;
}
}
return false; return false;
} }
@ -918,16 +923,13 @@ public class WorldEdit {
if (!player.passThroughForwardWall(40)) { if (!player.passThroughForwardWall(40)) {
player.printError("Nothing to pass through!"); player.printError("Nothing to pass through!");
} }
} else if (player.getItemInHand() == config.wandItem) {
WorldVector pos = player.getSolidBlockTrace(config.navigationWandMaxDistance);
return selectSecondPoint(player, session, pos);
} }
Tool tool = session.getTool(player.getItemInHand()); Tool tool = session.getTool(player.getItemInHand());
if (tool != null && tool instanceof TraceTool) { if (tool != null && tool instanceof TraceTool) {
if (tool.canUse(player)) { if (tool.canUse(player)) {
((TraceTool)tool).act(server, config, player, session); ((TraceTool) tool).actPrimary(server, config, player, session);
return true; return true;
} }
} }
@ -943,10 +945,18 @@ public class WorldEdit {
* @return false if you want the action to go through * @return false if you want the action to go through
*/ */
public boolean handleBlockRightClick(LocalPlayer player, WorldVector clicked) { public boolean handleBlockRightClick(LocalPlayer player, WorldVector clicked) {
int itemInHand = player.getItemInHand();
LocalSession session = getSession(player); LocalSession session = getSession(player);
if (player.getItemInHand() == config.wandItem) { if (itemInHand == config.wandItem && session.isToolControlEnabled()
return selectSecondPoint(player, session, clicked); && player.hasPermission("worldedit.selection.pos")) {
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectSecondary(clicked)) {
selector.explainSecondarySelection(player, session, clicked);
}
return true;
} }
Tool tool = session.getTool(player.getItemInHand()); Tool tool = session.getTool(player.getItemInHand());
@ -972,7 +982,21 @@ public class WorldEdit {
LocalSession session = getSession(player); LocalSession session = getSession(player);
if (player.getItemInHand() == config.wandItem) { if (player.getItemInHand() == config.wandItem) {
return selectFirstPoint(player, session, clicked); if (session.isToolControlEnabled()
&& player.hasPermission("worldedit.selection.pos")) {
// Bug workaround
if (clicked.getBlockX() == 0 && clicked.getBlockY() == 0
&& clicked.getBlockZ() == 0) {
return false;
}
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectPrimary(clicked)) {
selector.explainPrimarySelection(player, session, clicked);
}
return true;
}
} else if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) { } else if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) {
if (session.getSuperPickaxe() != null) { if (session.getSuperPickaxe() != null) {
if (session.getSuperPickaxe().canUse(player)) { if (session.getSuperPickaxe().canUse(player)) {
@ -994,40 +1018,6 @@ public class WorldEdit {
return false; return false;
} }
private boolean selectFirstPoint(LocalPlayer player, LocalSession session, WorldVector clicked)
{
if (session.isToolControlEnabled()
&& player.hasPermission("worldedit.selection.pos")) {
// Bug workaround
if (clicked.getBlockX() == 0 && clicked.getBlockY() == 0
&& clicked.getBlockZ() == 0) {
return false;
}
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectPrimary(clicked)) {
selector.explainPrimarySelection(player, session, clicked);
}
return true;
}
return false;
}
private boolean selectSecondPoint(LocalPlayer player, LocalSession session, WorldVector clicked)
{
if (session.isToolControlEnabled()
&& player.hasPermission("worldedit.selection.pos")) {
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectSecondary(clicked)) {
selector.explainSecondarySelection(player, session, clicked);
}
return true;
}
return false;
}
/** /**
* *
* @param player * @param player

Datei anzeigen

@ -95,7 +95,13 @@ public class WorldEditPlayerListener extends PlayerListener {
if (plugin.getWorldEdit().handleBlockLeftClick(player, pos)) { if (plugin.getWorldEdit().handleBlockLeftClick(player, pos)) {
event.setCancelled(true); event.setCancelled(true);
} else if (plugin.getWorldEdit().handleLeftClick(wrapPlayer(event.getPlayer()))) { }
if (plugin.getWorldEdit().handleArmSwing(wrapPlayer(event.getPlayer()))) {
event.setCancelled(true);
}
} else if (event.getAction() == Action.LEFT_CLICK_AIR) {
if (plugin.getWorldEdit().handleArmSwing(wrapPlayer(event.getPlayer()))) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
@ -106,17 +112,15 @@ public class WorldEditPlayerListener extends PlayerListener {
if (plugin.getWorldEdit().handleBlockRightClick(player, pos)) { if (plugin.getWorldEdit().handleBlockRightClick(player, pos)) {
event.setCancelled(true); event.setCancelled(true);
} else if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) { }
if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (event.getAction() == Action.RIGHT_CLICK_AIR) { } else if (event.getAction() == Action.RIGHT_CLICK_AIR) {
if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) { if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (event.getAction() == Action.LEFT_CLICK_AIR) {
if (plugin.getWorldEdit().handleLeftClick(wrapPlayer(event.getPlayer()))) {
event.setCancelled(true);
}
} }
} }

Datei anzeigen

@ -176,4 +176,20 @@ public class ToolCommands {
player.print("Floating tree remover tool bound to " player.print("Floating tree remover tool bound to "
+ ItemType.toHeldName(player.getItemInHand()) + "."); + ItemType.toHeldName(player.getItemInHand()) + ".");
} }
@Command(
aliases = {"farwand"},
usage = "",
desc = "Wand at a distance tool",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.tool.farwand"})
public static void farwand(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setTool(player.getItemInHand(), new DistanceWand());
player.print("Far wand tool bound to " + ItemType.toHeldName(player.getItemInHand()) + ".");
}
} }

Datei anzeigen

@ -36,8 +36,8 @@ import com.sk89q.worldedit.tools.brushes.SphereBrush;
* @author sk89q * @author sk89q
*/ */
public class BrushTool implements TraceTool { public class BrushTool implements TraceTool {
private static int MAX_RANGE = 500; protected static int MAX_RANGE = 500;
private int range = -1; protected int range = -1;
private Mask mask = null; private Mask mask = null;
private Brush brush = new SphereBrush(); private Brush brush = new SphereBrush();
private Pattern material = new SingleBlockPattern(new BaseBlock(BlockID.COBBLESTONE)); private Pattern material = new SingleBlockPattern(new BaseBlock(BlockID.COBBLESTONE));
@ -164,7 +164,7 @@ public class BrushTool implements TraceTool {
* @param session * @param session
* @return true to deny * @return true to deny
*/ */
public boolean act(ServerInterface server, LocalConfiguration config, public boolean actPrimary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session) { LocalPlayer player, LocalSession session) {
WorldVector target = null; WorldVector target = null;
if (this.range > -1) { if (this.range > -1) {

Datei anzeigen

@ -0,0 +1,96 @@
// $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.tools;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.regions.RegionSelector;
/**
* A wand that can be used at a distance.
*
* @author wizjany
*/
public class DistanceWand extends BrushTool implements DoubleActionTraceTool {
public DistanceWand() {
super("worldedit.wand");
}
public boolean canUse(LocalPlayer player) {
return player.hasPermission("worldedit.wand");
}
public boolean actSecondary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session) {
if (session.isToolControlEnabled() && player.hasPermission("worldedit.selection.pos")) {
WorldVector target = getTarget(player);
if (target == null) return true;
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectPrimary(target)) {
selector.explainPrimarySelection(player, session, target);
}
return true;
}
return false;
}
@Override
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session) {
if (session.isToolControlEnabled() && player.hasPermission("worldedit.selection.pos")) {
WorldVector target = getTarget(player);
if (target == null) return true;
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectSecondary(target)) {
selector.explainSecondarySelection(player, session, target);
}
return true;
}
return false;
}
public WorldVector getTarget(LocalPlayer player) {
WorldVector target = null;
if (this.range > -1) {
target = player.getBlockTrace(getRange(), true);
} else {
target = player.getBlockTrace(MAX_RANGE);
}
if (target == null) {
player.printError("No block in sight!");
return null;
}
// Bug workaround
if (target.getBlockX() == 0 && target.getBlockY() == 0 && target.getBlockZ() == 0) {
return null;
}
return target;
}
}

Datei anzeigen

@ -0,0 +1,44 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.tools;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.WorldVector;
/**
* Represents a trace tool that also has a secondary/primary function.
*/
public interface DoubleActionTraceTool extends TraceTool {
/**
* Perform the secondary action. Should return true to deny the default
* action.
*
* @param server
* @param config
* @param player
* @param session
* @return true to deny
*/
public boolean actSecondary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session);
}

Datei anzeigen

@ -40,6 +40,6 @@ public interface TraceTool extends Tool {
* @param session * @param session
* @return true to deny * @return true to deny
*/ */
public boolean act(ServerInterface server, LocalConfiguration config, public boolean actPrimary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session); LocalPlayer player, LocalSession session);
} }