Replace split with substring for placeholders

This commit is contained in:
EpiCanard 2020-06-25 14:08:44 +02:00
parent 7fbac4f286
commit e833403e3c

View file

@ -72,20 +72,20 @@ public class Placeholders extends PlaceholderExpansion {
} }
if (identifier.startsWith("has_plot_")) { if (identifier.startsWith("has_plot_")) {
if (identifier.split("has_plot_").length != 2) identifier = identifier.substring("has_plot_".length());
if (identifier.isEmpty())
return ""; return "";
identifier = identifier.split("has_plot_")[1];
return pl.getPlotCount(identifier) > 0 ? return pl.getPlotCount(identifier) > 0 ?
PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanTrue() :
PlaceholderAPIPlugin.booleanFalse(); PlaceholderAPIPlugin.booleanFalse();
} }
if (identifier.startsWith("plot_count_")) { if (identifier.startsWith("plot_count_")) {
if (identifier.split("plot_count_").length != 2) identifier = identifier.substring("plot_count_".length());
if (identifier.isEmpty())
return ""; return "";
identifier = identifier.split("plot_count_")[1];
return String.valueOf(pl.getPlotCount(identifier)); return String.valueOf(pl.getPlotCount(identifier));
} }
@ -184,12 +184,11 @@ public class Placeholders extends PlaceholderExpansion {
break; break;
} }
if (identifier.startsWith("currentplot_localflag_")) { if (identifier.startsWith("currentplot_localflag_")) {
final String[] splitValues = identifier.split("currentplot_localflag_"); return getFlagValue(plot, identifier.substring("currentplot_localflag_".length()),
return (splitValues.length >= 2) ? getFlagValue(plot, splitValues[1], false) : ""; false);
} }
if (identifier.startsWith("currentplot_flag_")) { if (identifier.startsWith("currentplot_flag_")) {
final String[] splitValues = identifier.split("currentplot_flag_"); return getFlagValue(plot, identifier.substring("currentplot_flag_".length()), true);
return (splitValues.length >= 2) ? getFlagValue(plot, splitValues[1], true) : "";
} }
return ""; return "";
} }
@ -206,10 +205,11 @@ public class Placeholders extends PlaceholderExpansion {
* @return The value of flag serialized in string * @return The value of flag serialized in string
*/ */
private String getFlagValue(final Plot plot, final String flagName, final boolean inherit) { private String getFlagValue(final Plot plot, final String flagName, final boolean inherit) {
final PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName); if (flagName.isEmpty())
if (flag == null) { return "";
final PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName);
if (flag == null)
return ""; return "";
}
if (inherit) { if (inherit) {
return plot.getFlag(flag).toString(); return plot.getFlag(flag).toString();
@ -217,6 +217,5 @@ public class Placeholders extends PlaceholderExpansion {
final PlotFlag<?, ?> plotFlag = plot.getFlagContainer().queryLocal(flag.getClass()); final PlotFlag<?, ?> plotFlag = plot.getFlagContainer().queryLocal(flag.getClass());
return (plotFlag != null) ? plotFlag.getValue().toString() : ""; return (plotFlag != null) ? plotFlag.getValue().toString() : "";
} }
} }
} }