mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 23:26:45 +01:00
Fix MainUtil.java
This commit is contained in:
parent
eeb814fb8f
commit
948bd39224
@ -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<Flag<?>, Object> getPlotFlags(PlotArea area, PlotSettings settings,
|
||||
boolean ignorePluginflags) {
|
||||
HashMap<Flag<?>, 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<PlotFlag<?, ?>> getPlotFlags(final Plot plot, final boolean ignorePluginFlags) {
|
||||
final Map<Class<?>, PlotFlag<?, ?>> flags = new HashMap<>();
|
||||
if (plot.getArea() != null && !plot.getArea().getFlagContainer().getFlagMap().isEmpty()) {
|
||||
final Map<Class<?>, PlotFlag<?, ?>> flagMap = plot.getArea().getFlagContainer().getFlagMap();
|
||||
flags.putAll(flagMap);
|
||||
}
|
||||
if (ignorePluginflags) {
|
||||
if (flags == null) {
|
||||
flags = new HashMap<>(settings.flags.size());
|
||||
}
|
||||
for (Map.Entry<Flag<?>, Object> flag : settings.flags.entrySet()) {
|
||||
if (flag.getKey().isReserved()) {
|
||||
final Map<Class<?>, 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<Flag<?>, Object> getSettingFlags(PlotArea area, PlotSettings settings) {
|
||||
|
@ -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<br>
|
||||
* - E.g. If using an older version of Bukkit, or before the plugin is updated to 1.5<br>
|
||||
@ -778,22 +784,18 @@ public class MainUtil {
|
||||
}
|
||||
|
||||
StringBuilder flags = new StringBuilder();
|
||||
HashMap<Flag<?>, Object> flagMap =
|
||||
FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true);
|
||||
if (flagMap.isEmpty()) {
|
||||
Collection<PlotFlag<?, ?>> flagCollection = FlagManager.getPlotFlags(plot, true);
|
||||
if (flagCollection.isEmpty()) {
|
||||
flags.append(Captions.NONE.getTranslated());
|
||||
} else {
|
||||
String prefix = "";
|
||||
for (Entry<Flag<?>, 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 = ", ";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user