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

View File

@ -26,12 +26,12 @@
package com.plotsquared.core.util; package com.plotsquared.core.util;
import com.plotsquared.core.PlotSquared; 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.ConfigurationSection;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.plot.BlockBucket; import com.plotsquared.core.plot.BlockBucket;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import net.kyori.adventure.text.minimessage.Template;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -108,23 +108,20 @@ public final class LegacyConverter {
.toArray(BlockState[]::new); .toArray(BlockState[]::new);
} }
private void convertBlock(@Nonnull final ConfigurationSection section, private void convertBlock(@Nonnull final ConfigurationSection section, @Nonnull final String key, @Nonnull final String block) {
@Nonnull final String key, @Nonnull final String block) {
final BlockBucket bucket = this.blockToBucket(block); final BlockBucket bucket = this.blockToBucket(block);
this.setString(section, key, bucket); this.setString(section, key, bucket);
logger.info(CaptionUtility ConsolePlayer.getConsole().sendMessage(TranslatableCaption.of("legacyconfig.legacy_config_replaced"), Template.of("value1", block),
.format(ConsolePlayer.getConsole(), Captions.LEGACY_CONFIG_REPLACED.getTranslated(), Template.of("value2", bucket.toString()));
block, bucket.toString()));
} }
private void convertBlockList(@Nonnull final ConfigurationSection section, private void convertBlockList(@Nonnull final ConfigurationSection section, @Nonnull final String key, @Nonnull final List<String> blockList) {
@Nonnull final String key, @Nonnull final List<String> blockList) {
final BlockState[] blocks = this.splitBlockList(blockList); final BlockState[] blocks = this.splitBlockList(blockList);
final BlockBucket bucket = this.blockListToBucket(blocks); final BlockBucket bucket = this.blockListToBucket(blocks);
this.setString(section, key, bucket); this.setString(section, key, bucket);
logger.info(CaptionUtility ConsolePlayer.getConsole()
.format(ConsolePlayer.getConsole(), Captions.LEGACY_CONFIG_REPLACED.getTranslated(), .sendMessage(TranslatableCaption.of("legacyconfig.legacy_config_replaced"), Template.of("value1", plotBlockArrayString(blocks)),
plotBlockArrayString(blocks), bucket.toString())); Template.of("value2", bucket.toString()));
} }
private String plotBlockArrayString(@Nonnull final BlockState[] blocks) { 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_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_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_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>", "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_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_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_footer": "<dark_gray><strikethrough>---------<reset> <gold>PlotSquared Flags </gold><dark_gray><strikethrough>---------<reset>",
"flag.flag_info_color_key": "<gold>", "flag.flag_list_categories": "<gold><category>: </gold>",
"flag.flag_info_color_value": "<gray>", "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_name": "<gray>Name: </gray>",
"flag.flag_info_category": "<gray>Category: </gray>", "flag.flag_info_category": "<gray>Category: </gray>",
"flag.flag_info_description": "<gray>Description: </gray>", "flag.flag_info_description": "<gray>Description: </gray>",