mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 14:46:45 +01:00
More json progress
This commit is contained in:
parent
18f630ba15
commit
6970dfa5f8
@ -30,6 +30,7 @@ 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.Templates;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.events.PlotFlagAddEvent;
|
||||
import com.plotsquared.core.events.PlotFlagRemoveEvent;
|
||||
@ -136,7 +137,7 @@ public final class FlagCommand extends Command {
|
||||
TranslatableCaption.of("flag.flag_parse_error"),
|
||||
Template.of("flag_name", flag.getName()),
|
||||
Template.of("flag_value", e.getValue()),
|
||||
Template.of("error", e.getErrorMessage())
|
||||
Templates.of(player, "error", e.getErrorMessage(), e.getTemplates())
|
||||
);
|
||||
return false;
|
||||
} catch (final Exception e) {
|
||||
@ -333,7 +334,7 @@ public final class FlagCommand extends Command {
|
||||
TranslatableCaption.of("flag.flag_parse_error"),
|
||||
Template.of("flag_name", plotFlag.getName()),
|
||||
Template.of("flag_value", e.getValue()),
|
||||
Template.of("error", e.getErrorMessage())
|
||||
Templates.of(player, "error", e.getErrorMessage(), e.getTemplates())
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -392,7 +393,7 @@ public final class FlagCommand extends Command {
|
||||
TranslatableCaption.of("flag.flag_parse_error"),
|
||||
Template.of("flag_name", plotFlag.getName()),
|
||||
Template.of("flag_value", e.getValue()),
|
||||
Template.of("error", e.getErrorMessage())
|
||||
Templates.of(player, "error", e.getErrorMessage(), e.getTemplates())
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -462,7 +463,7 @@ public final class FlagCommand extends Command {
|
||||
TranslatableCaption.of("flag.flag_parse_error"),
|
||||
Template.of("flag_name", flag.getName()),
|
||||
Template.of("flag_value", e.getValue()),
|
||||
Template.of("error", e.getErrorMessage())
|
||||
Templates.of(player, "error", e.getErrorMessage(), e.getTemplates())
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -576,32 +577,23 @@ public final class FlagCommand extends Command {
|
||||
if (plotFlag != null) {
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_header"));
|
||||
// Flag name
|
||||
new PlotMessage(Captions.FLAG_INFO_NAME.getTranslated())
|
||||
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text(plotFlag.getName())
|
||||
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player);
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_name"), Template.of("flag", plotFlag.getName()));
|
||||
// Flag category
|
||||
new PlotMessage(Captions.FLAG_INFO_CATEGORY.getTranslated())
|
||||
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated())
|
||||
.text(plotFlag.getFlagCategory().getTranslated())
|
||||
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player);
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_category"),
|
||||
Templates.of(player, "value", plotFlag.getFlagCategory()));
|
||||
// Flag description
|
||||
new PlotMessage(Captions.FLAG_INFO_DESCRIPTION.getTranslated())
|
||||
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).send(player);
|
||||
new PlotMessage(plotFlag.getFlagDescription().getTranslated())
|
||||
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player);
|
||||
// TODO maybe merge and \n instead?
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_description"));
|
||||
player.sendMessage(plotFlag.getFlagDescription());
|
||||
// Flag example
|
||||
new PlotMessage(Captions.FLAG_INFO_EXAMPLE.getTranslated())
|
||||
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated())
|
||||
.text("/plot flag set " + plotFlag.getName() + " " + plotFlag.getExample())
|
||||
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated())
|
||||
.suggest("/plot flag set " + plotFlag.getName() + " " + plotFlag.getExample())
|
||||
.send(player);
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_example"),
|
||||
Template.of("flag", plotFlag.getName()),
|
||||
Template.of("value", plotFlag.getExample()));
|
||||
// Default value
|
||||
final String defaultValue = player.getLocation().getPlotArea().getFlagContainer()
|
||||
.getFlagErased(plotFlag.getClass()).toString();
|
||||
new PlotMessage(Captions.FLAG_INFO_DEFAULT_VALUE.getTranslated())
|
||||
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text(defaultValue)
|
||||
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player);
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_default_value"),
|
||||
Template.of("value", defaultValue));
|
||||
// Footer. Done this way to prevent the duplicate-message-thingy from catching it
|
||||
player.sendMessage(TranslatableCaption.of("flag.flag_info_footer"));
|
||||
}
|
||||
|
@ -26,13 +26,15 @@
|
||||
package com.plotsquared.core.plot.flag;
|
||||
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.configuration.caption.CaptionUtility;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
public class FlagParseException extends Exception {
|
||||
|
||||
private final PlotFlag<?, ?> flag;
|
||||
private final String value;
|
||||
private final String errorMessage;
|
||||
private final Caption errorMessage;
|
||||
private final Template[] templates;
|
||||
|
||||
/**
|
||||
* Construct a new flag parse exception to indicate that an attempt to parse a plot
|
||||
@ -44,12 +46,13 @@ public class FlagParseException extends Exception {
|
||||
* @param args Arguments used to format the error message
|
||||
*/
|
||||
public FlagParseException(final PlotFlag<?, ?> flag, final String value,
|
||||
final Caption errorMessage, final Object... args) {
|
||||
final Caption errorMessage, final Template... args) {
|
||||
super(String.format("Failed to parse flag of type '%s'. Value '%s' was not accepted.",
|
||||
flag.getName(), value));
|
||||
this.flag = flag;
|
||||
this.value = value;
|
||||
this.errorMessage = CaptionUtility.format(null, errorMessage, args);
|
||||
this.errorMessage = errorMessage;
|
||||
this.templates = args;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,8 +78,15 @@ public class FlagParseException extends Exception {
|
||||
*
|
||||
* @return Error message.
|
||||
*/
|
||||
public String getErrorMessage() {
|
||||
public Caption getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the templates that were supplied by the flag instance.
|
||||
* @return Message templates.
|
||||
*/
|
||||
public Template[] getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
|
@ -62,8 +62,20 @@ public abstract class PlotFlag<T, F extends PlotFlag<T, F>> {
|
||||
this.flagDescription =
|
||||
Preconditions.checkNotNull(flagDescription, "flag description may not be null");
|
||||
// Parse flag name
|
||||
// noinspection unchecked
|
||||
this.flagName = getFlagName(this.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the flag.
|
||||
* @param flagClass Flag class
|
||||
* @param <T> Value type
|
||||
* @param <F> Flag type
|
||||
* @return The name of the flag implemented by the given class
|
||||
*/
|
||||
public static <T, F extends PlotFlag<T, F>> String getFlagName(Class<F> flagClass) {
|
||||
final StringBuilder flagName = new StringBuilder();
|
||||
final char[] chars = this.getClass().getSimpleName().replace("Flag", "").toCharArray();
|
||||
final char[] chars = flagClass.getSimpleName().replace("Flag", "").toCharArray();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
if (i == 0) {
|
||||
flagName.append(Character.toLowerCase(chars[i]));
|
||||
@ -73,7 +85,7 @@ public abstract class PlotFlag<T, F extends PlotFlag<T, F>> {
|
||||
flagName.append(chars[i]);
|
||||
}
|
||||
}
|
||||
this.flagName = flagName.toString();
|
||||
return flagName.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.plotsquared.core.plot.flag.types;
|
||||
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.configuration.caption.Templates;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.plot.flag.FlagParseException;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
@ -51,8 +52,9 @@ public abstract class NumberFlag<N extends Number & Comparable<N>, F extends Plo
|
||||
@Override public F parse(@Nonnull String input) throws FlagParseException {
|
||||
final N parsed = parseNumber(input);
|
||||
if (parsed.compareTo(minimum) < 0 || parsed.compareTo(maximum) > 0) {
|
||||
throw new FlagParseException(this, input, TranslatableCaption.of("invalid.number_not_in_range"), minimum,
|
||||
maximum);
|
||||
throw new FlagParseException(this, input, TranslatableCaption.of("invalid.number_not_in_range"),
|
||||
Templates.of("min", minimum),
|
||||
Templates.of("max", maximum));
|
||||
}
|
||||
return flagOf(parsed);
|
||||
|
||||
|
@ -294,11 +294,14 @@ public class EventDispatcher {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.toString(),
|
||||
false) || !(!notifyPerms || MainUtil
|
||||
.sendMessage(player, Captions.FLAG_TUTORIAL_USAGE,
|
||||
Captions.FLAG_USE.getTranslated()));
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.toString(), false)) {
|
||||
return true;
|
||||
}
|
||||
if (notifyPerms) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.flag_tutorial_usage"),
|
||||
Template.of("flag", PlaceFlag.getFlagName(UseFlag.class)));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case TRIGGER_PHYSICAL: {
|
||||
if (plot == null) {
|
||||
@ -347,9 +350,12 @@ public class EventDispatcher {
|
||||
false)) {
|
||||
return true;
|
||||
}
|
||||
return !(!notifyPerms || MainUtil.sendMessage(player, Captions.FLAG_TUTORIAL_USAGE,
|
||||
Captions.FLAG_MOB_PLACE.getTranslated() + '/' + Captions.FLAG_PLACE
|
||||
.getTranslated()));
|
||||
if (notifyPerms) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.flag_tutorial_usage"),
|
||||
Template.of("flag", PlotFlag.getFlagName(MobPlaceFlag.class)
|
||||
+ '/' + PlotFlag.getFlagName(PlaceFlag.class)));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case PLACE_MISC: {
|
||||
if (plot == null) {
|
||||
@ -375,9 +381,12 @@ public class EventDispatcher {
|
||||
false)) {
|
||||
return true;
|
||||
}
|
||||
return !(!notifyPerms || MainUtil.sendMessage(player, Captions.FLAG_TUTORIAL_USAGE,
|
||||
Captions.FLAG_MISC_PLACE.getTranslated() + '/' + Captions.FLAG_PLACE
|
||||
.getTranslated()));
|
||||
if (notifyPerms) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.flag_tutorial_usage"),
|
||||
Template.of("flag", PlotFlag.getFlagName(MiscPlaceFlag.class)
|
||||
+ '/' + PlotFlag.getFlagName(PlaceFlag.class)));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case PLACE_VEHICLE:
|
||||
if (plot == null) {
|
||||
|
@ -514,11 +514,11 @@
|
||||
"flag.flag_info_footer": "<dark_gray><strikethrough>---------<reset> <gold>PlotSquared Flags </gold><dark_gray><strikethrough>---------<reset>",
|
||||
"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_name": "<gray>Name: <gold><flag></gold></gray>",
|
||||
"flag.flag_info_category": "<gray>Category: </gray>",
|
||||
"flag.flag_info_description": "<gray>Description: </gray>",
|
||||
"flag.flag_info_example": "<gray>Example: </gray>",
|
||||
"flag.flag_info_default_value": "<gray>Default Value: </gray>",
|
||||
"flag.flag_info_example": "<gray>Example: <click:suggest_command:/plot flag set <flag> <value>><gold>/plot flag set <flag> <value><click></gold></gray>",
|
||||
"flag.flag_info_default_value": "<gray>Default Value: <value></gray>",
|
||||
|
||||
"flags.flag_category_string": "<gray>String Flags</gray>",
|
||||
"flags.flag_category_integers": "<gray>Integer Flags</gray>",
|
||||
|
@ -27,8 +27,13 @@ package com.plotsquared.core.plot;
|
||||
|
||||
import com.plotsquared.core.database.AbstractDBTest;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.UseFlag;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class FlagTest {
|
||||
|
||||
@ -58,4 +63,9 @@ public class FlagTest {
|
||||
// assertEquals(flag.get(), flag2.get());
|
||||
// }
|
||||
// }
|
||||
|
||||
@Test public void testFlagName() {
|
||||
String flagName = PlotFlag.getFlagName(UseFlag.class);
|
||||
assertEquals("use", flagName);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user