Fix some more captions

This commit is contained in:
Alexander Söderberg 2020-07-17 21:46:15 +02:00
parent 22bd2eb238
commit 5478e70576
12 changed files with 73 additions and 56 deletions

View File

@ -30,8 +30,9 @@ import com.google.common.cache.CacheBuilder;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.Templates;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.inject.factory.PlayerBackupProfileFactory;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
@ -94,17 +95,18 @@ import java.util.concurrent.TimeUnit;
whenDone.run();
} else {
if (player != null) {
Captions.BACKUP_AUTOMATIC_STARTED.send(player);
player.sendMessage(TranslatableCaption.of("backups.backup_automatic_started"));
}
profile.createBackup().whenComplete((backup, throwable) -> {
if (throwable != null) {
if (player != null) {
Captions.BACKUP_AUTOMATIC_FAILURE.send(player, throwable.getMessage());
player.sendMessage(TranslatableCaption.of("backups.backup_automatic_failure"),
Templates.of("reason", throwable.getMessage()));
}
throwable.printStackTrace();
} else {
if (player != null) {
Captions.BACKUP_AUTOMATIC_FINISHED.send(player);
player.sendMessage(TranslatableCaption.of("backups.backup_automatic_finished"));
TaskManager.runTaskAsync(whenDone);
}
}

View File

@ -30,6 +30,7 @@ import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil;
import com.plotsquared.core.configuration.caption.Templates;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.events.TeleportCause;
@ -45,7 +46,6 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.message.PlotMessage;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.util.MainUtil;
@ -244,8 +244,8 @@ public class Area extends SubCommand {
PlotSquared.get().loadWorld(world, null);
player.sendMessage(TranslatableCaption.of("single.single_area_created"));
} else {
player.sendMessage(TranslatableCaption.of("errors.error_create",
Template.of("world", hybridPlotWorld.getWorldName())));
player.sendMessage(TranslatableCaption.of("errors.error_create"),
Template.of("world", hybridPlotWorld.getWorldName()));
}
};
singleRun.run();
@ -260,16 +260,16 @@ public class Area extends SubCommand {
}
switch (args.length) {
case 1:
Captions.COMMAND_SYNTAX
.send(player, "/plot area create [world[:id]] [<modifier>=<value>]...");
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]..."));
return false;
case 2:
switch (args[1].toLowerCase()) {
case "pos1": { // Set position 1
HybridPlotWorld area = player.getMeta("area_create_area");
if (area == null) {
Captions.COMMAND_SYNTAX.send(player,
"/plot area create [world[:id]] [<modifier>=<value>]...");
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]..."));
return false;
}
Location location = player.getLocation();
@ -277,16 +277,14 @@ public class Area extends SubCommand {
player.sendMessage(TranslatableCaption.of("set.set_attribute"),
Template.of("attribute", "area_pos1"),
Template.of("value", location.getX() + "," + location.getZ()));
MainUtil.sendMessage(player,
"You will now set pos2: /plot area create pos2"
+ "\nNote: The chosen plot size may result in the created area not exactly matching your second position.");
player.sendMessage(TranslatableCaption.of("area.set_pos2"));
return true;
}
case "pos2": // Set position 2 and finish creation for type=2 (partial)
final HybridPlotWorld area = player.getMeta("area_create_area");
if (area == null) {
Captions.COMMAND_SYNTAX.send(player,
"/plot area create [world[:id]] [<modifier>=<value>]...");
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]..."));
return false;
}
Location pos1 = player.getLocation();

View File

@ -26,6 +26,7 @@
package com.plotsquared.core.command;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.MainUtil;
@ -39,7 +40,7 @@ public class Chat extends SubCommand {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (player.getPlotAreaAbs().isForcingPlotChat()) {
MainUtil.sendMessage(player, Captions.PLOT_CHAT_FORCED);
player.sendMessage(TranslatableCaption.of("chat.plot_chat_forced"));
return true;
}
MainCommand.getInstance().toggle.chat(this, player, args, null, null);

View File

@ -44,7 +44,6 @@ import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.expiration.PlotAnalysis;
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.message.PlotMessage;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.util.ChunkManager;

View File

@ -37,7 +37,6 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.flag.implementations.PriceFlag;
import com.plotsquared.core.plot.message.PlotMessage;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.MainUtil;
@ -56,6 +55,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
@ -391,7 +391,7 @@ public class ListCmd extends SubCommand {
final List<UUIDMapping> names = PlotSquared.get().getImpromptuUUIDPipeline()
.getNames(plot.getOwners()).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS);
for (final UUIDMapping uuidMapping : names) {
PlotPlayer pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid());
PlotPlayer<?> pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid());
if (pp != null) {
message = message.text(prefix).color("$4").text(uuidMapping.getUsername()).color("$1")
.tooltip(new PlotMessage("Online").color("$4"));
@ -402,9 +402,19 @@ public class ListCmd extends SubCommand {
prefix = ", ";
}
} catch (InterruptedException | ExecutionException e) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER);
final StringBuilder playerBuilder = new StringBuilder();
final Iterator<UUID> uuidIterator = plot.getOwners().iterator();
while (uuidIterator.hasNext()) {
final UUID uuid = uuidIterator.next();
playerBuilder.append(uuid);
if (uuidIterator.hasNext()) {
playerBuilder.append(", ");
}
}
player.sendMessage(TranslatableCaption.of("errors.invalid_player"),
Templates.of("value", playerBuilder.toString()));
} catch (TimeoutException e) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
}
}
}, "/plot list " + args[0], Captions.PLOT_LIST_HEADER_PAGED.getTranslated());

