Skip to content
Permalink
Browse files

Re-arrange messages in (re)define commands.

Only send messages after successful add.
  • Loading branch information...
wizjany committed Sep 29, 2019
1 parent d07f959 commit d410e1f84e7ae6bfbfa3299bdd7d538fc3128399
@@ -11,10 +11,6 @@ applyPlatformAndCoreConfiguration()
applyShadowConfiguration()

repositories {
maven {
name = "spigot"
url = uri("https://hub.spigotmc.org/nexus/content/groups/public")
}
maven {
name = "paper"
url = uri("https://papermc.io/repo/repository/maven-public/")
@@ -152,8 +152,6 @@ public void define(CommandContext args, Actor sender) throws CommandException {
region = new GlobalProtectedRegion(id);
} else {
region = checkRegionFromSelection(player, id);
warnAboutDimensions(player, region);
informNewUser(player, manager, region);
}

RegionAdder task = new RegionAdder(manager, region);
@@ -162,8 +160,13 @@ public void define(CommandContext args, Actor sender) throws CommandException {
final String description = String.format("Adding region '%s'", region.getId());
AsyncCommandBuilder.wrap(task, sender)
.registerWithSupervisor(worldGuard.getSupervisor(), description)
.onSuccess(String.format("A new region has been made named '%s'.", region.getId()), null)
.onFailure("Failed to add the region '%s'", worldGuard.getExceptionConverter())
.onSuccess((Component) null,
t -> {
sender.print(String.format("A new region has been made named '%s'.", region.getId()));
warnAboutDimensions(sender, region);
informNewUser(sender, manager, region);
})
.onFailure(String.format("Failed to add the region '%s'", region.getId()), worldGuard.getExceptionConverter())
.buildAndExec(worldGuard.getExecutorService());
}

@@ -201,8 +204,6 @@ public void redefine(CommandContext args, Actor sender) throws CommandException
region = new GlobalProtectedRegion(id);
} else {
region = checkRegionFromSelection(player, id);
warnAboutDimensions(player, region);
informNewUser(player, manager, region);
}

region.copyFrom(existing);
@@ -213,7 +214,12 @@ public void redefine(CommandContext args, Actor sender) throws CommandException
AsyncCommandBuilder.wrap(task, sender)
.registerWithSupervisor(worldGuard.getSupervisor(), description)
.sendMessageAfterDelay("(Please wait... " + description + ")")
.onSuccess(String.format("Region '%s' has been updated with a new area.", region.getId()), null)
.onSuccess((Component) null,
t -> {
player.print(String.format("Region '%s' has been updated with a new area.", region.getId()));
warnAboutDimensions(player, region);
informNewUser(player, manager, region);
})
.onFailure(String.format("Failed to update the region '%s'", region.getId()), worldGuard.getExceptionConverter())
.buildAndExec(worldGuard.getExecutorService());
}
@@ -254,7 +254,7 @@ protected static void checkRegionDoesNotExist(RegionManager manager, String id,
* @param world the world
* @throws CommandException thrown if the manager is null
*/
protected static RegionManager checkRegionManager(com.sk89q.worldedit.world.World world) throws CommandException {
protected static RegionManager checkRegionManager(World world) throws CommandException {
if (!WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world).useRegions) {
throw new CommandException("Region support is disabled in the target world. " +
"It can be enabled per-world in WorldGuard's configuration files. " +
@@ -334,7 +334,7 @@ protected static void warnAboutDimensions(Actor sender, ProtectedRegion region)
* @param region the region
*/
protected static void informNewUser(Actor sender, RegionManager manager, ProtectedRegion region) {
if (manager.getRegions().size() <= 2) {
if (manager.size() <= 2) {
sender.print(SubtleFormat.wrap("(This region is NOW PROTECTED from modification from others. Don't want that? Use ")
.append(TextComponent.of("/rg flag " + region.getId() + " passthrough allow", TextColor.AQUA))
.append(TextComponent.of(")", TextColor.GRAY)));

0 comments on commit d410e1f

Please sign in to comment.
You can’t perform that action at this time.