DynmapCitizens/src/main/java/net/knarcraft/dynmapcitizens/settings/GlobalSettings.java
EpicKnarvik97 88bf1b28c2
All checks were successful
KnarCraft/DynmapCitizens/pipeline/head This commit looks good
Adds icons for trader NPCs
2023-08-21 22:38:07 +02:00

90 lines
2.8 KiB
Java

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<Icon, MarkerIcon> markerIcons = new HashMap<>();
private long updateMovingNPCDelay;
private long updateAllMarkersDelay;
/**
* Loads all global settings from the given configuration
*
* @param configuration <p>The configuration to load from</p>
*/
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 <p>The marker icons to use</p>
*/
public Map<Icon, MarkerIcon> getMarkerIcons() {
return new HashMap<>(markerIcons);
}
/**
* Gets the delay to wait between each time a moving NPC's marker is updated
*
* @return <p>The update delay for moving NPCs</p>
*/
public long getUpdateMovingNPCDelay() {
return updateMovingNPCDelay;
}
/**
* Gets the delay to wait between each time all markers are updated
*
* @return <p>The update delay for all markers</p>
*/
public long getUpdateAllMarkersDelay() {
return updateAllMarkersDelay;
}
/**
* Gets the default icon name for the given icon identifier
*
* @param icon <p>The icon identifier to get the icon for</p>
* @return <p>The default icon name</p>
*/
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";
case TRADER -> "coins";
};
}
}