Move some more code to core.

This commit is contained in:
Matthew Miller 2018-08-10 23:39:52 +10:00
parent e31fa306ab
commit b2e64498a8
14 changed files with 184 additions and 164 deletions

View File

@ -21,11 +21,32 @@
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.sk89q.squirrelid.cache.HashMapCache;
import com.sk89q.squirrelid.cache.ProfileCache;
import com.sk89q.squirrelid.cache.SQLiteCache;
import com.sk89q.squirrelid.resolver.BukkitPlayerService;
import com.sk89q.squirrelid.resolver.CacheForwardingService;
import com.sk89q.squirrelid.resolver.CombinedProfileService;
import com.sk89q.squirrelid.resolver.HttpRepositoryService;
import com.sk89q.squirrelid.resolver.ProfileService;
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
import com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry;
import com.sk89q.worldguard.util.concurrent.EvenMoreExecutors;
import com.sk89q.worldguard.util.task.SimpleSupervisor;
import com.sk89q.worldguard.util.task.Supervisor;
import com.sk89q.worldguard.util.task.Task;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
public class WorldGuard {
@ -35,6 +56,10 @@ public class WorldGuard {
private static final WorldGuard instance = new WorldGuard();
private WorldGuardPlatform platform;
private final SimpleFlagRegistry flagRegistry = new SimpleFlagRegistry();
private final Supervisor supervisor = new SimpleSupervisor();
private ProfileCache profileCache;
private ProfileService profileService;
private ListeningExecutorService executorService;
public static WorldGuard getInstance() {
return instance;
@ -44,8 +69,26 @@ private WorldGuard() {
}
public void setup() {
executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 20));
getPlatform().load();
Flags.registerAll();
File cacheDir = new File(getPlatform().getConfigDir().toFile(), "cache");
cacheDir.mkdirs();
try {
profileCache = new SQLiteCache(new File(getPlatform().getConfigDir().toFile(), "profiles.sqlite"));
} catch (IOException e) {
WorldGuard.logger.log(Level.WARNING, "Failed to initialize SQLite profile cache");
profileCache = new HashMapCache();
}
profileService = new CacheForwardingService(
new CombinedProfileService(
BukkitPlayerService.getInstance(),
HttpRepositoryService.forMinecraft()),
profileCache);
}
/**
@ -71,4 +114,71 @@ public void setPlatform(WorldGuardPlatform platform) {
public FlagRegistry getFlagRegistry() {
return this.flagRegistry;
}
/**
* Get the supervisor.
*
* @return the supervisor
*/
public Supervisor getSupervisor() {
return supervisor;
}
/**
* Get the global executor service for internal usage (please use your
* own executor service).
*
* @return the global executor service
*/
public ListeningExecutorService getExecutorService() {
return executorService;
}
/**
* Get the profile lookup service.
*
* @return the profile lookup service
*/
public ProfileService getProfileService() {
return profileService;
}
/**
* Get the profile cache.
*
* @return the profile cache
*/
public ProfileCache getProfileCache() {
return profileCache;
}
/**
* Called when WorldGuard should be disabled.
*/
public void disable() {
executorService.shutdown();
try {
WorldGuard.logger.log(Level.INFO, "Shutting down executor and waiting for any pending tasks...");
List<Task<?>> tasks = supervisor.getTasks();
if (!tasks.isEmpty()) {
StringBuilder builder = new StringBuilder("Known tasks:");
for (Task<?> task : tasks) {
builder.append("\n");
builder.append(task.getName());
}
WorldGuard.logger.log(Level.INFO, builder.toString());
}
Futures.successfulAsList(tasks).get();
executorService.awaitTermination(Integer.MAX_VALUE, TimeUnit.DAYS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
WorldGuard.logger.log(Level.WARNING, "Some tasks failed while waiting for remaining tasks to finish", e);
}
platform.unload();
}
}

View File

@ -17,10 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands.task;
package com.sk89q.worldguard.commands.task;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
@ -37,7 +37,6 @@
*/
public class RegionAdder implements Callable<ProtectedRegion> {
private final WorldGuardPlugin plugin;
private final RegionManager manager;
private final ProtectedRegion region;
@Nullable
@ -47,16 +46,13 @@ public class RegionAdder implements Callable<ProtectedRegion> {
/**
* Create a new instance.
*
* @param plugin the plugin
* @param manager the manage
* @param region the region
*/
public RegionAdder(WorldGuardPlugin plugin, RegionManager manager, ProtectedRegion region) {
checkNotNull(plugin);
public RegionAdder(RegionManager manager, ProtectedRegion region) {
checkNotNull(manager);
checkNotNull(region);
this.plugin = plugin;
this.manager = manager;
this.region = region;
}
@ -77,7 +73,7 @@ public void addOwnersFromCommand(CommandContext args, int namesIndex) {
@Override
public ProtectedRegion call() throws Exception {
if (ownersInput != null) {
DomainInputResolver resolver = new DomainInputResolver(plugin.getProfileService(), ownersInput);
DomainInputResolver resolver = new DomainInputResolver(WorldGuard.getInstance().getProfileService(), ownersInput);
resolver.setLocatorPolicy(locatorPolicy);
DefaultDomain domain = resolver.call();
region.getOwners().addAll(domain);

View File

@ -17,17 +17,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands.task;
package com.sk89q.worldguard.commands.task;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.squirrelid.Profile;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.ArrayList;
@ -39,24 +40,19 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
public class RegionLister implements Callable<Integer> {
private static final Logger log = Logger.getLogger(RegionLister.class.getCanonicalName());
private final WorldGuardPlugin plugin;
private final CommandSender sender;
private final Actor sender;
private final RegionManager manager;
private OwnerMatcher ownerMatcher;
private int page;
public RegionLister(WorldGuardPlugin plugin, RegionManager manager, CommandSender sender) {
checkNotNull(plugin);
public RegionLister(RegionManager manager, Actor sender) {
checkNotNull(manager);
checkNotNull(sender);
this.plugin = plugin;
this.manager = manager;
this.sender = sender;
}
@ -124,7 +120,7 @@ public boolean isContainedWithin(DefaultDomain domain) throws CommandException {
Profile profile;
try {
profile = plugin.getProfileService().findByName(name);
profile = WorldGuard.getInstance().getProfileService().findByName(name);
} catch (IOException e) {
log.log(Level.WARNING, "Failed UUID lookup of '" + name + "'", e);
throw new CommandException("Failed to lookup the UUID of '" + name + "'");
@ -150,7 +146,7 @@ public Integer call() throws Exception {
Map<String, ProtectedRegion> regions = manager.getRegions();
// Build a list of regions to show
List<RegionListEntry> entries = new ArrayList<RegionListEntry>();
List<RegionListEntry> entries = new ArrayList<>();
int index = 0;
for (String id : regions.keySet()) {
@ -176,8 +172,8 @@ public Integer call() throws Exception {
final int pageSize = 10;
final int pages = (int) Math.ceil(totalSize / (float) pageSize);
sender.sendMessage(ChatColor.RED
+ (ownerMatcher == null ? "Regions (page " : "Regions for " + ownerMatcher.getName() + " (page ")
sender.printError(
(ownerMatcher == null ? "Regions (page " : "Regions for " + ownerMatcher.getName() + " (page ")
+ (page + 1) + " of " + pages + "):");
if (page < pages) {
@ -187,17 +183,17 @@ public Integer call() throws Exception {
break;
}
sender.sendMessage(ChatColor.YELLOW.toString() + entries.get(i));
sender.print(String.valueOf(entries.get(i)));
}
}
return page;
}
private static interface OwnerMatcher {
public String getName();
private interface OwnerMatcher {
String getName();
public boolean isContainedWithin(DefaultDomain domain) throws CommandException;
boolean isContainedWithin(DefaultDomain domain) throws CommandException;
}
private class RegionListEntry implements Comparable<RegionListEntry> {

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands.task;
package com.sk89q.worldguard.commands.task;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.managers.storage.StorageException;

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands.task;
package com.sk89q.worldguard.commands.task;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.managers.storage.StorageException;

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands.task;
package com.sk89q.worldguard.commands.task;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.worldguard.protection.managers.RegionManager;

View File

@ -27,6 +27,8 @@
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.session.SessionManager;
import java.nio.file.Path;
/**
* A platform for implementing.
*/
@ -119,4 +121,11 @@ public interface WorldGuardPlatform {
* @return The default game mode
*/
GameMode getDefaultGameMode();
/**
* Gets the configuration directory.
*
* @return The config directory
*/
Path getConfigDir();
}

View File

@ -229,7 +229,7 @@ private void autoMigrate() {
if (config.migrateRegionsToUuid) {
RegionDriver driver = getDriver();
UUIDMigration migrator = new UUIDMigration(driver, plugin.getProfileService(), WorldGuard.getInstance().getFlagRegistry());
UUIDMigration migrator = new UUIDMigration(driver, WorldGuard.getInstance().getProfileService(), WorldGuard.getInstance().getFlagRegistry());
migrator.setKeepUnresolvedNames(config.keepUnresolvedNames);
try {
migrate(migrator);

View File

@ -36,6 +36,7 @@
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Set;
@ -128,4 +129,9 @@ public RegionContainer getRegionContainer() {
public GameMode getDefaultGameMode() {
return GameModes.get(Bukkit.getServer().getDefaultGameMode().name().toLowerCase());
}
@Override
public Path getConfigDir() {
return WorldGuardPlugin.inst().getDataFolder().toPath();
}
}

View File

@ -21,9 +21,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.sk89q.bukkit.util.CommandsManagerRegistration;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
@ -32,14 +29,6 @@
import com.sk89q.minecraft.util.commands.MissingNestedCommandException;
import com.sk89q.minecraft.util.commands.SimpleInjector;
import com.sk89q.minecraft.util.commands.WrappedCommandException;
import com.sk89q.squirrelid.cache.HashMapCache;
import com.sk89q.squirrelid.cache.ProfileCache;
import com.sk89q.squirrelid.cache.SQLiteCache;
import com.sk89q.squirrelid.resolver.BukkitPlayerService;
import com.sk89q.squirrelid.resolver.CacheForwardingService;
import com.sk89q.squirrelid.resolver.CombinedProfileService;
import com.sk89q.squirrelid.resolver.HttpRepositoryService;
import com.sk89q.squirrelid.resolver.ProfileService;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitCommandSender;
@ -74,18 +63,14 @@
import com.sk89q.worldguard.bukkit.listener.WorldRulesListener;
import com.sk89q.worldguard.bukkit.session.BukkitSessionManager;
import com.sk89q.worldguard.bukkit.util.Events;
import com.sk89q.worldguard.bukkit.util.logging.ClassSourceValidator;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry;
import com.sk89q.worldguard.protection.managers.storage.StorageException;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.util.UnresolvedNamesException;
import com.sk89q.worldguard.util.concurrent.EvenMoreExecutors;
import com.sk89q.worldguard.bukkit.util.logging.ClassSourceValidator;
import com.sk89q.worldguard.util.logging.RecordMessagePrefixer;
import com.sk89q.worldguard.util.task.SimpleSupervisor;
import com.sk89q.worldguard.util.task.Supervisor;
import com.sk89q.worldguard.util.task.Task;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
@ -109,9 +94,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -127,10 +110,6 @@ public class WorldGuardPlugin extends JavaPlugin {
private static WorldGuardPlugin inst;
private static BukkitWorldGuardPlatform platform;
private final CommandsManager<CommandSender> commands;
private final Supervisor supervisor = new SimpleSupervisor();
private ListeningExecutorService executorService;
private ProfileService profileService;
private ProfileCache profileCache;
private PlayerMoveListener playerMoveListener;
/**
@ -165,23 +144,6 @@ public void onEnable() {
getDataFolder().mkdirs(); // Need to create the plugins/WorldGuard folder
executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 20));
File cacheDir = new File(getDataFolder(), "cache");
cacheDir.mkdirs();
try {
profileCache = new SQLiteCache(new File(cacheDir, "profiles.sqlite"));
} catch (IOException e) {
WorldGuard.logger.log(Level.WARNING, "Failed to initialize SQLite profile cache");
profileCache = new HashMapCache();
}
profileService = new CacheForwardingService(
new CombinedProfileService(
BukkitPlayerService.getInstance(),
HttpRepositoryService.forMinecraft()),
profileCache);
PermissionsResolverManager.initialize(this);
WorldGuard.getInstance().setPlatform(platform = new BukkitWorldGuardPlatform()); // Initialise WorldGuard
@ -260,30 +222,7 @@ public void onEnable() {
@Override
public void onDisable() {
executorService.shutdown();
try {
WorldGuard.logger.log(Level.INFO, "Shutting down executor and waiting for any pending tasks...");
List<Task<?>> tasks = supervisor.getTasks();
if (!tasks.isEmpty()) {
StringBuilder builder = new StringBuilder("Known tasks:");
for (Task<?> task : tasks) {
builder.append("\n");
builder.append(task.getName());
}
WorldGuard.logger.log(Level.INFO, builder.toString());
}
Futures.successfulAsList(tasks).get();
executorService.awaitTermination(Integer.MAX_VALUE, TimeUnit.DAYS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
WorldGuard.logger.log(Level.WARNING, "Some tasks failed while waiting for remaining tasks to finish", e);
}
platform.unload();
WorldGuard.getInstance().disable();
this.getServer().getScheduler().cancelTasks(this);
}
@ -335,43 +274,6 @@ public String convertThrowable(@Nullable Throwable throwable) {
}
}
/**
* Get the supervisor.
*
* @return the supervisor
*/
public Supervisor getSupervisor() {
return supervisor;
}
/**
* Get the global executor service for internal usage (please use your
* own executor service).
*
* @return the global executor service
*/
public ListeningExecutorService getExecutorService() {
return executorService;
}
/**
* Get the profile lookup service.
*
* @return the profile lookup service
*/
public ProfileService getProfileService() {
return profileService;
}
/**
* Get the profile cache.
*
* @return the profile cache
*/
public ProfileCache getProfileCache() {
return profileCache;
}
/**
* Check whether a player is in a group.
* This calls the corresponding method in PermissionsResolverManager

View File

@ -21,6 +21,7 @@
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.util.task.FutureForwardingTask;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.World;
@ -62,7 +63,7 @@ private String format(String message) {
}
public AsyncCommandHelper registerWithSupervisor(String description) {
plugin.getSupervisor().monitor(
WorldGuard.getInstance().getSupervisor().monitor(
FutureForwardingTask.create(
future, format(description), sender));
return this;

View File

@ -82,7 +82,7 @@ public void version(CommandContext args, CommandSender sender) throws CommandExc
@CommandPermissions({"worldguard.reload"})
public void reload(CommandContext args, CommandSender sender) throws CommandException {
// TODO: This is subject to a race condition, but at least other commands are not being processed concurrently
List<Task<?>> tasks = plugin.getSupervisor().getTasks();
List<Task<?>> tasks = WorldGuard.getInstance().getSupervisor().getTasks();
if (!tasks.isEmpty()) {
throw new CommandException("There are currently pending tasks. Use /wg running to monitor these tasks first.");
}
@ -265,7 +265,7 @@ public void flushStates(CommandContext args, CommandSender sender) throws Comman
@Command(aliases = {"running", "queue"}, desc = "List running tasks", max = 0)
@CommandPermissions("worldguard.running")
public void listRunningTasks(CommandContext args, CommandSender sender) throws CommandException {
List<Task<?>> tasks = plugin.getSupervisor().getTasks();
List<Task<?>> tasks = WorldGuard.getInstance().getSupervisor().getTasks();
if (!tasks.isEmpty()) {
Collections.sort(tasks, new TaskStateComparator());

View File

@ -71,12 +71,12 @@ public void addMember(CommandContext args, CommandSender sender) throws CommandE
// Resolve members asynchronously
DomainInputResolver resolver = new DomainInputResolver(
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
WorldGuard.getInstance().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),
WorldGuard.getInstance().getExecutorService().submit(resolver),
resolver.createAddAllFunction(region.getMembers()));
AsyncCommandHelper.wrap(future, plugin, sender)
@ -135,12 +135,12 @@ public void addOwner(CommandContext args, CommandSender sender) throws CommandEx
// Resolve owners asynchronously
DomainInputResolver resolver = new DomainInputResolver(
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
WorldGuard.getInstance().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),
WorldGuard.getInstance().getExecutorService().submit(resolver),
resolver.createAddAllFunction(region.getOwners()));
AsyncCommandHelper.wrap(future, plugin, sender)
@ -181,12 +181,12 @@ public void removeMember(CommandContext args, CommandSender sender) throws Comma
// Resolve members asynchronously
DomainInputResolver resolver = new DomainInputResolver(
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
WorldGuard.getInstance().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),
WorldGuard.getInstance().getExecutorService().submit(resolver),
resolver.createRemoveAllFunction(region.getMembers()));
}
@ -228,12 +228,12 @@ public void removeOwner(CommandContext args, CommandSender sender) throws Comman
// Resolve owners asynchronously
DomainInputResolver resolver = new DomainInputResolver(
plugin.getProfileService(), args.getParsedPaddedSlice(1, 0));
WorldGuard.getInstance().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),
WorldGuard.getInstance().getExecutorService().submit(resolver),
resolver.createRemoveAllFunction(region.getOwners()));
}

View File

@ -40,11 +40,11 @@
import com.sk89q.worldguard.bukkit.commands.CommandUtils;
import com.sk89q.worldguard.bukkit.commands.FutureProgressListener;
import com.sk89q.worldguard.bukkit.commands.MessageFutureCallback.Builder;
import com.sk89q.worldguard.bukkit.commands.task.RegionAdder;
import com.sk89q.worldguard.bukkit.commands.task.RegionLister;
import com.sk89q.worldguard.bukkit.commands.task.RegionManagerReloader;
import com.sk89q.worldguard.bukkit.commands.task.RegionManagerSaver;
import com.sk89q.worldguard.bukkit.commands.task.RegionRemover;
import com.sk89q.worldguard.commands.task.RegionAdder;
import com.sk89q.worldguard.commands.task.RegionLister;
import com.sk89q.worldguard.commands.task.RegionManagerReloader;
import com.sk89q.worldguard.commands.task.RegionManagerSaver;
import com.sk89q.worldguard.commands.task.RegionRemover;
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
import com.sk89q.worldguard.bukkit.util.logging.LoggerToChatHandler;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
@ -131,9 +131,9 @@ public void define(CommandContext args, CommandSender sender) throws CommandExce
informNewUser(player, manager, region);
}
RegionAdder task = new RegionAdder(plugin, manager, region);
RegionAdder task = new RegionAdder(manager, region);
task.addOwnersFromCommand(args, 2);
ListenableFuture<?> future = plugin.getExecutorService().submit(task);
ListenableFuture<?> future = WorldGuard.getInstance().getExecutorService().submit(task);
AsyncCommandHelper.wrap(future, plugin, player)
.formatUsing(id)
@ -186,8 +186,8 @@ public void redefine(CommandContext args, CommandSender sender) throws CommandEx
region.copyFrom(existing);
RegionAdder task = new RegionAdder(plugin, manager, region);
ListenableFuture<?> future = plugin.getExecutorService().submit(task);
RegionAdder task = new RegionAdder(manager, region);
ListenableFuture<?> future = WorldGuard.getInstance().getExecutorService().submit(task);
AsyncCommandHelper.wrap(future, plugin, player)
.formatUsing(id)
@ -288,10 +288,10 @@ public void claim(CommandContext args, CommandSender sender) throws CommandExcep
}
}
RegionAdder task = new RegionAdder(plugin, manager, region);
RegionAdder task = new RegionAdder(manager, region);
task.setLocatorPolicy(UserLocatorPolicy.UUID_ONLY);
task.setOwnersInput(new String[]{player.getName()});
ListenableFuture<?> future = plugin.getExecutorService().submit(task);
ListenableFuture<?> future = WorldGuard.getInstance().getExecutorService().submit(task);
AsyncCommandHelper.wrap(future, plugin, player)
.formatUsing(id)
@ -385,9 +385,9 @@ public void info(CommandContext args, CommandSender sender) throws CommandExcept
}
// Print region information
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(existing, args.hasFlag('u') ? null : plugin.getProfileCache());
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(existing, args.hasFlag('u') ? null : WorldGuard.getInstance().getProfileCache());
ListenableFuture<?> future = Futures.transform(
plugin.getExecutorService().submit(printout),
WorldGuard.getInstance().getExecutorService().submit(printout),
CommandUtils.messageFunction(sender)::apply);
// If it takes too long...
@ -443,13 +443,13 @@ public void list(CommandContext args, CommandSender sender) throws CommandExcept
RegionManager manager = checkRegionManager(plugin, BukkitAdapter.adapt(world));
RegionLister task = new RegionLister(plugin, manager, sender);
RegionLister task = new RegionLister(manager, actor);
task.setPage(page);
if (ownedBy != null) {
task.filterOwnedByName(ownedBy, args.hasFlag('n'));
}
ListenableFuture<?> future = plugin.getExecutorService().submit(task);
ListenableFuture<?> future = WorldGuard.getInstance().getExecutorService().submit(task);
AsyncCommandHelper.wrap(future, plugin, sender)
.registerWithSupervisor("Getting list of regions...")
@ -765,7 +765,7 @@ public void remove(CommandContext args, CommandSender sender) throws CommandExce
task.setRemovalStrategy(RemovalStrategy.UNSET_PARENT_IN_CHILDREN);
}
AsyncCommandHelper.wrap(plugin.getExecutorService().submit(task), plugin, sender)
AsyncCommandHelper.wrap(WorldGuard.getInstance().getExecutorService().submit(task), plugin, sender)
.formatUsing(existing.getId())
.registerWithSupervisor("Removing the region '%s'...")
.sendMessageAfterDelay("(Please wait... removing '%s'...)")
@ -807,7 +807,7 @@ public void load(CommandContext args, final CommandSender sender) throws Command
throw new CommandException("No region manager exists for world '" + world.getName() + "'.");
}
ListenableFuture<?> future = plugin.getExecutorService().submit(new RegionManagerReloader(manager));
ListenableFuture<?> future = WorldGuard.getInstance().getExecutorService().submit(new RegionManagerReloader(manager));
AsyncCommandHelper.wrap(future, plugin, sender)
.forRegionDataLoad(world, false);
@ -822,7 +822,7 @@ public void load(CommandContext args, final CommandSender sender) throws Command
}
}
ListenableFuture<?> future = plugin.getExecutorService().submit(new RegionManagerReloader(managers));
ListenableFuture<?> future = WorldGuard.getInstance().getExecutorService().submit(new RegionManagerReloader(managers));
AsyncCommandHelper.wrap(future, plugin, sender)
.registerWithSupervisor("Loading regions for all worlds")
@ -866,7 +866,7 @@ public void save(CommandContext args, final CommandSender sender) throws Command
throw new CommandException("No region manager exists for world '" + world.getName() + "'.");
}
ListenableFuture<?> future = plugin.getExecutorService().submit(new RegionManagerSaver(manager));
ListenableFuture<?> future = WorldGuard.getInstance().getExecutorService().submit(new RegionManagerSaver(manager));
AsyncCommandHelper.wrap(future, plugin, sender)
.forRegionDataSave(world, false);
@ -881,7 +881,7 @@ public void save(CommandContext args, final CommandSender sender) throws Command
}
}
ListenableFuture<?> future = plugin.getExecutorService().submit(new RegionManagerSaver(managers));
ListenableFuture<?> future = WorldGuard.getInstance().getExecutorService().submit(new RegionManagerSaver(managers));
AsyncCommandHelper.wrap(future, plugin, sender)
.registerWithSupervisor("Saving regions for all worlds")
@ -999,7 +999,7 @@ public void migrateUuid(CommandContext args, CommandSender sender) throws Comman
ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitRegionContainer container = (BukkitRegionContainer) WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionDriver driver = container.getDriver();
UUIDMigration migration = new UUIDMigration(driver, plugin.getProfileService(), WorldGuard.getInstance().getFlagRegistry());
UUIDMigration migration = new UUIDMigration(driver, WorldGuard.getInstance().getProfileService(), WorldGuard.getInstance().getFlagRegistry());
migration.setKeepUnresolvedNames(config.keepUnresolvedNames);
sender.sendMessage(ChatColor.YELLOW + "Now performing migration... this may take a while.");
container.migrate(migration);