Added AdminPurgeStatusCommand and improved some purge-related messages

Implements https://github.com/BentoBoxWorld/BentoBox/issues/1254
This commit is contained in:
Florian CUNY 2020-04-04 15:31:22 +02:00
parent c1741aa37f
commit 2c7316ba21
5 changed files with 84 additions and 12 deletions

View File

@ -37,6 +37,7 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
setOnlyPlayer(false);
setParametersHelp("commands.admin.purge.parameters");
setDescription("commands.admin.purge.description");
new AdminPurgeStatusCommand(this);
new AdminPurgeStopCommand(this);
new AdminPurgeUnownedCommand(this);
new AdminPurgeProtectCommand(this);
@ -100,7 +101,8 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
getIslands().getIslandById(it.next()).ifPresent(i -> {
getIslands().deleteIsland(i, true, null);
count++;
getPlugin().log(count + " islands purged");
String percentage = String.format("%.1f", (((float) count)/getPurgeableIslandsCount() * 100));
getPlugin().log(count + " islands purged out of " + getPurgeableIslandsCount() + " (" + percentage + " %)");
});
} else {
user.sendMessage("commands.admin.purge.completed");
@ -155,4 +157,22 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
void setIslands(Set<String> islands) {
this.islands = islands;
}
/**
* Returns the amount of purged islands.
* @return the amount of islands that have been purged.
* @since 1.13.0
*/
int getPurgedIslandsCount() {
return this.count;
}
/**
* Returns the amount of islands that can be purged.
* @return the amount of islands that can be purged.
* @since 1.13.0
*/
int getPurgeableIslandsCount() {
return this.islands.size();
}
}

View File

@ -0,0 +1,50 @@
package world.bentobox.bentobox.api.commands.admin.purge;
import org.bukkit.command.Command;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import java.util.List;
/**
* Displays the current status and progress of the purge.
* @since 1.13.0
* @author Poslovitch
*/
public class AdminPurgeStatusCommand extends CompositeCommand {
public AdminPurgeStatusCommand(AdminPurgeCommand parent) {
super(parent, "status");
}
@Override
public void setup() {
inheritPermission();
setOnlyPlayer(false);
setParametersHelp("commands.admin.purge.status.parameters");
setDescription("commands.admin.purge.status.description");
}
@Override
public boolean execute(User user, String label, List<String> args) {
if (!args.isEmpty()) {
// Show help
showHelp(this, user);
return false;
}
AdminPurgeCommand parentCommand = ((AdminPurgeCommand)getParent());
if (parentCommand.isInPurge()) {
int purged = parentCommand.getPurgedIslandsCount();
int purgeable = parentCommand.getPurgeableIslandsCount();
user.sendMessage("commands.admin.purge.purge-in-progress", TextVariables.LABEL, this.getTopLabel());
user.sendMessage("commands.admin.purge.status.status",
"[purged]", String.valueOf(purged),
"[purgeable]", String.valueOf(purgeable),
"[percentage]", String.format("%.1f", (((float) purged)/purgeable) * 100));
} else {
user.sendMessage("commands.admin.purge.no-purge-in-progress");
}
return true;
}
}

View File

@ -31,7 +31,7 @@ public class AdminPurgeStopCommand extends CompositeCommand {
parentCommand.stop();
return true;
} else {
user.sendMessage("commands.admin.purge.stop.no-purge-in-progress");
user.sendMessage("commands.admin.purge.no-purge-in-progress");
return false;
}
}

View File

@ -81,18 +81,21 @@ commands:
confirm: "&d Type &b /[label] purge confirm &d to start purging"
completed: "&a Purging stopped."
see-console-for-status: "&a Purge started. See console for status or use &b /[label] purge status&a."
no-purge-in-progress: "&c There is currently no purge in progress."
protect:
description: "Toggle island purge protection"
description: "toggle island purge protection"
move-to-island: "&c Move to an island first!"
protecting: "&a Purge-protecting island"
unprotecting: "&a Removing purge protection"
stop:
description: "Stop a purge in progress"
description: "stop a purge in progress"
stopping: "Stopping the purge"
no-purge-in-progress: "&c No purge in progress!"
unowned:
description: "Purge unowned islands - requires confirmation"
unowned-islands: "&d Found [number] islands"
description: "purge unowned islands"
unowned-islands: "&a Found &b [number] &a unowned islands."
status:
description: "displays the status of the purge"
status: "&b [purged] &a islands purged out of &b [purgeable] &7(&b[percentage] %&7)&a."
team:
add:

View File

@ -121,7 +121,7 @@ public class AdminPurgeCommandTest {
assertFalse(apc.isOnlyPlayer());
assertEquals("commands.admin.purge.parameters", apc.getParameters());
assertEquals("commands.admin.purge.description", apc.getDescription());
assertEquals(4, apc.getSubCommands().size());
assertEquals(5, apc.getSubCommands().size());
}
@ -293,8 +293,8 @@ public class AdminPurgeCommandTest {
testExecuteUserStringListOfStringIslandsFound();
assertTrue(apc.execute(user, "", Collections.singletonList("confirm")));
verify(im).deleteIsland(eq(island), eq(true), eq(null));
verify(plugin).log(eq("1 islands purged"));
verify(user).sendMessage(eq("commands.admin.purge.see-console-for-status"));
verify(plugin).log(any());
verify(user).sendMessage(eq("commands.admin.purge.see-console-for-status"), eq("[label]"), eq("bsb"));
}
/**
@ -348,8 +348,7 @@ public class AdminPurgeCommandTest {
public void testSetUser() {
apc.setUser(user);
apc.removeIslands();
verify(user, Mockito.times(2)).sendMessage(any());
verify(user, Mockito.times(1)).sendMessage(any());
}
}