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.blacksmith.BlacksmithPlugin; import net.knarcraft.blacksmith.config.NPCSettings; import net.knarcraft.blacksmith.trait.BlacksmithTrait; import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.property.Icon; import net.knarcraft.dynmapcitizens.settings.BlacksmithSettings; import net.knarcraft.dynmapcitizens.settings.TraitSettings; import org.bukkit.Bukkit; import org.bukkit.Material; import org.dynmap.markers.GenericMarker; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; /** * A handler class for the blacksmith trait */ public class BlacksmithHandler extends AbstractTraitHandler { private final BlacksmithSettings settings = new BlacksmithSettings(); @Override public void initialize() { BlacksmithPlugin blacksmithPlugin = (BlacksmithPlugin) Bukkit.getServer().getPluginManager().getPlugin( "Blacksmith"); if (blacksmithPlugin != null) { super.initializeMarkerSet(); } else { super.isEnabled = false; } } @Override public @NotNull TraitSettings getSettings() { return this.settings; } @Override public void updateMarkers() { //Remove existing markers super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker); Class extends Trait> blacksmithTrait = CitizensAPI.getTraitFactory().getTraitClass("blacksmith"); for (NPC npc : CitizensAPI.getNPCRegistry()) { if (npc.hasTrait(blacksmithTrait)) { BlacksmithTrait trait = npc.getTraitNullable(BlacksmithTrait.class); String description = ""; if (trait == null) { DynmapCitizens.getInstance().getLogger().log(Level.WARNING, "Unable to get blacksmith trait"); } else { //TODO: Make a setting which allows disabling extra information (except title and reforge-able items?) description = getDetailedBlacksmithInfo(npc, trait.getSettings()); } addNPCMarker(npc.getUniqueId(), "Blacksmith NPC: ", description, DynmapCitizens.getInstance().getGlobalSettings().getMarkerIcons().get(Icon.BLACKSMITH), super.markerSet); } } } /** * Gets detailed information about a blacksmith NPC * * @param npc
The NPC the settings belong to
* @param npcSettingsThe settings to search for information
* @returnA string describing the blacksmith
*/ private @NotNull String getDetailedBlacksmithInfo(@NotNull NPC npc, @NotNull NPCSettings npcSettings) { String info = "The materials specified as reforge-able items
* @returnThe reforge-able items
*/ private static @NotNull String getReforgeAbleItemsString(@NotNull List