Implements configuration for common configuration values
Makes "enabled", marker set id, marker set priority, hide markers by default and marker set name configurable for all trait handlers. Makes "displayMinstrelSongs" configurable for minstrels
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package net.knarcraft.dynmapcitizens.settings;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
/**
|
||||
* An abstract implementation of trait settings
|
||||
*/
|
||||
public abstract class AbstractTraitSettings implements TraitSettings {
|
||||
|
||||
private boolean isEnabled;
|
||||
private String markerSetId;
|
||||
private int markerSetPriority;
|
||||
private boolean hideMarkersByDefault;
|
||||
private String markerSetName;
|
||||
|
||||
@Override
|
||||
public void load(FileConfiguration configuration) {
|
||||
this.isEnabled = configuration.getBoolean(getTraitConfigRoot() + ".enabled", false);
|
||||
this.markerSetId = configuration.getString(getTraitConfigRoot() + ".markerSetId", null);
|
||||
this.markerSetPriority = configuration.getInt(getTraitConfigRoot() + ".markerSetPriority", 1);
|
||||
this.hideMarkersByDefault = configuration.getBoolean(getTraitConfigRoot() + ".markersHiddenByDefault", false);
|
||||
this.markerSetName = configuration.getString(getTraitConfigRoot() + ".markerSetName", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMarkerSetId() {
|
||||
return markerSetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMarkerSetName() {
|
||||
return markerSetName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMarkerSetPriority() {
|
||||
return markerSetPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markersHiddenByDefault() {
|
||||
return hideMarkersByDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the root config node for this trait's settings
|
||||
*
|
||||
* @return <p>The root config node for this trait's settings</p>
|
||||
*/
|
||||
protected abstract String getTraitConfigRoot();
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package net.knarcraft.dynmapcitizens.settings;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
/**
|
||||
* All settings for the blacksmith trait
|
||||
*/
|
||||
public class BlacksmithSettings extends AbstractTraitSettings {
|
||||
|
||||
@Override
|
||||
public void load(FileConfiguration configuration) {
|
||||
super.load(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTraitConfigRoot() {
|
||||
return "traits.blacksmith";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,88 @@
|
||||
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";
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package net.knarcraft.dynmapcitizens.settings;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
/**
|
||||
* All settings for the minstrel trait
|
||||
*/
|
||||
public class MinstrelSettings extends AbstractTraitSettings {
|
||||
|
||||
private boolean displayMinstrelSongs;
|
||||
|
||||
@Override
|
||||
public void load(FileConfiguration configuration) {
|
||||
super.load(configuration);
|
||||
displayMinstrelSongs = configuration.getBoolean(getTraitConfigRoot() + ".displayMinstrelSongs", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTraitConfigRoot() {
|
||||
return "traits.minstrel";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether a minstrel's songs should be displayed in their description
|
||||
*
|
||||
* @return <p>True if minstrel songs should be displayed</p>
|
||||
*/
|
||||
public boolean displayMinstrelSongs() {
|
||||
return displayMinstrelSongs;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package net.knarcraft.dynmapcitizens.settings;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
/**
|
||||
* All settings for the quests trait
|
||||
*/
|
||||
public class QuestsSettings extends AbstractTraitSettings {
|
||||
|
||||
@Override
|
||||
public void load(FileConfiguration configuration) {
|
||||
super.load(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTraitConfigRoot() {
|
||||
return "traits.quests";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package net.knarcraft.dynmapcitizens.settings;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
/**
|
||||
* All settings for the sentinel trait
|
||||
*/
|
||||
public class SentinelSettings extends AbstractTraitSettings {
|
||||
|
||||
@Override
|
||||
public void load(FileConfiguration configuration) {
|
||||
super.load(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTraitConfigRoot() {
|
||||
return "traits.sentinel";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package net.knarcraft.dynmapcitizens.settings;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
/**
|
||||
* An interface describing a generic trait settings class
|
||||
*/
|
||||
public interface TraitSettings {
|
||||
|
||||
/**
|
||||
* Loads the current values of this trait's settings from the given file configuration
|
||||
*
|
||||
* @param configuration <p>The configuration to load values from</p>
|
||||
*/
|
||||
void load(FileConfiguration configuration);
|
||||
|
||||
/**
|
||||
* Gets whether this trait type is enabled in the config
|
||||
*
|
||||
* @return <p>True if this trait is enabled</p>
|
||||
*/
|
||||
boolean isEnabled();
|
||||
|
||||
/**
|
||||
* Gets the id of the trait's marker set
|
||||
*
|
||||
* <p>This is mainly configurable in case of duplicate ids</p>
|
||||
*
|
||||
* @return <p>The id of the marker set</p>
|
||||
*/
|
||||
String getMarkerSetId();
|
||||
|
||||
/**
|
||||
* Gets the name of this trait's marker set
|
||||
*
|
||||
* @return <p>The name of the marker set</p>
|
||||
*/
|
||||
String getMarkerSetName();
|
||||
|
||||
/**
|
||||
* Gets the priority of the trait's marker set
|
||||
*
|
||||
* @return <p>The priority of the marker set</p>
|
||||
*/
|
||||
int getMarkerSetPriority();
|
||||
|
||||
/**
|
||||
* Gets whether this trait's markers should be hidden by default
|
||||
*
|
||||
* @return <p>Whether markers should be hidden by default</p>
|
||||
*/
|
||||
boolean markersHiddenByDefault();
|
||||
|
||||
}
|
Reference in New Issue
Block a user