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

@ -36,6 +36,10 @@ public class AreaPickaxe implements BlockTool {
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 @@ import com.sk89q.worldedit.blocks.BlockID;
*/
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 class BlockReplacer implements DoubleActionBlockTool {
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 class BrushTool implements TraceTool {
*
* @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 @@ import com.sk89q.worldedit.blocks.*;
* @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 class RecursivePickaxe implements BlockTool {
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 @@ import com.sk89q.worldedit.blocks.BlockID;
*/
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 @@ package com.sk89q.worldedit.tools;
* @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 class TreePlanter implements BlockTool {
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) {