mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-26 02:57:42 +01:00
Refactor region commands and make the necessary ones run in the background.
This commit is contained in:
parent
a35cb9277e
commit
28c538e981
@ -30,7 +30,7 @@
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
class AsyncCommandHelper {
|
||||
public class AsyncCommandHelper {
|
||||
|
||||
private final ListenableFuture<?> future;
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
@ -30,7 +30,7 @@
|
||||
/**
|
||||
* Command-related utility methods.
|
||||
*/
|
||||
final class CommandUtils {
|
||||
public final class CommandUtils {
|
||||
|
||||
private CommandUtils() {
|
||||
}
|
||||
@ -41,7 +41,7 @@ private CommandUtils() {
|
||||
* @param owner the owner object
|
||||
* @return a name
|
||||
*/
|
||||
static String getOwnerName(@Nullable Object owner) {
|
||||
public static String getOwnerName(@Nullable Object owner) {
|
||||
if (owner == null) {
|
||||
return "?";
|
||||
} else if (owner instanceof Player) {
|
||||
@ -62,7 +62,7 @@ static String getOwnerName(@Nullable Object owner) {
|
||||
* @param sender the sender
|
||||
* @return a function
|
||||
*/
|
||||
static Function<String, ?> messageFunction(final CommandSender sender) {
|
||||
public static Function<String, ?> messageFunction(final CommandSender sender) {
|
||||
return new Function<String, Object>() {
|
||||
@Override
|
||||
public Object apply(@Nullable String s) {
|
||||
|
@ -28,14 +28,14 @@
|
||||
|
||||
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 int MESSAGE_DELAY = 1000;
|
||||
|
||||
private final MessageTimerTask task;
|
||||
|
||||
FutureProgressListener(CommandSender sender, String message) {
|
||||
public FutureProgressListener(CommandSender sender, String message) {
|
||||
checkNotNull(sender);
|
||||
checkNotNull(message);
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
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 CommandSender sender;
|
||||
@ -57,7 +57,7 @@ public void onFailure(@Nullable Throwable throwable) {
|
||||
sender.sendMessage(ChatColor.RED + failure + ": " + plugin.convertThrowable(throwable));
|
||||
}
|
||||
|
||||
static class Builder {
|
||||
public static class Builder {
|
||||
private final WorldGuardPlugin plugin;
|
||||
private final CommandSender sender;
|
||||
@Nullable
|
||||
@ -65,7 +65,7 @@ static class Builder {
|
||||
@Nullable
|
||||
private String failure;
|
||||
|
||||
Builder(WorldGuardPlugin plugin, CommandSender sender) {
|
||||
public Builder(WorldGuardPlugin plugin, CommandSender sender) {
|
||||
checkNotNull(plugin);
|
||||
checkNotNull(sender);
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
class MessageTimerTask extends TimerTask {
|
||||
public class MessageTimerTask extends TimerTask {
|
||||
|
||||
private final CommandSender sender;
|
||||
private final String message;
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
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 com.sk89q.minecraft.util.commands.Command;
|
||||
@ -35,7 +37,7 @@ public ProtectionCommands(WorldGuardPlugin plugin) {
|
||||
}
|
||||
|
||||
@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) {}
|
||||
|
||||
@Command(aliases = {"worldguard", "wg"}, desc = "WorldGuard commands")
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,330 +1,234 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.util.DomainInputResolver;
|
||||
import com.sk89q.worldguard.protection.util.DomainInputResolver.UserLocatorPolicy;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// @TODO: A lot of code duplication here! Need to fix.
|
||||
|
||||
public class RegionMemberCommands {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public RegionMemberCommands(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(aliases = {"addmember", "addmember", "addmem", "am"},
|
||||
usage = "<id> <members...>",
|
||||
flags = "nw:",
|
||||
desc = "Add a member to a region",
|
||||
min = 2)
|
||||
public void addMember(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.addmember.own." + id.toLowerCase());
|
||||
} else if (region.isMember(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.addmember.member." + id.toLowerCase());
|
||||
} else {
|
||||
plugin.checkPermission(sender, "worldguard.region.addmember." + id.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve members asynchronously
|
||||
DomainInputResolver resolver = new DomainInputResolver(
|
||||
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
|
||||
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
|
||||
|
||||
// Then add it to the members
|
||||
ListenableFuture<DefaultDomain> future = Futures.transform(
|
||||
plugin.getExecutorService().submit(resolver),
|
||||
resolver.createAddAllFunction(region.getMembers()));
|
||||
|
||||
AsyncCommandHelper.wrap(future, plugin, sender)
|
||||
.formatUsing(region.getId(), world.getName())
|
||||
.registerWithSupervisor("Adding members to the region '%s' on '%s'")
|
||||
.sendMessageAfterDelay("(Please wait... querying player names...)")
|
||||
.thenRespondWith("Region '%s' updated with new members.", "Failed to add new members");
|
||||
}
|
||||
|
||||
@Command(aliases = {"addowner", "addowner", "ao"},
|
||||
usage = "<id> <owners...>",
|
||||
flags = "nw:",
|
||||
desc = "Add an owner to a region",
|
||||
min = 2)
|
||||
public void addOwner(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();
|
||||
|
||||
Boolean flag = region.getFlag(DefaultFlag.BUYABLE);
|
||||
DefaultDomain owners = region.getOwners();
|
||||
if (localPlayer != null) {
|
||||
if (flag != null && flag && owners != null && owners.size() == 0) {
|
||||
if (!plugin.hasPermission(player, "worldguard.region.unlimited")) {
|
||||
int maxRegionCount = plugin.getGlobalStateManager().get(world).getMaxRegionCount(player);
|
||||
if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(localPlayer)
|
||||
>= maxRegionCount) {
|
||||
throw new CommandException("You already own the maximum allowed amount of regions.");
|
||||
}
|
||||
}
|
||||
plugin.checkPermission(sender, "worldguard.region.addowner.unclaimed." + id.toLowerCase());
|
||||
} else {
|
||||
if (region.isOwner(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.addowner.own." + id.toLowerCase());
|
||||
} else if (region.isMember(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.addowner.member." + id.toLowerCase());
|
||||
} else {
|
||||
plugin.checkPermission(sender, "worldguard.region.addowner." + id.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve owners asynchronously
|
||||
DomainInputResolver resolver = new DomainInputResolver(
|
||||
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
|
||||
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
|
||||
|
||||
// Then add it to the owners
|
||||
ListenableFuture<DefaultDomain> future = Futures.transform(
|
||||
plugin.getExecutorService().submit(resolver),
|
||||
resolver.createAddAllFunction(region.getOwners()));
|
||||
|
||||
AsyncCommandHelper.wrap(future, plugin, sender)
|
||||
.formatUsing(region.getId(), world.getName())
|
||||
.registerWithSupervisor("Adding owners to the region '%s' on '%s'")
|
||||
.sendMessageAfterDelay("(Please wait... querying player names...)")
|
||||
.thenRespondWith("Region '%s' updated with new owners.", "Failed to add new owners");
|
||||
}
|
||||
|
||||
@Command(aliases = {"removemember", "remmember", "removemem", "remmem", "rm"},
|
||||
usage = "<id> <owners...>",
|
||||
flags = "naw:",
|
||||
desc = "Remove an owner to a region",
|
||||
min = 1)
|
||||
public void removeMember(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.removemember.own." + id.toLowerCase());
|
||||
} else if (region.isMember(localPlayer)) {
|
||||
plugin.checkPermission(sender, "worldguard.region.removemember.member." + id.toLowerCase());
|
||||
} else {
|
||||
plugin.checkPermission(sender, "worldguard.region.removemember." + id.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
ListenableFuture<?> future;
|
||||
|
||||
if (args.hasFlag('a')) {
|
||||
region.getMembers().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 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");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.region;
|
||||
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.commands.AsyncCommandHelper;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.util.DomainInputResolver;
|
||||
import com.sk89q.worldguard.protection.util.DomainInputResolver.UserLocatorPolicy;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MemberCommands extends RegionCommandsBase {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public MemberCommands(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(aliases = {"addmember", "addmember", "addmem", "am"},
|
||||
usage = "<id> <members...>",
|
||||
flags = "nw:",
|
||||
desc = "Add a member to a region",
|
||||
min = 2)
|
||||
public void addMember(CommandContext args, CommandSender sender) throws CommandException {
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
String id = args.getString(0);
|
||||
RegionManager manager = checkRegionManager(plugin, world);
|
||||
ProtectedRegion region = checkExistingRegion(manager, id, true);
|
||||
|
||||
id = region.getId();
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).mayAddMembers(region)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
|
||||
// Resolve members asynchronously
|
||||
DomainInputResolver resolver = new DomainInputResolver(
|
||||
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
|
||||
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
|
||||
|
||||
// Then add it to the members
|
||||
ListenableFuture<DefaultDomain> future = Futures.transform(
|
||||
plugin.getExecutorService().submit(resolver),
|
||||
resolver.createAddAllFunction(region.getMembers()));
|
||||
|
||||
AsyncCommandHelper.wrap(future, plugin, sender)
|
||||
.formatUsing(region.getId(), world.getName())
|
||||
.registerWithSupervisor("Adding members to the region '%s' on '%s'")
|
||||
.sendMessageAfterDelay("(Please wait... querying player names...)")
|
||||
.thenRespondWith("Region '%s' updated with new members.", "Failed to add new members");
|
||||
}
|
||||
|
||||
@Command(aliases = {"addowner", "addowner", "ao"},
|
||||
usage = "<id> <owners...>",
|
||||
flags = "nw:",
|
||||
desc = "Add an owner to a region",
|
||||
min = 2)
|
||||
public void addOwner(CommandContext args, CommandSender sender) throws CommandException {
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
|
||||
Player player = null;
|
||||
LocalPlayer localPlayer = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
localPlayer = plugin.wrapPlayer(player);
|
||||
}
|
||||
|
||||
String id = args.getString(0);
|
||||
|
||||
RegionManager manager = checkRegionManager(plugin, world);
|
||||
ProtectedRegion region = checkExistingRegion(manager, id, true);
|
||||
|
||||
id = region.getId();
|
||||
|
||||
Boolean flag = region.getFlag(DefaultFlag.BUYABLE);
|
||||
DefaultDomain owners = region.getOwners();
|
||||
|
||||
if (localPlayer != null) {
|
||||
if (flag != null && flag && owners != null && owners.size() == 0) {
|
||||
// TODO: Move this to an event
|
||||
if (!plugin.hasPermission(player, "worldguard.region.unlimited")) {
|
||||
int maxRegionCount = plugin.getGlobalStateManager().get(world).getMaxRegionCount(player);
|
||||
if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(localPlayer)
|
||||
>= maxRegionCount) {
|
||||
throw new CommandException("You already own the maximum allowed amount of regions.");
|
||||
}
|
||||
}
|
||||
plugin.checkPermission(sender, "worldguard.region.addowner.unclaimed." + id.toLowerCase());
|
||||
} else {
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).mayAddOwners(region)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve owners asynchronously
|
||||
DomainInputResolver resolver = new DomainInputResolver(
|
||||
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
|
||||
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
|
||||
|
||||
// Then add it to the owners
|
||||
ListenableFuture<DefaultDomain> future = Futures.transform(
|
||||
plugin.getExecutorService().submit(resolver),
|
||||
resolver.createAddAllFunction(region.getOwners()));
|
||||
|
||||
AsyncCommandHelper.wrap(future, plugin, sender)
|
||||
.formatUsing(region.getId(), world.getName())
|
||||
.registerWithSupervisor("Adding owners to the region '%s' on '%s'")
|
||||
.sendMessageAfterDelay("(Please wait... querying player names...)")
|
||||
.thenRespondWith("Region '%s' updated with new owners.", "Failed to add new owners");
|
||||
}
|
||||
|
||||
@Command(aliases = {"removemember", "remmember", "removemem", "remmem", "rm"},
|
||||
usage = "<id> <owners...>",
|
||||
flags = "naw:",
|
||||
desc = "Remove an owner to a region",
|
||||
min = 1)
|
||||
public void removeMember(CommandContext args, CommandSender sender) throws CommandException {
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
String id = args.getString(0);
|
||||
RegionManager manager = checkRegionManager(plugin, world);
|
||||
ProtectedRegion region = checkExistingRegion(manager, id, true);
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).mayRemoveMembers(region)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
|
||||
ListenableFuture<?> future;
|
||||
|
||||
if (args.hasFlag('a')) {
|
||||
region.getMembers().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 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 {
|
||||
World world = checkWorld(args, sender, 'w'); // Get the world
|
||||
String id = args.getString(0);
|
||||
RegionManager manager = checkRegionManager(plugin, world);
|
||||
ProtectedRegion region = checkExistingRegion(manager, id, true);
|
||||
|
||||
// Check permissions
|
||||
if (!getPermissionModel(sender).mayRemoveOwners(region)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,7 @@
|
||||
* 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.worldedit.BlockVector;
|
||||
@ -39,7 +39,7 @@
|
||||
* Create a region printout, as used in /region info to show information about
|
||||
* a region.
|
||||
*/
|
||||
class RegionPrintoutBuilder implements Callable<String> {
|
||||
public class RegionPrintoutBuilder implements Callable<String> {
|
||||
|
||||
private final ProtectedRegion region;
|
||||
@Nullable
|
||||
@ -52,7 +52,7 @@ class RegionPrintoutBuilder implements Callable<String> {
|
||||
* @param region the region
|
||||
* @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.cache = cache;
|
||||
}
|
@ -28,16 +28,16 @@
|
||||
|
||||
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;
|
||||
|
||||
public RegionManagerReload(Collection<RegionManager> managers) {
|
||||
public RegionManagerReloader(Collection<RegionManager> managers) {
|
||||
checkNotNull(managers);
|
||||
this.managers = managers;
|
||||
}
|
||||
|
||||
public RegionManagerReload(RegionManager... manager) {
|
||||
public RegionManagerReloader(RegionManager... manager) {
|
||||
this(Arrays.asList(manager));
|
||||
}
|
||||
|
@ -28,16 +28,16 @@
|
||||
|
||||
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;
|
||||
|
||||
public RegionmanagerSave(Collection<RegionManager> managers) {
|
||||
public RegionManagerSaver(Collection<RegionManager> managers) {
|
||||
checkNotNull(managers);
|
||||
this.managers = managers;
|
||||
}
|
||||
|
||||
public RegionmanagerSave(RegionManager... manager) {
|
||||
public RegionManagerSaver(RegionManager... manager) {
|
||||
this(Arrays.asList(manager));
|
||||
}
|
||||
|
@ -123,6 +123,22 @@ public boolean maySetFlag(ProtectedRegion region, Flag<?> flag) {
|
||||
return hasPatternPermission(
|
||||
"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
|
||||
|
Loading…
Reference in New Issue
Block a user