Added permission checks for tools on /use/, so now if you switch world or lose your permissions, you lose your tools.

This commit is contained in:
sk89q 2011-05-01 17:06:40 -07:00
parent 5755755c15
commit a18546d698
12 changed files with 87 additions and 17 deletions

View File

@ -455,7 +455,7 @@ public BrushTool getBrushTool(int item) throws InvalidToolBindException {
Tool tool = getTool(item);
if (tool == null || !(tool instanceof BrushTool)) {
tool = new BrushTool();
tool = new BrushTool("worldedit.brush.sphere");
setTool(item, tool);
}

View File

@ -834,8 +834,10 @@ public boolean handleRightClick(LocalPlayer player) {
Tool tool = session.getTool(player.getItemInHand());
if (tool != null && tool instanceof TraceTool) {
((TraceTool)tool).act(server, config, player, session);
return true;
if (tool.canUse(player)) {
((TraceTool)tool).act(server, config, player, session);
return true;
}
}
return false;
@ -866,8 +868,10 @@ public boolean handleBlockRightClick(LocalPlayer player, WorldVector clicked) {
Tool tool = session.getTool(player.getItemInHand());
if (tool != null && tool instanceof BlockTool) {
((BlockTool)tool).actPrimary(server, config, player, session, clicked);
return true;
if (tool.canUse(player)) {
((BlockTool)tool).actPrimary(server, config, player, session, clicked);
return true;
}
}
return false;
@ -901,16 +905,20 @@ public boolean handleBlockLeftClick(LocalPlayer player, WorldVector clicked) {
}
} else if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) {
if (session.getSuperPickaxe() != null) {
return session.getSuperPickaxe().actPrimary(server, config,
player, session, clicked);
if (session.getSuperPickaxe().canUse(player)) {
return session.getSuperPickaxe().actPrimary(server, config,
player, session, clicked);
}
}
}
Tool tool = session.getTool(player.getItemInHand());
if (tool != null && tool instanceof DoubleActionBlockTool) {
((DoubleActionBlockTool)tool).actSecondary(server, config, player, session, clicked);
return true;
if (tool.canUse(player)) {
((DoubleActionBlockTool)tool).actSecondary(server, config, player, session, clicked);
return true;
}
}
return false;

View File

@ -77,9 +77,9 @@ public static void sphereBrush(CommandContext args, WorldEdit we,
tool.setSize(radius);
if (args.hasFlag('h')) {
tool.setBrush(new HollowSphereBrush());
tool.setBrush(new HollowSphereBrush(), "worldedit.brush.sphere");
} else {
tool.setBrush(new SphereBrush());
tool.setBrush(new SphereBrush(), "worldedit.brush.sphere");
}
player.print(String.format("Sphere brush shape equipped (%d).",
@ -121,9 +121,9 @@ public static void cylinderBrush(CommandContext args, WorldEdit we,
tool.setSize(radius);
if (args.hasFlag('h')) {
tool.setBrush(new HollowCylinderBrush(height));
tool.setBrush(new HollowCylinderBrush(height), "worldedit.brush.cylinder");
} else {
tool.setBrush(new CylinderBrush(height));
tool.setBrush(new CylinderBrush(height), "worldedit.brush.cylinder");
}
player.print(String.format("Cylinder brush shape equipped (%d by %d).",
@ -163,7 +163,7 @@ public static void clipboardBrush(CommandContext args, WorldEdit we,
}
BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setBrush(new ClipboardBrush(clipboard, args.hasFlag('a')));
tool.setBrush(new ClipboardBrush(clipboard, args.hasFlag('a')), "worldedit.brush.clipboard");
player.print("Clipboard brush shape equipped.");
}
@ -193,7 +193,7 @@ public static void smoothBrush(CommandContext args, WorldEdit we,
BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setSize(radius);
tool.setBrush(new SmoothBrush(iterations));
tool.setBrush(new SmoothBrush(iterations), "worldedit.brush.smooth");
player.print(String.format("Smooth brush equipped (%d x %dx).",
radius, iterations));
@ -225,7 +225,7 @@ public static void extinguishBrush(CommandContext args, WorldEdit we,
tool.setFill(fill);
tool.setSize(radius);
tool.setMask(new BlockTypeMask(BlockID.FIRE));
tool.setBrush(new SphereBrush());
tool.setBrush(new SphereBrush(), "worldedit.brush.ex");
player.print(String.format("Extinguisher equipped (%d).",
radius));

View File

@ -36,6 +36,10 @@ public AreaPickaxe(int range) {
this.range = range;
}
public boolean canUse(LocalPlayer player) {
return player.hasPermission("worldedit.superpickaxe.area");
}
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {
LocalWorld world = clicked.getWorld();

View File

@ -29,6 +29,10 @@
*/
public class BlockDataCyler implements DoubleActionBlockTool {
public boolean canUse(LocalPlayer player) {
return player.hasPermission("worldedit.tool.data-cycler");
}
private boolean handleCycle(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked, boolean forward) {

View File

@ -36,6 +36,10 @@ public BlockReplacer(BaseBlock targetBlock) {
this.targetBlock = targetBlock;
}
public boolean canUse(LocalPlayer player) {
return player.hasPermission("worldedit.tool.replacer");
}
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {

View File

@ -39,6 +39,27 @@ public class BrushTool implements TraceTool {
private Brush brush = new SphereBrush();
private Pattern material = new SingleBlockPattern(new BaseBlock(BlockID.COBBLESTONE));
private int size = 1;
private String permission;
/**
* Construct the tool.
*
* @param permission
*/
public BrushTool(String permission) {
this.permission = permission;
}
/**
* Checks to see if the player can still be using this tool (considering
* permissions and such).
*
* @param player
* @return
*/
public boolean canUse(LocalPlayer player) {
return player.hasPermission(permission);
}
/**
* Get the filter.
@ -63,8 +84,9 @@ public void setMask(Mask filter) {
*
* @param brush
*/
public void setBrush(Brush brush) {
public void setBrush(Brush brush, String perm) {
this.brush = brush;
this.permission = perm;
}
/**

View File

@ -28,6 +28,10 @@
* @author sk89q
*/
public class QueryTool implements BlockTool {
public boolean canUse(LocalPlayer player) {
return player.hasPermission("worldedit.tool.info");
}
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {

View File

@ -39,6 +39,10 @@ public RecursivePickaxe(int range) {
this.range = range;
}
public boolean canUse(LocalPlayer player) {
return player.hasPermission("worldedit.superpickaxe.recursive");
}
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {
LocalWorld world = clicked.getWorld();

View File

@ -29,6 +29,10 @@
*/
public class SinglePickaxe implements BlockTool {
public boolean canUse(LocalPlayer player) {
return player.hasPermission("worldedit.superpickaxe");
}
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {
LocalWorld world = clicked.getWorld();

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.LocalPlayer;
/**
* Represents a tool. This interface alone defines nothing. A tool also
* has to implement <code>BlockTool</code> or <code>TraceTool</code>.
@ -26,4 +28,14 @@
* @author sk89q
*/
public abstract interface Tool {
/**
* Checks to see if the player can still be using this tool (considering
* permissions and such).
*
* @param player
* @return
*/
public boolean canUse(LocalPlayer player);
}

View File

@ -34,6 +34,10 @@ public TreePlanter(TreeGenerator gen) {
this.gen = gen;
}
public boolean canUse(LocalPlayer player) {
return player.hasPermission("worldedit.tool.tree");
}
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {