mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2024-12-27 05:00:08 +08:00
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:
parent
5755755c15
commit
a18546d698
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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();
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user