package net.knarcraft.dynmapcitizens.handler.trait; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.trait.Trait; import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.property.Icon; import net.knarcraft.dynmapcitizens.property.UpdateRate; import net.knarcraft.minstrel.MinstrelPlugin; import net.knarcraft.minstrel.music.Song; import net.knarcraft.minstrel.trait.MinstrelTrait; import org.bukkit.Bukkit; import org.dynmap.DynmapAPI; import org.dynmap.markers.GenericMarker; import org.dynmap.markers.MarkerSet; import java.util.logging.Level; /** * A handler class for the minstrel trait */ public class MinstrelHandler extends AbstractTraitHandler { private MarkerSet minstrelSet; @Override public void initialize() { MinstrelPlugin minstrelPlugin = (MinstrelPlugin) Bukkit.getServer().getPluginManager().getPlugin("Minstrel"); DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI(); if (minstrelPlugin != null) { minstrelSet = getMarkerSet(dynmapAPI, "minstrels", "Minstrels"); if (minstrelSet != null) { minstrelSet.setHideByDefault(false); minstrelSet.setLayerPriority(3); isEnabled = true; return; } } isEnabled = false; } @Override public UpdateRate getUpdateRate() { return UpdateRate.VERY_SLOW; } @Override public void updateMarkers() { //Remove existing markers minstrelSet.getMarkers().forEach(GenericMarker::deleteMarker); Class minstrelTrait = CitizensAPI.getTraitFactory().getTraitClass("minstrel"); for (NPC npc : CitizensAPI.getNPCRegistry()) { if (npc.hasTrait(minstrelTrait)) { MinstrelTrait trait = npc.getTraitNullable(MinstrelTrait.class); String description = null; if (trait == null) { DynmapCitizens.getInstance().getLogger().log(Level.WARNING, "Unable to get minstrel trait"); } else { description = getDetailedMinstrelInfo(npc, trait); } addNPCMarker(npc.getUniqueId(), "Minstrel NPC: ", description, DynmapCitizens.getInstance().getMarkerIcons().get(Icon.MINSTREL), minstrelSet); } } } /** * Gets detailed information about a minstrel NPC * * @param npc

The NPC the settings belong to

* @param trait

The minstrel trait to get information from

* @return

A string describing the minstrel

*/ private String getDetailedMinstrelInfo(NPC npc, MinstrelTrait trait) { StringBuilder info = new StringBuilder("

" + npc.getName() + "

"); info.append("Songs:"); return info.toString(); } }