diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java index 6f56465d9..9cc73c8f8 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java @@ -3,6 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.flag; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.flags.FlagContainer; +import com.github.intellectualsites.plotsquared.plot.flags.InternalFlag; import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; @@ -12,6 +13,8 @@ import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.google.common.collect.ImmutableSet; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -170,30 +173,24 @@ public class FlagManager { return getSettingFlags(plot.getArea(), plot.getSettings()); } - public static HashMap, Object> getPlotFlags(PlotArea area, PlotSettings settings, - boolean ignorePluginflags) { - HashMap, Object> flags = null; - if (area != null && !area.DEFAULT_FLAGS.isEmpty()) { - flags = new HashMap<>(area.DEFAULT_FLAGS.size()); - flags.putAll(area.DEFAULT_FLAGS); + public static Collection> getPlotFlags(final Plot plot, final boolean ignorePluginFlags) { + final Map, PlotFlag> flags = new HashMap<>(); + if (plot.getArea() != null && !plot.getArea().getFlagContainer().getFlagMap().isEmpty()) { + final Map, PlotFlag> flagMap = plot.getArea().getFlagContainer().getFlagMap(); + flags.putAll(flagMap); } - if (ignorePluginflags) { - if (flags == null) { - flags = new HashMap<>(settings.flags.size()); - } - for (Map.Entry, Object> flag : settings.flags.entrySet()) { - if (flag.getKey().isReserved()) { + final Map, PlotFlag> flagMap = plot.getFlagContainer().getFlagMap(); + if (ignorePluginFlags) { + for (final PlotFlag flag : flagMap.values()) { + if (flag instanceof InternalFlag) { continue; } - flags.put(flag.getKey(), flag.getValue()); + flags.put(flag.getClass(), flag); } - return flags; - } else if (flags == null) { - return settings.flags; } else { - flags.putAll(settings.flags); + flags.putAll(flagMap); } - return flags; + return flagMap.values(); } public static Map, Object> getSettingFlags(PlotArea area, PlotSettings settings) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java index 5e2110abc..e7a2e7047 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java @@ -8,10 +8,11 @@ import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.ServerPlotFlag; +import com.github.intellectualsites.plotsquared.plot.flags.types.DoubleFlag; import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; @@ -60,6 +61,11 @@ import java.util.stream.IntStream; */ public class MainUtil { + private static final DecimalFormat FLAG_DECIMAL_FORMAT = new DecimalFormat("0"); + static { + FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340); + } + /** * If the NMS code for sending chunk updates is functional
* - E.g. If using an older version of Bukkit, or before the plugin is updated to 1.5
@@ -778,22 +784,18 @@ public class MainUtil { } StringBuilder flags = new StringBuilder(); - HashMap, Object> flagMap = - FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true); - if (flagMap.isEmpty()) { + Collection> flagCollection = FlagManager.getPlotFlags(plot, true); + if (flagCollection.isEmpty()) { flags.append(Captions.NONE.getTranslated()); } else { String prefix = ""; - for (Entry, Object> entry : flagMap.entrySet()) { - Object value = entry.getValue(); - if (entry.getKey() instanceof DoubleFlag && !Settings.General.SCIENTIFIC) { - DecimalFormat df = new DecimalFormat("0"); - df.setMaximumFractionDigits(340); - value = df.format(value); + for (final PlotFlag flag : flagCollection) { + Object value = flag.getValue(); + if (flag instanceof DoubleFlag && !Settings.General.SCIENTIFIC) { + value = FLAG_DECIMAL_FORMAT.format(value); } - flags.append(prefix).append(CaptionUtility - .format(Captions.PLOT_FLAG_LIST.getTranslated(), entry.getKey().getName(), - value)); + flags.append(prefix).append(CaptionUtility.format(Captions.PLOT_FLAG_LIST.getTranslated(), + flag.getName(), value)); prefix = ", "; } }