85 lines
3.9 KiB
Java
85 lines
3.9 KiB
Java
package org.dynmap.factions.config;
|
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.dynmap.factions.DynmapFactionsPlugin;
|
|
import org.dynmap.markers.MarkerIcon;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
/**
|
|
* A style usable to mark a faction area
|
|
*
|
|
* @param strokeColor <p>The color of the outer stroke</p>
|
|
* @param strokeOpacity <p>The opacity of the outer stroke</p>
|
|
* @param strokeWeight <p>The weight (priority) of the stroke</p>
|
|
* @param fillColor <p>The color of the filled-in area</p>
|
|
* @param fillOpacity <p>The opacity of the filled-in area</p>
|
|
* @param homeMarker <p>The name of the icon to use for marking faction homes</p>
|
|
* @param homeIcon <p>The icon to use for marking faction homes</p>
|
|
* @param boost
|
|
*/
|
|
public record AreaStyle(String strokeColor, double strokeOpacity, int strokeWeight, String fillColor,
|
|
double fillOpacity, String homeMarker, MarkerIcon homeIcon, boolean boost) {
|
|
|
|
/**
|
|
* Instantiates a new area style
|
|
*
|
|
* @param dynmapFactionsPlugin <p>An instance of the dynmap factions plugin</p>
|
|
* @param cfg <p>The configuration to read</p>
|
|
* @param path <p>The path of the area style to load from the config</p>
|
|
* @param def <p>The default area style to use for missing values</p>
|
|
*/
|
|
public AreaStyle(@NotNull DynmapFactionsPlugin dynmapFactionsPlugin, @NotNull FileConfiguration cfg,
|
|
@NotNull String path, @NotNull AreaStyle def) {
|
|
this(cfg.getString(path + ".strokeColor", def.strokeColor),
|
|
cfg.getDouble(path + ".strokeOpacity", def.strokeOpacity),
|
|
cfg.getInt(path + ".strokeWeight", def.strokeWeight),
|
|
cfg.getString(path + ".fillColor", def.fillColor),
|
|
cfg.getDouble(path + ".fillOpacity", def.fillOpacity),
|
|
cfg.getString(path + ".homeIcon", def.homeMarker),
|
|
getHomeIcon(dynmapFactionsPlugin, cfg.getString(path + ".homeIcon", def.homeMarker)),
|
|
cfg.getBoolean(path + ".boost", def.boost));
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new area style
|
|
*
|
|
* @param dynmapFactionsPlugin <p>An instance of the dynmap factions plugin</p>
|
|
* @param cfg <p>The configuration to read</p>
|
|
* @param path <p>The path of the area style to load from the config</p>
|
|
*/
|
|
public AreaStyle(@NotNull DynmapFactionsPlugin dynmapFactionsPlugin, @NotNull FileConfiguration cfg,
|
|
@NotNull String path) {
|
|
this(cfg.getString(path + ".strokeColor", "#FF0000"),
|
|
cfg.getDouble(path + ".strokeOpacity", 0.8),
|
|
cfg.getInt(path + ".strokeWeight", 3),
|
|
cfg.getString(path + ".fillColor", "#FF0000"),
|
|
cfg.getDouble(path + ".fillOpacity", 0.35),
|
|
cfg.getString(path + ".homeIcon", null),
|
|
getHomeIcon(dynmapFactionsPlugin, cfg.getString(path + ".homeIcon", null)),
|
|
cfg.getBoolean(path + ".boost", false));
|
|
}
|
|
|
|
/**
|
|
* Gets the icon to use for marking a faction home
|
|
*
|
|
* @param dynmapFactionsPlugin <p>An instance of the dynmap factions plugin</p>
|
|
* @param homeMarker <p>The name of the marker to get</p>
|
|
* @return <p>The marker, or null if it does not exist</p>
|
|
*/
|
|
@Nullable
|
|
private static MarkerIcon getHomeIcon(@NotNull DynmapFactionsPlugin dynmapFactionsPlugin,
|
|
@Nullable String homeMarker) {
|
|
MarkerIcon homeIcon = null;
|
|
if (homeMarker != null) {
|
|
homeIcon = dynmapFactionsPlugin.getMarkerAPI().getMarkerIcon(homeMarker);
|
|
if (homeIcon == null) {
|
|
DynmapFactionsPlugin.severe("Invalid home icon: " + homeMarker);
|
|
homeIcon = dynmapFactionsPlugin.getMarkerAPI().getMarkerIcon("blueicon");
|
|
}
|
|
}
|
|
return homeIcon;
|
|
}
|
|
|
|
}
|