package net.knarcraft.dynmapcitizens.settings; import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.property.Icon; import org.bukkit.configuration.file.FileConfiguration; import org.dynmap.DynmapAPI; import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerIcon; import java.util.HashMap; import java.util.Map; /** * A representation of all settings not specific to one trait */ public class GlobalSettings { private final Map markerIcons = new HashMap<>(); private long updateMovingNPCDelay; private long updateAllMarkersDelay; /** * Loads all global settings from the given configuration * * @param configuration

The configuration to load from

*/ public void load(FileConfiguration configuration) { DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI(); MarkerAPI markerAPI = dynmapAPI.getMarkerAPI(); //Load the icons to use for (Icon icon : Icon.values()) { markerIcons.put(icon, markerAPI.getMarkerIcon(configuration.getString("icon." + icon.name(), getDefaultIconName(icon)))); } updateMovingNPCDelay = configuration.getLong("timer.updateMovingNPCDelay", 10); updateAllMarkersDelay = configuration.getLong("timer.updateAllMarkersDelay", 300); } /** * Gets the marker icons to use * * @return

The marker icons to use

*/ public Map getMarkerIcons() { return new HashMap<>(markerIcons); } /** * Gets the delay to wait between each time a moving NPC's marker is updated * * @return

The update delay for moving NPCs

*/ public long getUpdateMovingNPCDelay() { return updateMovingNPCDelay; } /** * Gets the delay to wait between each time all markers are updated * * @return

The update delay for all markers

*/ public long getUpdateAllMarkersDelay() { return updateAllMarkersDelay; } /** * Gets the default icon name for the given icon identifier * * @param icon

The icon identifier to get the icon for

* @return

The default icon name

*/ private String getDefaultIconName(Icon icon) { //The advantage of this switch over a map is that it will throw an error if a case is missing return switch (icon) { case QUEST_GIVER -> "exclamation"; case QUEST_DELIVER -> "basket"; case QUEST_KILL -> "skull"; case QUEST_INTERACT -> "comment"; case QUEST_CHAIN -> "caution"; case BLACKSMITH -> "hammer"; case SENTINEL -> "shield"; case MINSTREL -> "theater"; }; } }