Skip to content

Commit

Permalink
Add /sb safesel command and permission
Browse files Browse the repository at this point in the history
  • Loading branch information
bermudalocket committed Jan 23, 2019
1 parent 50f052e commit 16822db
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/nu/nerd/SafeBuckets/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class Commands implements TabExecutor {

private static final LinkedHashSet<String> SUBCOMMANDS = new LinkedHashSet<>(Arrays.asList(
"flowsel", "reload", "safe", "unsafe"
"flowsel", "reload", "safe", "safesel", "unsafe"
));

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -122,13 +122,34 @@ private boolean sbCommand(CommandSender sender, String[] args) {
}

if (sender instanceof Player) {
flowLiquidsInSelection((Player) sender);
bulkSafetyToggle((Player) sender, false);
} else {
sender.sendMessage(ChatColor.RED + "You must be in-game to flow liquids!");
}
return true;
}

// /sb safesel
if (args.length == 1 && args[0].equalsIgnoreCase("safesel")) {

if (!sender.hasPermission("safebuckets.safesel")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to do that!");
return true;
}

if (!SafeBuckets._worldEditEnabled || !Configuration.WORLDEDIT_FLOWSEL_ENABLED) {
sender.sendMessage(ChatColor.RED + "That feature is not enabled.");
return true;
}

if (sender instanceof Player) {
bulkSafetyToggle((Player) sender, true);
} else {
sender.sendMessage(ChatColor.RED + "You must be in-game to manage liquids!");
}
return true;
}

// /sb
if (args.length <= 2) {

Expand Down Expand Up @@ -236,7 +257,7 @@ private boolean playerFlowCommand(CommandSender sender) {
*
* @param player the player performing the action.
*/
private void flowLiquidsInSelection(Player player) {
private void bulkSafetyToggle(Player player, boolean state) {
int blocksAffected = 0;

if (!SafeBuckets._worldEditEnabled) {
Expand Down Expand Up @@ -272,14 +293,14 @@ private void flowLiquidsInSelection(Player player) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() == Material.WATER || block.getType() == Material.LAVA || Util.isWaterlogged(block)) {
SafeBuckets.setSafe(block, false);
SafeBuckets.setSafe(block, state);
blocksAffected++;
}
}
}
}

player.sendMessage(ChatColor.LIGHT_PURPLE + "Flowed " + blocksAffected + " blocks around " + Util.formatCoords(player.getLocation()) + ".");
player.sendMessage(ChatColor.LIGHT_PURPLE + (state ? "Made safe " : "Flowed ") + blocksAffected + " blocks around " + Util.formatCoords(player.getLocation()) + ".");
}

}
2 changes: 2 additions & 0 deletions src/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ permissions:
description: Players with this permission do not need to refill the unsafe buckets they empty.
safebuckets.flowsel:
description: Permission to use `/sb flowsel`.
safebuckets.safesel:
description: Permission to use `/sb safesel`.
safebuckets.reload:
description: Permission to use `/sb reload`.

Expand Down

0 comments on commit 16822db

Please sign in to comment.