Skip to content

Commit

Permalink
Ensure that the wand can be used before giving it
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal committed Oct 18, 2020
1 parent 5876f18 commit d33b7a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Expand Up @@ -28,6 +28,7 @@
import com.sk89q.worldedit.command.argument.SelectorChoice;
import com.sk89q.worldedit.command.tool.NavigationWand;
import com.sk89q.worldedit.command.tool.SelectionWand;
import com.sk89q.worldedit.command.tool.Tool;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging;
Expand Down Expand Up @@ -289,7 +290,13 @@ public void chunk(Actor actor, World world, LocalSession session,
)
@CommandPermissions("worldedit.wand")
public void wand(Player player, LocalSession session,
@Switch(name = 'n', desc = "Get a navigation wand") boolean navWand) throws WorldEditException {
@Switch(name = 'n', desc = "Get a navigation wand")
boolean navWand) throws WorldEditException {
Tool tool = navWand ? new NavigationWand() : new SelectionWand();
if (!tool.canUse(player)) {
player.printError(TranslatableComponent.of("worldedit.command.permissions"));
return;
}
String wandId = navWand ? session.getNavWandItem() : session.getWandItem();
if (wandId == null) {
wandId = navWand ? we.getConfiguration().navigationWand : we.getConfiguration().wandItem;
Expand All @@ -300,13 +307,8 @@ public void wand(Player player, LocalSession session,
return;
}
player.giveItem(new BaseItemStack(itemType, 1));
if (navWand) {
session.setTool(itemType, new NavigationWand());
player.printInfo(TranslatableComponent.of("worldedit.wand.navwand.info"));
} else {
session.setTool(itemType, new SelectionWand());
player.printInfo(TranslatableComponent.of("worldedit.wand.selwand.info"));
}
session.setTool(itemType, tool);
player.printInfo(TranslatableComponent.of("worldedit.wand." + (navWand ? "nav" : "sel" ) + "wand.info"));
}

@Command(
Expand Down
Expand Up @@ -28,9 +28,13 @@
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;

public class NavigationWand implements DoubleActionTraceTool {

private static final String PRIMARY_PERMISSION = "worldedit.navigation.thru.tool";
private static final String SECONDARY_PERMISSION = "worldedit.navigation.jumpto.tool";

@Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
if (!player.hasPermission("worldedit.navigation.jumpto.tool")) {
if (!player.hasPermission(SECONDARY_PERMISSION)) {
return false;
}
final int maxDist = config.navigationWandMaxDistance;
Expand All @@ -48,7 +52,7 @@ public boolean actSecondary(Platform server, LocalConfiguration config, Player p

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
if (!player.hasPermission("worldedit.navigation.thru.tool")) {
if (!player.hasPermission(PRIMARY_PERMISSION)) {
return false;
}
final int maxDist = config.navigationWandMaxDistance;
Expand All @@ -64,6 +68,6 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla

@Override
public boolean canUse(Actor actor) {
return true; // skip check here - checked separately for primary/secondary
return actor.hasPermission(PRIMARY_PERMISSION) || actor.hasPermission(SECONDARY_PERMISSION);
}
}

0 comments on commit d33b7a8

Please sign in to comment.