Adds minstrel markers

This commit is contained in:
Kristian Knarvik 2022-11-01 15:08:50 +01:00
parent eabcffe878
commit ce042fe3ec
6 changed files with 102 additions and 3 deletions

View File

@ -120,6 +120,12 @@
<version>1.0.1-SNAPSHOT</version> <version>1.0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>net.knarcraft</groupId>
<artifactId>minstrel</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.mcmonkey</groupId> <groupId>org.mcmonkey</groupId>
<artifactId>sentinel</artifactId> <artifactId>sentinel</artifactId>

View File

@ -2,6 +2,7 @@ package net.knarcraft.dynmapcitizens;
import net.knarcraft.dynmapcitizens.trait.BlacksmithHandler; import net.knarcraft.dynmapcitizens.trait.BlacksmithHandler;
import net.knarcraft.dynmapcitizens.trait.CitizensTraitHandler; import net.knarcraft.dynmapcitizens.trait.CitizensTraitHandler;
import net.knarcraft.dynmapcitizens.trait.MinstrelHandler;
import net.knarcraft.dynmapcitizens.trait.SentinelHandler; import net.knarcraft.dynmapcitizens.trait.SentinelHandler;
import net.knarcraft.dynmapcitizens.trait.quests.QuestsHandler; import net.knarcraft.dynmapcitizens.trait.quests.QuestsHandler;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -47,6 +48,7 @@ public final class DynmapCitizens extends JavaPlugin {
handlers.add(new BlacksmithHandler()); handlers.add(new BlacksmithHandler());
handlers.add(new QuestsHandler()); handlers.add(new QuestsHandler());
handlers.add(new SentinelHandler()); handlers.add(new SentinelHandler());
handlers.add(new MinstrelHandler());
for (CitizensTraitHandler handler : handlers) { for (CitizensTraitHandler handler : handlers) {
handler.initialize(); handler.initialize();
} }
@ -115,6 +117,7 @@ public final class DynmapCitizens extends JavaPlugin {
markerIcons.put(Icon.BLACKSMITH, markerAPI.getMarkerIcon("hammer")); markerIcons.put(Icon.BLACKSMITH, markerAPI.getMarkerIcon("hammer"));
markerIcons.put(Icon.SENTINEL, markerAPI.getMarkerIcon("shield")); markerIcons.put(Icon.SENTINEL, markerAPI.getMarkerIcon("shield"));
markerIcons.put(Icon.QUEST_CHAIN, markerAPI.getMarkerIcon("caution")); markerIcons.put(Icon.QUEST_CHAIN, markerAPI.getMarkerIcon("caution"));
markerIcons.put(Icon.MINSTREL, markerAPI.getMarkerIcon("theater"));
this.markerIcons = markerIcons; this.markerIcons = markerIcons;
} }

View File

@ -38,6 +38,11 @@ public enum Icon {
/** /**
* An icon representing a blacksmith NPC * An icon representing a blacksmith NPC
*/ */
BLACKSMITH BLACKSMITH,
/**
* An icon representing a minstrel NPC
*/
MINSTREL
} }

View File

@ -55,7 +55,7 @@ public class BlacksmithHandler extends AbstractTraitHandler {
Class<? extends Trait> blacksmithTrait = CitizensAPI.getTraitFactory().getTraitClass("blacksmith"); Class<? extends Trait> blacksmithTrait = CitizensAPI.getTraitFactory().getTraitClass("blacksmith");
for (NPC npc : CitizensAPI.getNPCRegistry()) { for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (npc.hasTrait(blacksmithTrait)) { if (npc.hasTrait(blacksmithTrait)) {
BlacksmithTrait trait = CitizensAPI.getTraitFactory().getTrait("blacksmith"); BlacksmithTrait trait = npc.getTraitNullable(BlacksmithTrait.class);
String description = null; String description = null;
if (trait == null) { if (trait == null) {
DynmapCitizens.getInstance().getLogger().log(Level.WARNING, "Unable to get blacksmith trait"); DynmapCitizens.getInstance().getLogger().log(Level.WARNING, "Unable to get blacksmith trait");

View File

@ -0,0 +1,85 @@
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.dynmapcitizens.DynmapCitizens;
import net.knarcraft.dynmapcitizens.Icon;
import net.knarcraft.dynmapcitizens.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<? extends Trait> 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 <p>The NPC the settings belong to</p>
* @param trait <p>The minstrel trait to get information from</p>
* @return <p>A string describing the minstrel</p>
*/
private String getDetailedMinstrelInfo(NPC npc, MinstrelTrait trait) {
StringBuilder info = new StringBuilder("<b>Minstrel name:</b> " + npc.getName());
info.append("<br><b>Songs:</b><ul>");
for (Song song : trait.getPlaylist().getSongs()) {
info.append("<li>Category: ").append(song.getCategory()).append(" Sound: ").append(song.getSound()).append("</li>");
}
info.append("</ul>");
return info.toString();
}
}

View File

@ -4,6 +4,6 @@ main: net.knarcraft.dynmapcitizens.DynmapCitizens
api-version: 1.19 api-version: 1.19
prefix: DynmapCitizens prefix: DynmapCitizens
depend: [ dynmap, Citizens ] depend: [ dynmap, Citizens ]
softdepend: [ Blacksmith, Sentinel, Quests ] softdepend: [ Blacksmith, Sentinel, Quests, Minstrel ]
authors: [ EpicKnarvik97 ] authors: [ EpicKnarvik97 ]
description: A plugin for displaying citizens info on the dynmap map description: A plugin for displaying citizens info on the dynmap map