View File

@ -25,7 +25,6 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
@ -48,11 +47,6 @@ public abstract class SubCommand extends Command {
setRequiredArguments(arguments);
}
public static boolean sendMessage(PlotPlayer player, Captions message, Object... args) {
message.send(player, args);
return true;
}
@Override
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,

View File

@ -27,6 +27,7 @@ package com.plotsquared.core.command;
import com.google.inject.Inject;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
@ -125,7 +126,7 @@ public class Trust extends Command {
}
currentPlot.addTrusted(uuid);
this.eventDispatcher.callTrusted(player, currentPlot, uuid, true);
MainUtil.sendMessage(player, Captions.TRUSTED_ADDED);
player.sendMessage(TranslatableCaption.of("trusted.trusted_added"));
}
}, null);
}

View File

@ -28,6 +28,8 @@ package com.plotsquared.core.command;
import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.caption.Templates;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
@ -68,11 +70,6 @@ public class Visit extends Command {
this.plotAreaManager = plotAreaManager;
}
private void visit(@Nonnull final PlotPlayer player, @Nonnull final PlotQuery query, final PlotArea sortByArea,
final RunnableVal3<Command, Runnable, Runnable> confirm, final RunnableVal2<Command, CommandResult> whenDone) {
this.visit(player, query, sortByArea, confirm, whenDone, 1);
}
private void visit(@Nonnull final PlotPlayer player, @Nonnull final PlotQuery query, final PlotArea sortByArea,
final RunnableVal3<Command, Runnable, Runnable> confirm, final RunnableVal2<Command, CommandResult> whenDone, int page) {
// We get the query once,
@ -80,7 +77,7 @@ public class Visit extends Command {
final List<Plot> unsorted = query.asList();
if (unsorted.isEmpty()) {
Captions.FOUND_NO_PLOTS.send(player);
player.sendMessage(TranslatableCaption.of("invalid.found_no_plots"));
return;
}
@ -93,7 +90,8 @@ public class Visit extends Command {
}
if (page < 1 || page > unsorted.size()) {
MainUtil.sendMessage(player, String.format("(1, %d)", unsorted.size()));
// TODO: Huh?
// MainUtil.sendMessage(player, String.format("(1, %d)", unsorted.size()));
return;
}
@ -108,28 +106,33 @@ public class Visit extends Command {
final Plot plot = plots.get(page - 1);
if (!plot.hasOwner()) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_UNOWNED)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_UNOWNED);
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
Templates.of("node", "plots.visit.unowned"));
return;
}
} else if (plot.isOwner(player.getUUID())) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OWNED) && !Permissions
.hasPermission(player, Captions.PERMISSION_HOME)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OWNED);
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
Templates.of("node", "plots.visit.owned"));
return;
}
} else if (plot.isAdded(player.getUUID())) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_SHARED)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_SHARED);
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
Templates.of("node", "plots.visit.shared"));
return;
}
} else {
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OTHER);
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
Templates.of("node", "plots.visit.other"));
return;
}
if (!plot.getFlag(UntrustedVisitFlag.class) && !Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED);
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
Templates.of("node", "plots.admin.visit.untrusted"));
return;
}
}
@ -160,8 +163,10 @@ public class Visit extends Command {
// /p v <user> <area> <page>
case 3:
if (!MathMan.isInteger(args[2])) {
Captions.NOT_VALID_NUMBER.send(player, "(1, ∞)");
Captions.COMMAND_SYNTAX.send(player, getUsage());
player.sendMessage(TranslatableCaption.of("invalid.not_valid_number"),
Templates.of("value", "(1, ∞)"));
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
Templates.of("value", getUsage()));
return CompletableFuture.completedFuture(false);
}
page = Integer.parseInt(args[2]);
@ -171,8 +176,10 @@ public class Visit extends Command {
if (page != Integer.MIN_VALUE || !MathMan.isInteger(args[1])) {
sortByArea = this.plotAreaManager.getPlotAreaByString(args[1]);
if (sortByArea == null) {
Captions.NOT_VALID_NUMBER.send(player, "(1, ∞)");
Captions.COMMAND_SYNTAX.send(player, getUsage());
player.sendMessage(TranslatableCaption.of("invalid.not_valid_number"),
Templates.of("value", "(1, ∞)"));
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
Templates.of("value", getUsage()));
return CompletableFuture.completedFuture(false);
}
@ -182,7 +189,8 @@ public class Visit extends Command {
if (throwable instanceof TimeoutException) {
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
} else if (throwable != null || uuids.size() != 1) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
Templates.of("value", getUsage()));
} else {
final UUID uuid = uuids.toArray(new UUID[0])[0];
this.visit(player, PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(), finalSortByArea, confirm, whenDone, finalPage1);
@ -227,7 +235,8 @@ public class Visit extends Command {
break;
case 0:
// /p v is invalid
Captions.COMMAND_SYNTAX.send(player, getUsage());
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
Templates.of("value", getUsage()));
return CompletableFuture.completedFuture(false);
default:
}

