Improved user feedback when pasting (creation/reset) an island

Implements https://github.com/BentoBoxWorld/BentoBox/issues/996
This commit is contained in:
Florian CUNY 2019-10-21 17:55:35 +02:00
parent ba35d7c062
commit 8692685822
3 changed files with 32 additions and 6 deletions

View File

@ -64,7 +64,7 @@ public class IslandCreateCommand extends CompositeCommand {
public boolean execute(User user, String label, List<String> args) {
// Permission check if the name is not the default one
if (!args.isEmpty()) {
String name = getPlugin().getBlueprintsManager().validate((GameModeAddon)getAddon(), args.get(0).toLowerCase(java.util.Locale.ENGLISH));
String name = getPlugin().getBlueprintsManager().validate(getAddon(), args.get(0).toLowerCase(java.util.Locale.ENGLISH));
if (name == null) {
// The blueprint name is not valid.
user.sendMessage("commands.island.create.unknown-blueprint");
@ -77,7 +77,7 @@ public class IslandCreateCommand extends CompositeCommand {
return makeIsland(user, name);
} else {
// Show panel only if there are multiple bundles available
if (getPlugin().getBlueprintsManager().getBlueprintBundles((GameModeAddon)getAddon()).size() > 1) {
if (getPlugin().getBlueprintsManager().getBlueprintBundles(getAddon()).size() > 1) {
// Show panel
IslandCreationPanel.openPanel(this, user, label);
return true;
@ -91,7 +91,7 @@ public class IslandCreateCommand extends CompositeCommand {
try {
NewIsland.builder()
.player(user)
.addon((GameModeAddon)getAddon())
.addon(getAddon())
.reason(Reason.CREATE)
.name(name)
.build();

View File

@ -1,10 +1,13 @@
package world.bentobox.bentobox.blueprints;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -149,6 +152,20 @@ public class BlueprintPaster {
pasteState = PasteState.BLOCKS;
final int pasteSpeed = plugin.getSettings().getPasteSpeed();
// If this is an island OVERWORLD paste, get the island owner.
final Optional<User> owner = Optional.ofNullable(island)
.filter(i -> location.getWorld().getEnvironment().equals(World.Environment.NORMAL))
.map(i -> User.getInstance(i.getOwner()));
// Tell the owner we're pasting blocks and how much time it might take
owner.ifPresent(user -> {
// Estimated time:
double total = blocks.size() + attached.size() + entities.size();
BigDecimal time = new BigDecimal(total / (pasteSpeed * 20.0D)).setScale(1, RoundingMode.UP);
user.sendMessage("commands.island.create.pasting.estimated-time", TextVariables.NUMBER, String.valueOf(time.doubleValue()));
// We're pasting blocks!
user.sendMessage("commands.island.create.pasting.blocks", TextVariables.NUMBER, String.valueOf(blocks.size() + attached.size()));
});
pastingTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
int count = 0;
while (pasteState.equals(PasteState.BLOCKS) && count < pasteSpeed && it.hasNext()) {
@ -169,14 +186,18 @@ public class BlueprintPaster {
// Next paste attachments
pasteState = PasteState.ATTACHMENTS;
}
if (pasteState.equals(PasteState.ATTACHMENTS) && !it2.hasNext()) {
else if (pasteState.equals(PasteState.ATTACHMENTS) && !it2.hasNext()) {
// Attachments done. Next paste entities
pasteState = PasteState.ENTITIES;
if (entities.size() != 0) {
owner.ifPresent(user -> user.sendMessage("commands.island.create.pasting.entities", TextVariables.NUMBER, String.valueOf(entities.size())));
}
}
if (pasteState.equals(PasteState.ENTITIES) && !it3.hasNext()) {
else if (pasteState.equals(PasteState.ENTITIES) && !it3.hasNext()) {
pasteState = PasteState.DONE;
owner.ifPresent(user -> user.sendMessage("commands.island.create.pasting.done"));
}
if (pasteState.equals(PasteState.DONE)) {
else if (pasteState.equals(PasteState.DONE)) {
// All done. Cancel task
// Set pos1 and 2 if this was a clipboard paste
if (island == null && clipboard != null) {

View File

@ -425,6 +425,11 @@ commands:
too-many-islands: "&cThere are too many islands in this world: there isn't enough room for yours to be created."
unable-create-island: "&cYour island could not be generated, please contact an administrator."
creating-island: "&aCreating your island, please wait a moment..."
pasting:
estimated-time: "&aThis might take up to &b[number] &aseconds."
blocks: "&aPasting &b[number] &ablocks..."
entities: "&aPasting &b[number] &aentities..."
done: "&aYour island is ready!"
pick: "&aPick an island"
unknown-blueprint: "&cThat blueprint has not been loaded yet."
info: