2022-10-19 12:41:26 +02:00
|
|
|
package net.knarcraft.dynmapcitizens.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.Icon;
|
2022-10-19 17:35:26 +02:00
|
|
|
import net.knarcraft.dynmapcitizens.UpdateRate;
|
2022-10-19 12:41:26 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.dynmap.DynmapAPI;
|
|
|
|
import org.dynmap.markers.GenericMarker;
|
|
|
|
import org.dynmap.markers.MarkerSet;
|
|
|
|
|
|
|
|
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 MarkerSet blacksmithSet;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initialize() {
|
|
|
|
BlacksmithPlugin blacksmithPlugin = (BlacksmithPlugin) Bukkit.getServer().getPluginManager().getPlugin("Blacksmith");
|
|
|
|
DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI();
|
|
|
|
if (blacksmithPlugin != null) {
|
|
|
|
blacksmithSet = getMarkerSet(dynmapAPI, "blacksmiths", "Blacksmiths");
|
|
|
|
if (blacksmithSet != null) {
|
|
|
|
blacksmithSet.setHideByDefault(false);
|
2022-10-20 20:40:17 +02:00
|
|
|
blacksmithSet.setLayerPriority(3);
|
2022-10-19 12:41:26 +02:00
|
|
|
isEnabled = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isEnabled = false;
|
|
|
|
}
|
|
|
|
|
2022-10-19 17:35:26 +02:00
|
|
|
@Override
|
|
|
|
public UpdateRate getUpdateRate() {
|
|
|
|
return UpdateRate.VERY_SLOW;
|
|
|
|
}
|
|
|
|
|
2022-10-19 12:41:26 +02:00
|
|
|
@Override
|
|
|
|
public void updateMarkers() {
|
|
|
|
//Remove existing markers
|
|
|
|
blacksmithSet.getMarkers().forEach(GenericMarker::deleteMarker);
|
|
|
|
|
|
|
|
Class<? extends Trait> blacksmithTrait = CitizensAPI.getTraitFactory().getTraitClass("blacksmith");
|
|
|
|
for (NPC npc : CitizensAPI.getNPCRegistry()) {
|
|
|
|
if (npc.hasTrait(blacksmithTrait)) {
|
|
|
|
BlacksmithTrait trait = CitizensAPI.getTraitFactory().getTrait("blacksmith");
|
|
|
|
String description = null;
|
|
|
|
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?)
|
2022-10-19 12:58:12 +02:00
|
|
|
description = getDetailedBlacksmithInfo(npc, trait.getSettings());
|
2022-10-19 12:41:26 +02:00
|
|
|
}
|
|
|
|
addNPCMarker(npc.getUniqueId(), "Blacksmith NPC: ", description,
|
|
|
|
DynmapCitizens.getInstance().getMarkerIcons().get(Icon.BLACKSMITH), blacksmithSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-19 12:58:12 +02:00
|
|
|
/**
|
|
|
|
* Gets detailed information about a blacksmith NPC
|
|
|
|
*
|
|
|
|
* @param npc <p>The NPC the settings belong to</p>
|
|
|
|
* @param npcSettings <p>The settings to search for information</p>
|
|
|
|
* @return <p>A string describing the blacksmith</p>
|
|
|
|
*/
|
|
|
|
private String getDetailedBlacksmithInfo(NPC npc, NPCSettings npcSettings) {
|
|
|
|
String info = "<b>Blacksmith name:</b> " + npc.getName() + "<br><b>Blacksmith title:</b> " +
|
|
|
|
npcSettings.getBlacksmithTitle() + "<br><b>Fail chance:</b> " + npcSettings.getFailChance() +
|
|
|
|
"<br><b>Enchantment chance:</b> " + npcSettings.getExtraEnchantmentChance() + "<br><b>Delay:</b> " +
|
|
|
|
npcSettings.getMinReforgeDelay() + " to " + npcSettings.getMaxReforgeDelay() +
|
|
|
|
" seconds<br><b>Cool-down:</b> " + npcSettings.getReforgeCoolDown() + " seconds<br><b>Drop item:</b> " +
|
2022-10-25 20:46:35 +02:00
|
|
|
npcSettings.getDropItem() + "<br><b>Max enchantments:</b> " + npcSettings.getMaxEnchantments();
|
2022-10-19 12:58:12 +02:00
|
|
|
if (!npcSettings.getReforgeAbleItems().isEmpty()) {
|
|
|
|
info += "<br><b>Reforge-able items:</b> " + getReforgeAbleItemsString(npcSettings.getReforgeAbleItems());
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2022-10-19 12:41:26 +02:00
|
|
|
/**
|
|
|
|
* Gets reforge-able items as a string
|
|
|
|
*
|
|
|
|
* @param materials <p>The materials specified as reforge-able items</p>
|
|
|
|
* @return <p>The reforge-able items</p>
|
|
|
|
*/
|
|
|
|
private static String getReforgeAbleItemsString(List<Material> materials) {
|
|
|
|
List<String> materialNames = new ArrayList<>();
|
|
|
|
for (Material material : materials) {
|
|
|
|
materialNames.add(material.name());
|
|
|
|
}
|
|
|
|
return String.join(", ", materialNames);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|