Bit more json

This commit is contained in:
dordsor21 2020-08-06 14:06:19 +01:00
parent f68eb9c778
commit 18f630ba15
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
3 changed files with 33 additions and 39 deletions

View File

@ -26,9 +26,10 @@
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.caption.StaticCaption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.PlotFlagAddEvent;
import com.plotsquared.core.events.PlotFlagRemoveEvent;
@ -49,6 +50,7 @@ import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.helpmenu.HelpMenu;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.Template;
import javax.annotation.Nonnull;
@ -80,7 +82,7 @@ public final class FlagCommand extends Command {
super(MainCommand.getInstance(), true);
}
private static boolean sendMessage(PlotPlayer player, Captions message, Object... args) {
private static boolean sendMessage(PlotPlayer<?> player, Captions message, Object... args) {
player.sendMessage(
TranslatableCaption.of("commandconfig.command_syntax"),
Template.of("value", "/plot flag <set | remove | add | list | info> <flag> <value>")
@ -88,7 +90,7 @@ public final class FlagCommand extends Command {
return true;
}
private static boolean checkPermValue(@Nonnull final PlotPlayer player,
private static boolean checkPermValue(@Nonnull final PlotPlayer<?> player,
@Nonnull final PlotFlag<?, ?> flag, @Nonnull String key, @Nonnull String value) {
key = key.toLowerCase();
value = value.toLowerCase();
@ -156,7 +158,7 @@ public final class FlagCommand extends Command {
*
* @return true if the player is allowed to modify the flags at their current location
*/
private static boolean checkRequirements(@Nonnull final PlotPlayer player) {
private static boolean checkRequirements(@Nonnull final PlotPlayer<?> player) {
final Location location = player.getLocation();
final Plot plot = location.getPlotAbs();
if (plot == null) {
@ -186,9 +188,9 @@ public final class FlagCommand extends Command {
* @param arg String to extract flag from
* @return The flag, if found, else null
*/
@Nullable private static PlotFlag<?, ?> getFlag(@Nonnull final PlotPlayer player,
@Nullable private static PlotFlag<?, ?> getFlag(@Nonnull final PlotPlayer<?> player,
@Nonnull final String arg) {
if (arg != null && arg.length() > 0) {
if (arg.length() > 0) {
final PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(arg);
if (flag instanceof InternalFlag || flag == null) {
boolean suggested = false;
@ -231,7 +233,7 @@ public final class FlagCommand extends Command {
}
@Override
public Collection<Command> tab(final PlotPlayer player, final String[] args,
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args,
final boolean space) {
if (args.length == 1) {
return Stream
@ -293,7 +295,7 @@ public final class FlagCommand extends Command {
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.set.flag")
public void set(final Command command, final PlotPlayer player, final String[] args,
public void set(final Command command, final PlotPlayer<?> player, final String[] args,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
if (!checkRequirements(player)) {
@ -346,7 +348,7 @@ public final class FlagCommand extends Command {
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.flag.add")
public void add(final Command command, PlotPlayer player, final String[] args,
public void add(final Command command, PlotPlayer<?> player, final String[] args,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
if (!checkRequirements(player)) {
@ -410,7 +412,7 @@ public final class FlagCommand extends Command {
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.flag.add")
public void remove(final Command command, PlotPlayer player, final String[] args,
public void remove(final Command command, PlotPlayer<?> player, final String[] args,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
if (!checkRequirements(player)) {
@ -517,7 +519,7 @@ public final class FlagCommand extends Command {
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.flag.list")
public void list(final Command command, final PlotPlayer player, final String[] args,
public void list(final Command command, final PlotPlayer<?> player, final String[] args,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
if (!checkRequirements(player)) {
@ -529,7 +531,7 @@ public final class FlagCommand extends Command {
if (plotFlag instanceof InternalFlag) {
continue;
}
final String category = plotFlag.getFlagCategory().getTranslated();
final String category = MINI_MESSAGE.stripTokens(plotFlag.getFlagCategory().getComponent(player));
final Collection<String> flagList =
flags.computeIfAbsent(category, k -> new ArrayList<>());
flagList.add(plotFlag.getName());
@ -537,21 +539,16 @@ public final class FlagCommand extends Command {
for (final Map.Entry<String, ArrayList<String>> entry : flags.entrySet()) {
Collections.sort(entry.getValue());
PlotMessage plotMessage = new PlotMessage(entry.getKey() + ": ")
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated());
Component category =
MINI_MESSAGE.parse(TranslatableCaption.of("flag.flag_list_categories").getComponent(player), Template.of("category", entry.getKey()));
final Iterator<String> flagIterator = entry.getValue().iterator();
while (flagIterator.hasNext()) {
final String flag = flagIterator.next();
plotMessage = plotMessage.text(flag).command("/plot flag info " + flag)
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).tooltip(
new PlotMessage(Captions.FLAG_LIST_SEE_INFO.getTranslated())
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()));
if (flagIterator.hasNext()) {
plotMessage = plotMessage.text(", ")
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated());
category.append(MINI_MESSAGE
.parse(TranslatableCaption.of("flag.flag_list_flag").getComponent(player), Template.of("command", "/plot flag info " + flag),
Template.of("flag", flag), Template.of("suffix", flagIterator.hasNext() ? ", " : "")));
}
}
plotMessage.send(player);
player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(category)));
}
}
@ -562,7 +559,7 @@ public final class FlagCommand extends Command {
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.flag.info")
public void info(final Command command, final PlotPlayer player, final String[] args,
public void info(final Command command, final PlotPlayer<?> player, final String[] args,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
if (!checkRequirements(player)) {

View File

@ -26,12 +26,12 @@
package com.plotsquared.core.util;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.plot.BlockBucket;
import com.sk89q.worldedit.world.block.BlockState;
import net.kyori.adventure.text.minimessage.Template;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -108,23 +108,20 @@ public final class LegacyConverter {
.toArray(BlockState[]::new);
}
private void convertBlock(@Nonnull final ConfigurationSection section,
@Nonnull final String key, @Nonnull final String block) {
private void convertBlock(@Nonnull final ConfigurationSection section, @Nonnull final String key, @Nonnull final String block) {
final BlockBucket bucket = this.blockToBucket(block);
this.setString(section, key, bucket);
logger.info(CaptionUtility
.format(ConsolePlayer.getConsole(), Captions.LEGACY_CONFIG_REPLACED.getTranslated(),
block, bucket.toString()));
ConsolePlayer.getConsole().sendMessage(TranslatableCaption.of("legacyconfig.legacy_config_replaced"), Template.of("value1", block),
Template.of("value2", bucket.toString()));
}
private void convertBlockList(@Nonnull final ConfigurationSection section,
@Nonnull final String key, @Nonnull final List<String> blockList) {
private void convertBlockList(@Nonnull final ConfigurationSection section, @Nonnull final String key, @Nonnull final List<String> blockList) {
final BlockState[] blocks = this.splitBlockList(blockList);
final BlockBucket bucket = this.blockListToBucket(blocks);
this.setString(section, key, bucket);
logger.info(CaptionUtility
.format(ConsolePlayer.getConsole(), Captions.LEGACY_CONFIG_REPLACED.getTranslated(),
plotBlockArrayString(blocks), bucket.toString()));
ConsolePlayer.getConsole()
.sendMessage(TranslatableCaption.of("legacyconfig.legacy_config_replaced"), Template.of("value1", plotBlockArrayString(blocks)),
Template.of("value2", bucket.toString()));
}
private String plotBlockArrayString(@Nonnull final BlockState[] blocks) {

View File

@ -494,7 +494,7 @@
"legacyconfig.legacy_config_found": "<prefix><green>A legacy configuration file was detected. Conversion will be attempted.</green>",
"legacyconfig.legacy_config_backup": "<prefix><gold>A copy of worlds.yml has been saved in the file worlds.yml.old</gold>.",
"legacyconfig.legacy_config_replaced": "<prefix><gray>> <value1> has been replaced with <value2></gray>",
"legacyconfig.legacy_config_replaced": "<prefix><gray><value1> has been replaced with <value2></gray>",
"legacyconfig.legacy_config_done": "<prefix><green>The conversion has finished. PlotSquared will now be disabled and the new configuration file will be used at next startup. Please review the new worlds.yml file. Please note that schematics will not be converted, as we are now using WorldEdit to handle schematics. You need to re-generate the schematics.</green>",
"legacyconfig.legacy_config_conversion_failed": "<prefix><red>Failed to convert the legacy configuration file. See stack trace for information.</red>",
@ -512,8 +512,8 @@
"flag.flag_parse_error": "<red>Failed to parse flag </red><gray><flag_name><red>, value </red><gray><flag_value></gray><red>: <error></red>",
"flag.flag_info_header": "<dark_gray><strikethrough>---------<reset> <gold>PlotSquared Flags </gold><dark_gray><strikethrough>---------<reset>",
"flag.flag_info_footer": "<dark_gray><strikethrough>---------<reset> <gold>PlotSquared Flags </gold><dark_gray><strikethrough>---------<reset>",
"flag.flag_info_color_key": "<gold>",
"flag.flag_info_color_value": "<gray>",
"flag.flag_list_categories": "<gold><category>: </gold>",
"flag.flag_list_flag": "<click:run_command:<command>><hover:show_text:<grey>Click to view information about the flag.</grey>><gray><flag></grey></hover></click><grey><suffix></grey>",
"flag.flag_info_name": "<gray>Name: </gray>",
"flag.flag_info_category": "<gray>Category: </gray>",
"flag.flag_info_description": "<gray>Description: </gray>",