View File

@ -25,14 +25,12 @@
*/
package com.plotsquared.core.configuration.caption;
import net.kyori.text.Component;
import javax.annotation.Nonnull;
import java.util.Locale;
/**
* Map containing mappings between {@link TranslatableCaption captions} and
* {@link Component components}
* {@link net.kyori.adventure.text.Component components}
*/
public interface CaptionMap {

View File

@ -104,7 +104,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static com.plotsquared.core.command.SubCommand.sendMessage;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ANIMAL;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ENTITY;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MISC;

View File

@ -27,6 +27,8 @@ package com.plotsquared.core.plot.expiration;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.caption.Templates;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.events.PlotFlagAddEvent;
import com.plotsquared.core.events.PlotUnlinkEvent;
@ -40,7 +42,6 @@ import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.AnalysisFlag;
import com.plotsquared.core.plot.flag.implementations.KeepFlag;
import com.plotsquared.core.plot.message.PlotMessage;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.query.PlotQuery;
@ -417,15 +418,17 @@ public class ExpireManager {
}
}
for (UUID helper : plot.getTrusted()) {
PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
PlotPlayer<?> player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
if (player != null) {
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
player.sendMessage(TranslatableCaption.of("trusted.plot_removed_user"),
Templates.of("plot", plot.toString()));
}
}
for (UUID helper : plot.getMembers()) {
PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
PlotPlayer<?> player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
if (player != null) {
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
player.sendMessage(TranslatableCaption.of("trusted.plot_removed_user"),
Templates.of("plot", plot.toString()));
}
}
plot.deletePlot(whenDone);

View File

@ -16,6 +16,8 @@
"set.set_attribute": "<prefix><dark_aqua>Successfully set <attribute> to <value>.</dark_aqua>",
"area.set_pos2": "You will now set pos2: /plot area create pos2. Note: The chosen plot size may result in the created area not exactly matching your second position.",
"web.generating_link": "<prefix><gold>Processing plot...</gold>",
"web.generating_link_failed": "<prefix><red>Failed to generate download link!</red>",
"web.save_failed": "<prefix><red>Failed to save.</red>",
@ -223,6 +225,7 @@
"invalid.not_a_number": "<prefix><red><gray><value></gray> is not a valid number.</red>",
"errors.invalid_player": "<prefix><red>Player not found: <gray><value></gray>.</red>",
"errors.invalid_player_offline": "<prefix><red>The player must be online: <gray><player></gray>.</red>",
"errors.invalid_command_flag": "<prefix><red>Invalid command flag: </red><value></gray>",
"errors.error": "<prefix><red>An error occurred: </gray><value></gray></red>",