89 lines
2.7 KiB
Java
89 lines
2.7 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";
|
||
|
};
|
||
|
}
|
||
|
|
||
|
}
|