Refactor region commands and make the necessary ones run in the background.

This commit is contained in:
sk89q 2014-08-14 21:24:32 -07:00
parent a35cb9277e
commit 28c538e981
13 changed files with 1228 additions and 1720 deletions

View File

@ -30,7 +30,7 @@
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
class AsyncCommandHelper { public class AsyncCommandHelper {
private final ListenableFuture<?> future; private final ListenableFuture<?> future;
private final WorldGuardPlugin plugin; private final WorldGuardPlugin plugin;

View File

@ -30,7 +30,7 @@
/** /**
* Command-related utility methods. * Command-related utility methods.
*/ */
final class CommandUtils { public final class CommandUtils {
private CommandUtils() { private CommandUtils() {
} }
@ -41,7 +41,7 @@ private CommandUtils() {
* @param owner the owner object * @param owner the owner object
* @return a name * @return a name
*/ */
static String getOwnerName(@Nullable Object owner) { public static String getOwnerName(@Nullable Object owner) {
if (owner == null) { if (owner == null) {
return "?"; return "?";
} else if (owner instanceof Player) { } else if (owner instanceof Player) {
@ -62,7 +62,7 @@ static String getOwnerName(@Nullable Object owner) {
* @param sender the sender * @param sender the sender
* @return a function * @return a function
*/ */
static Function<String, ?> messageFunction(final CommandSender sender) { public static Function<String, ?> messageFunction(final CommandSender sender) {
return new Function<String, Object>() { return new Function<String, Object>() {
@Override @Override
public Object apply(@Nullable String s) { public Object apply(@Nullable String s) {

View File

@ -28,14 +28,14 @@
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
class FutureProgressListener implements Runnable { public class FutureProgressListener implements Runnable {
private static final Timer timer = new Timer(); private static final Timer timer = new Timer();
private static final int MESSAGE_DELAY = 1000; private static final int MESSAGE_DELAY = 1000;
private final MessageTimerTask task; private final MessageTimerTask task;
FutureProgressListener(CommandSender sender, String message) { public FutureProgressListener(CommandSender sender, String message) {
checkNotNull(sender); checkNotNull(sender);
checkNotNull(message); checkNotNull(message);

View File

@ -28,7 +28,7 @@
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
class MessageFutureCallback<V> implements FutureCallback<V> { public class MessageFutureCallback<V> implements FutureCallback<V> {
private final WorldGuardPlugin plugin; private final WorldGuardPlugin plugin;
private final CommandSender sender; private final CommandSender sender;
@ -57,7 +57,7 @@ public void onFailure(@Nullable Throwable throwable) {
sender.sendMessage(ChatColor.RED + failure + ": " + plugin.convertThrowable(throwable)); sender.sendMessage(ChatColor.RED + failure + ": " + plugin.convertThrowable(throwable));
} }
static class Builder { public static class Builder {
private final WorldGuardPlugin plugin; private final WorldGuardPlugin plugin;
private final CommandSender sender; private final CommandSender sender;
@Nullable @Nullable
@ -65,7 +65,7 @@ static class Builder {
@Nullable @Nullable
private String failure; private String failure;
Builder(WorldGuardPlugin plugin, CommandSender sender) { public Builder(WorldGuardPlugin plugin, CommandSender sender) {
checkNotNull(plugin); checkNotNull(plugin);
checkNotNull(sender); checkNotNull(sender);

View File

@ -25,7 +25,7 @@
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
class MessageTimerTask extends TimerTask { public class MessageTimerTask extends TimerTask {
private final CommandSender sender; private final CommandSender sender;
private final String message; private final String message;

View File

@ -19,6 +19,8 @@
package com.sk89q.worldguard.bukkit.commands; package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.commands.region.MemberCommands;
import com.sk89q.worldguard.bukkit.commands.region.RegionCommands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
@ -35,7 +37,7 @@ public ProtectionCommands(WorldGuardPlugin plugin) {
} }
@Command(aliases = {"region", "regions", "rg"}, desc = "Region management commands") @Command(aliases = {"region", "regions", "rg"}, desc = "Region management commands")
@NestedCommand({RegionCommands.class, RegionMemberCommands.class}) @NestedCommand({RegionCommands.class, MemberCommands.class})
public void region(CommandContext args, CommandSender sender) {} public void region(CommandContext args, CommandSender sender) {}
@Command(aliases = {"worldguard", "wg"}, desc = "WorldGuard commands") @Command(aliases = {"worldguard", "wg"}, desc = "WorldGuard commands")

View File

@ -1,59 +0,0 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
/**
* Used for /rg list.
*/
class RegionListEntry implements Comparable<RegionListEntry> {
private final String id;
private final int index;
boolean isOwner;
boolean isMember;
public RegionListEntry(String id, int index) {
this.id = id;
this.index = index;
}
@Override
public int compareTo(RegionListEntry o) {
if (isOwner != o.isOwner) {
return isOwner ? 1 : -1;
}
if (isMember != o.isMember) {
return isMember ? 1 : -1;
}
return id.compareTo(o.id);
}
@Override
public String toString() {
if (isOwner) {
return (index + 1) + ". +" + id;
} else if (isMember) {
return (index + 1) + ". -" + id;
} else {
return (index + 1) + ". " + id;
}
}
}

View File

@ -1,330 +1,234 @@
/* /*
* WorldGuard, a suite of tools for Minecraft * WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors * Copyright (C) WorldGuard team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or * Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldguard.bukkit.commands; package com.sk89q.worldguard.bukkit.commands.region;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.worldguard.LocalPlayer; import com.sk89q.minecraft.util.commands.CommandPermissionsException;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.domains.DefaultDomain; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.util.DomainInputResolver; import com.sk89q.worldguard.bukkit.commands.AsyncCommandHelper;
import com.sk89q.worldguard.protection.util.DomainInputResolver.UserLocatorPolicy; import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.util.DomainInputResolver;
import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.util.DomainInputResolver.UserLocatorPolicy;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.flags.DefaultFlag;
import org.bukkit.World; import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.command.CommandSender; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.entity.Player; import org.bukkit.World;
import org.bukkit.command.CommandSender;
// @TODO: A lot of code duplication here! Need to fix. import org.bukkit.entity.Player;
public class RegionMemberCommands { public class MemberCommands extends RegionCommandsBase {
private final WorldGuardPlugin plugin; private final WorldGuardPlugin plugin;
public RegionMemberCommands(WorldGuardPlugin plugin) { public MemberCommands(WorldGuardPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@Command(aliases = {"addmember", "addmember", "addmem", "am"}, @Command(aliases = {"addmember", "addmember", "addmem", "am"},
usage = "<id> <members...>", usage = "<id> <members...>",
flags = "nw:", flags = "nw:",
desc = "Add a member to a region", desc = "Add a member to a region",
min = 2) min = 2)
public void addMember(CommandContext args, CommandSender sender) throws CommandException { public void addMember(CommandContext args, CommandSender sender) throws CommandException {
final World world; World world = checkWorld(args, sender, 'w'); // Get the world
Player player = null; String id = args.getString(0);
LocalPlayer localPlayer = null; RegionManager manager = checkRegionManager(plugin, world);
if (sender instanceof Player) { ProtectedRegion region = checkExistingRegion(manager, id, true);
player = (Player) sender;
localPlayer = plugin.wrapPlayer(player); id = region.getId();
}
if (args.hasFlag('w')) { // Check permissions
world = plugin.matchWorld(sender, args.getFlag('w')); if (!getPermissionModel(sender).mayAddMembers(region)) {
} else { throw new CommandPermissionsException();
if (player != null) { }
world = player.getWorld();
} else { // Resolve members asynchronously
throw new CommandException("No world specified. Use -w <worldname>."); DomainInputResolver resolver = new DomainInputResolver(
} plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
} resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
String id = args.getString(0); // Then add it to the members
ListenableFuture<DefaultDomain> future = Futures.transform(
RegionManager manager = plugin.getGlobalRegionManager().get(world); plugin.getExecutorService().submit(resolver),
ProtectedRegion region = manager.matchRegion(id); resolver.createAddAllFunction(region.getMembers()));
if (region == null) { AsyncCommandHelper.wrap(future, plugin, sender)
throw new CommandException("Could not find a region by that ID."); .formatUsing(region.getId(), world.getName())
} .registerWithSupervisor("Adding members to the region '%s' on '%s'")
.sendMessageAfterDelay("(Please wait... querying player names...)")
id = region.getId(); .thenRespondWith("Region '%s' updated with new members.", "Failed to add new members");
}
if (localPlayer != null) {
if (region.isOwner(localPlayer)) { @Command(aliases = {"addowner", "addowner", "ao"},
plugin.checkPermission(sender, "worldguard.region.addmember.own." + id.toLowerCase()); usage = "<id> <owners...>",
} else if (region.isMember(localPlayer)) { flags = "nw:",
plugin.checkPermission(sender, "worldguard.region.addmember.member." + id.toLowerCase()); desc = "Add an owner to a region",
} else { min = 2)
plugin.checkPermission(sender, "worldguard.region.addmember." + id.toLowerCase()); public void addOwner(CommandContext args, CommandSender sender) throws CommandException {
} World world = checkWorld(args, sender, 'w'); // Get the world
}
Player player = null;
// Resolve members asynchronously LocalPlayer localPlayer = null;
DomainInputResolver resolver = new DomainInputResolver( if (sender instanceof Player) {
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0)); player = (Player) sender;
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY); localPlayer = plugin.wrapPlayer(player);
}
// Then add it to the members
ListenableFuture<DefaultDomain> future = Futures.transform( String id = args.getString(0);
plugin.getExecutorService().submit(resolver),
resolver.createAddAllFunction(region.getMembers())); RegionManager manager = checkRegionManager(plugin, world);
ProtectedRegion region = checkExistingRegion(manager, id, true);
AsyncCommandHelper.wrap(future, plugin, sender)
.formatUsing(region.getId(), world.getName()) id = region.getId();
.registerWithSupervisor("Adding members to the region '%s' on '%s'")
.sendMessageAfterDelay("(Please wait... querying player names...)") Boolean flag = region.getFlag(DefaultFlag.BUYABLE);
.thenRespondWith("Region '%s' updated with new members.", "Failed to add new members"); DefaultDomain owners = region.getOwners();
}
if (localPlayer != null) {
@Command(aliases = {"addowner", "addowner", "ao"}, if (flag != null && flag && owners != null && owners.size() == 0) {
usage = "<id> <owners...>", // TODO: Move this to an event
flags = "nw:", if (!plugin.hasPermission(player, "worldguard.region.unlimited")) {
desc = "Add an owner to a region", int maxRegionCount = plugin.getGlobalStateManager().get(world).getMaxRegionCount(player);
min = 2) if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(localPlayer)
public void addOwner(CommandContext args, CommandSender sender) throws CommandException { >= maxRegionCount) {
final World world; throw new CommandException("You already own the maximum allowed amount of regions.");
Player player = null; }
LocalPlayer localPlayer = null; }
if (sender instanceof Player) { plugin.checkPermission(sender, "worldguard.region.addowner.unclaimed." + id.toLowerCase());
player = (Player) sender; } else {
localPlayer = plugin.wrapPlayer(player); // Check permissions
} if (!getPermissionModel(sender).mayAddOwners(region)) {
if (args.hasFlag('w')) { throw new CommandPermissionsException();
world = plugin.matchWorld(sender, args.getFlag('w')); }
} else { }
if (player != null) { }
world = player.getWorld();
} else { // Resolve owners asynchronously
throw new CommandException("No world specified. Use -w <worldname>."); DomainInputResolver resolver = new DomainInputResolver(
} plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
} resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
String id = args.getString(0); // Then add it to the owners
ListenableFuture<DefaultDomain> future = Futures.transform(
RegionManager manager = plugin.getGlobalRegionManager().get(world); plugin.getExecutorService().submit(resolver),
ProtectedRegion region = manager.matchRegion(id); resolver.createAddAllFunction(region.getOwners()));
if (region == null) { AsyncCommandHelper.wrap(future, plugin, sender)
throw new CommandException("Could not find a region by that ID."); .formatUsing(region.getId(), world.getName())
} .registerWithSupervisor("Adding owners to the region '%s' on '%s'")
.sendMessageAfterDelay("(Please wait... querying player names...)")
id = region.getId(); .thenRespondWith("Region '%s' updated with new owners.", "Failed to add new owners");
}
Boolean flag = region.getFlag(DefaultFlag.BUYABLE);
DefaultDomain owners = region.getOwners(); @Command(aliases = {"removemember", "remmember", "removemem", "remmem", "rm"},
if (localPlayer != null) { usage = "<id> <owners...>",
if (flag != null && flag && owners != null && owners.size() == 0) { flags = "naw:",
if (!plugin.hasPermission(player, "worldguard.region.unlimited")) { desc = "Remove an owner to a region",
int maxRegionCount = plugin.getGlobalStateManager().get(world).getMaxRegionCount(player); min = 1)
if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(localPlayer) public void removeMember(CommandContext args, CommandSender sender) throws CommandException {
>= maxRegionCount) { World world = checkWorld(args, sender, 'w'); // Get the world
throw new CommandException("You already own the maximum allowed amount of regions."); String id = args.getString(0);
} RegionManager manager = checkRegionManager(plugin, world);
} ProtectedRegion region = checkExistingRegion(manager, id, true);
plugin.checkPermission(sender, "worldguard.region.addowner.unclaimed." + id.toLowerCase());
} else { // Check permissions
if (region.isOwner(localPlayer)) { if (!getPermissionModel(sender).mayRemoveMembers(region)) {
plugin.checkPermission(sender, "worldguard.region.addowner.own." + id.toLowerCase()); throw new CommandPermissionsException();
} else if (region.isMember(localPlayer)) { }
plugin.checkPermission(sender, "worldguard.region.addowner.member." + id.toLowerCase());
} else { ListenableFuture<?> future;
plugin.checkPermission(sender, "worldguard.region.addowner." + id.toLowerCase());
} if (args.hasFlag('a')) {
} region.getMembers().removeAll();
}
future = Futures.immediateFuture(null);
// Resolve owners asynchronously } else {
DomainInputResolver resolver = new DomainInputResolver( if (args.argsLength() < 2) {
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0)); throw new CommandException("List some names to remove, or use -a to remove all.");
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY); }
// Then add it to the owners // Resolve members asynchronously
ListenableFuture<DefaultDomain> future = Futures.transform( DomainInputResolver resolver = new DomainInputResolver(
plugin.getExecutorService().submit(resolver), plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
resolver.createAddAllFunction(region.getOwners())); resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_AND_NAME);
AsyncCommandHelper.wrap(future, plugin, sender) // Then remove it from the members
.formatUsing(region.getId(), world.getName()) future = Futures.transform(
.registerWithSupervisor("Adding owners to the region '%s' on '%s'") plugin.getExecutorService().submit(resolver),
.sendMessageAfterDelay("(Please wait... querying player names...)") resolver.createRemoveAllFunction(region.getMembers()));
.thenRespondWith("Region '%s' updated with new owners.", "Failed to add new owners"); }
}
AsyncCommandHelper.wrap(future, plugin, sender)
@Command(aliases = {"removemember", "remmember", "removemem", "remmem", "rm"}, .formatUsing(region.getId(), world.getName())
usage = "<id> <owners...>", .registerWithSupervisor("Removing members from the region '%s' on '%s'")
flags = "naw:", .sendMessageAfterDelay("(Please wait... querying player names...)")
desc = "Remove an owner to a region", .thenRespondWith("Region '%s' updated with members removed.", "Failed to remove members");
min = 1) }
public void removeMember(CommandContext args, CommandSender sender) throws CommandException {
final World world; @Command(aliases = {"removeowner", "remowner", "ro"},
Player player = null; usage = "<id> <owners...>",
LocalPlayer localPlayer = null; flags = "naw:",
if (sender instanceof Player) { desc = "Remove an owner to a region",
player = (Player) sender; min = 1)
localPlayer = plugin.wrapPlayer(player); public void removeOwner(CommandContext args, CommandSender sender) throws CommandException {
} World world = checkWorld(args, sender, 'w'); // Get the world
if (args.hasFlag('w')) { String id = args.getString(0);
world = plugin.matchWorld(sender, args.getFlag('w')); RegionManager manager = checkRegionManager(plugin, world);
} else { ProtectedRegion region = checkExistingRegion(manager, id, true);
if (player != null) {
world = player.getWorld(); // Check permissions
} else { if (!getPermissionModel(sender).mayRemoveOwners(region)) {
throw new CommandException("No world specified. Use -w <worldname>."); throw new CommandPermissionsException();
} }
}
ListenableFuture<?> future;
String id = args.getString(0);
if (args.hasFlag('a')) {
RegionManager manager = plugin.getGlobalRegionManager().get(world); region.getOwners().removeAll();
ProtectedRegion region = manager.matchRegion(id);
future = Futures.immediateFuture(null);
if (region == null) { } else {
throw new CommandException("Could not find a region by that ID."); if (args.argsLength() < 2) {
} throw new CommandException("List some names to remove, or use -a to remove all.");
}
id = region.getId();
// Resolve owners asynchronously
if (localPlayer != null) { DomainInputResolver resolver = new DomainInputResolver(
if (region.isOwner(localPlayer)) { plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
plugin.checkPermission(sender, "worldguard.region.removemember.own." + id.toLowerCase()); resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_AND_NAME);
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removemember.member." + id.toLowerCase()); // Then remove it from the owners
} else { future = Futures.transform(
plugin.checkPermission(sender, "worldguard.region.removemember." + id.toLowerCase()); plugin.getExecutorService().submit(resolver),
} resolver.createRemoveAllFunction(region.getOwners()));
} }
ListenableFuture<?> future; AsyncCommandHelper.wrap(future, plugin, sender)
.formatUsing(region.getId(), world.getName())
if (args.hasFlag('a')) { .registerWithSupervisor("Removing owners from the region '%s' on '%s'")
region.getMembers().removeAll(); .sendMessageAfterDelay("(Please wait... querying player names...)")
.thenRespondWith("Region '%s' updated with owners removed.", "Failed to remove owners");
future = Futures.immediateFuture(null); }
} else { }
if (args.argsLength() < 2) {
throw new CommandException("List some names to remove, or use -a to remove all.");
}
// Resolve members asynchronously
DomainInputResolver resolver = new DomainInputResolver(
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_AND_NAME);
// Then remove it from the members
future = Futures.transform(
plugin.getExecutorService().submit(resolver),
resolver.createRemoveAllFunction(region.getMembers()));
}
AsyncCommandHelper.wrap(future, plugin, sender)
.formatUsing(region.getId(), world.getName())
.registerWithSupervisor("Removing members from the region '%s' on '%s'")
.sendMessageAfterDelay("(Please wait... querying player names...)")
.thenRespondWith("Region '%s' updated with members removed.", "Failed to remove members");
}
@Command(aliases = {"removeowner", "remowner", "ro"},
usage = "<id> <owners...>",
flags = "naw:",
desc = "Remove an owner to a region",
min = 1)
public void removeOwner(CommandContext args,
CommandSender sender) throws CommandException {
final World world;
Player player = null;
LocalPlayer localPlayer = null;
if (sender instanceof Player) {
player = (Player) sender;
localPlayer = plugin.wrapPlayer(player);
}
if (args.hasFlag('w')) {
world = plugin.matchWorld(sender, args.getFlag('w'));
} else {
if (player != null) {
world = player.getWorld();
} else {
throw new CommandException("No world specified. Use -w <worldname>.");
}
}
String id = args.getString(0);
RegionManager manager = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = manager.matchRegion(id);
if (region == null) {
throw new CommandException("Could not find a region by that ID.");
}
id = region.getId();
if (localPlayer != null) {
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removeowner.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removeowner.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.removeowner." + id.toLowerCase());
}
}
ListenableFuture<?> future;
if (args.hasFlag('a')) {
region.getOwners().removeAll();
future = Futures.immediateFuture(null);
} else {
if (args.argsLength() < 2) {
throw new CommandException("List some names to remove, or use -a to remove all.");
}
// Resolve owners asynchronously
DomainInputResolver resolver = new DomainInputResolver(
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_AND_NAME);
// Then remove it from the owners
future = Futures.transform(
plugin.getExecutorService().submit(resolver),
resolver.createRemoveAllFunction(region.getOwners()));
}
AsyncCommandHelper.wrap(future, plugin, sender)
.formatUsing(region.getId(), world.getName())
.registerWithSupervisor("Removing owners from the region '%s' on '%s'")
.sendMessageAfterDelay("(Please wait... querying player names...)")
.thenRespondWith("Region '%s' updated with owners removed.", "Failed to remove owners");
}
}

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldguard.bukkit.commands; package com.sk89q.worldguard.bukkit.commands.region;
import com.sk89q.squirrelid.cache.ProfileCache; import com.sk89q.squirrelid.cache.ProfileCache;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
@ -39,7 +39,7 @@
* Create a region printout, as used in /region info to show information about * Create a region printout, as used in /region info to show information about
* a region. * a region.
*/ */
class RegionPrintoutBuilder implements Callable<String> { public class RegionPrintoutBuilder implements Callable<String> {
private final ProtectedRegion region; private final ProtectedRegion region;
@Nullable @Nullable
@ -52,7 +52,7 @@ class RegionPrintoutBuilder implements Callable<String> {
* @param region the region * @param region the region
* @param cache a profile cache, or {@code null} * @param cache a profile cache, or {@code null}
*/ */
RegionPrintoutBuilder(ProtectedRegion region, @Nullable ProfileCache cache) { public RegionPrintoutBuilder(ProtectedRegion region, @Nullable ProfileCache cache) {
this.region = region; this.region = region;
this.cache = cache; this.cache = cache;
} }

View File

@ -28,16 +28,16 @@
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
public class RegionManagerReload implements Callable<Collection<RegionManager>> { public class RegionManagerReloader implements Callable<Collection<RegionManager>> {
private final Collection<RegionManager> managers; private final Collection<RegionManager> managers;
public RegionManagerReload(Collection<RegionManager> managers) { public RegionManagerReloader(Collection<RegionManager> managers) {
checkNotNull(managers); checkNotNull(managers);
this.managers = managers; this.managers = managers;
} }
public RegionManagerReload(RegionManager... manager) { public RegionManagerReloader(RegionManager... manager) {
this(Arrays.asList(manager)); this(Arrays.asList(manager));
} }

View File

@ -28,16 +28,16 @@
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
public class RegionmanagerSave implements Callable<Collection<RegionManager>> { public class RegionManagerSaver implements Callable<Collection<RegionManager>> {
private final Collection<RegionManager> managers; private final Collection<RegionManager> managers;
public RegionmanagerSave(Collection<RegionManager> managers) { public RegionManagerSaver(Collection<RegionManager> managers) {
checkNotNull(managers); checkNotNull(managers);
this.managers = managers; this.managers = managers;
} }
public RegionmanagerSave(RegionManager... manager) { public RegionManagerSaver(RegionManager... manager) {
this(Arrays.asList(manager)); this(Arrays.asList(manager));
} }

View File

@ -123,6 +123,22 @@ public boolean maySetFlag(ProtectedRegion region, Flag<?> flag) {
return hasPatternPermission( return hasPatternPermission(
"flag.flags." + flag.getName().toLowerCase(), region); "flag.flags." + flag.getName().toLowerCase(), region);
} }
public boolean mayAddMembers(ProtectedRegion region) {
return hasPatternPermission("addmember", region);
}
public boolean mayAddOwners(ProtectedRegion region) {
return hasPatternPermission("addowner", region);
}
public boolean mayRemoveMembers(ProtectedRegion region) {
return hasPatternPermission("removemember", region);
}
public boolean mayRemoveOwners(ProtectedRegion region) {
return hasPatternPermission("removeowner", region);
}
/** /**
* Checks to see if the given sender has permission to modify the given region * Checks to see if the given sender has permission to modify the given region