Adds icons for trader NPCs
All checks were successful
KnarCraft/DynmapCitizens/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2023-08-21 22:38:07 +02:00
parent 9312e2156b
commit 88bf1b28c2
9 changed files with 106 additions and 5 deletions

View File

@ -14,4 +14,8 @@ basis, and possibly choosing exactly what information to display on each trait's
- [Blacksmith](https://www.spigotmc.org/resources/blacksmith.105938/)
- [Quests](https://www.spigotmc.org/resources/quests.3711/)
- [Sentinel](https://www.spigotmc.org/resources/sentinel.22017/)
- [Minstrel](https://git.knarcraft.net/EpicKnarvik97/Minstrel)
- [Minstrel](https://git.knarcraft.net/EpicKnarvik97/Minstrel)
## Somewhat supported NPC traits, because the developers have no API
- [Trader](https://www.spigotmc.org/resources/dtltraders.35890/)

View File

@ -167,7 +167,7 @@
<dependency>
<groupId>net.knarcraft</groupId>
<artifactId>knarlib</artifactId>
<version>1.1</version>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -5,6 +5,7 @@ import net.knarcraft.dynmapcitizens.formatting.SentinelTranslatableMessage;
import net.knarcraft.dynmapcitizens.handler.VaultHandler;
import net.knarcraft.dynmapcitizens.handler.trait.BlacksmithHandler;
import net.knarcraft.dynmapcitizens.handler.trait.CitizensTraitHandler;
import net.knarcraft.dynmapcitizens.handler.trait.DTLTradersHandler;
import net.knarcraft.dynmapcitizens.handler.trait.MinstrelHandler;
import net.knarcraft.dynmapcitizens.handler.trait.SentinelHandler;
import net.knarcraft.dynmapcitizens.handler.trait.quests.QuestsHandler;
@ -23,6 +24,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
/**
* DynmapCitizens' main class
*/
@SuppressWarnings("unused")
public final class DynmapCitizens extends JavaPlugin {
@ -151,6 +155,7 @@ public final class DynmapCitizens extends JavaPlugin {
this.traitHandlers.add(new QuestsHandler());
this.traitHandlers.add(new SentinelHandler());
this.traitHandlers.add(new MinstrelHandler());
this.traitHandlers.add(new DTLTradersHandler());
//Load and initialize all enabled trait handlers
for (CitizensTraitHandler handler : this.traitHandlers) {

View File

@ -0,0 +1,53 @@
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.settings.DTLTradersSettings;
import net.knarcraft.dynmapcitizens.settings.TraitSettings;
import org.dynmap.markers.GenericMarker;
/**
* A handler class for the minstrel trait
*/
public class DTLTradersHandler extends AbstractTraitHandler {
private final DTLTradersSettings settings = new DTLTradersSettings();
@Override
public void initialize() {
super.isEnabled = false;
CitizensAPI.getTraitFactory().getRegisteredTraits().forEach(traitInfo -> {
if (traitInfo.getTraitName().equals("trader")) {
super.isEnabled = true;
}
});
if (this.isEnabled) {
super.initializeMarkerSet();
}
}
@Override
public TraitSettings getSettings() {
return this.settings;
}
@Override
public void updateMarkers() {
//Remove existing markers
super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker);
Class<? extends Trait> traderTrait = CitizensAPI.getTraitFactory().getTraitClass("trader");
for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (npc.hasTrait(traderTrait)) {
String description = "<h2>" + npc.getName() + "</h2>";
addNPCMarker(npc.getUniqueId(), "Trader NPC: ", description,
DynmapCitizens.getInstance().getGlobalSettings().getMarkerIcons().get(Icon.TRADER), super.markerSet);
}
}
}
}

View File

@ -93,7 +93,7 @@ public class QuestAreaHandler {
} else {
formattedAreaName = "";
}
String description = formatter.replacePlaceholders(QUESTS_REACH_AREA_DESCRIPTION_FORMAT,
new String[]{"{areaName}", "{questName}"}, new String[]{formattedAreaName, quest.getName()});
DynmapHelper.markLocation(location, radius, description, reachAreaMarkerSet, settings.getReachAreaSettings());

View File

@ -43,6 +43,11 @@ public enum Icon {
/**
* An icon representing a minstrel NPC
*/
MINSTREL
MINSTREL,
/**
* An icon representing a trader NPC
*/
TRADER,
}

View File

@ -0,0 +1,20 @@
package net.knarcraft.dynmapcitizens.settings;
import org.bukkit.configuration.file.FileConfiguration;
/**
* All settings for the minstrel trait
*/
public class DTLTradersSettings extends AbstractTraitSettings {
@Override
public void load(FileConfiguration configuration) {
super.load(configuration);
}
@Override
protected String getTraitConfigRoot() {
return "traits.trader";
}
}

View File

@ -82,6 +82,7 @@ public class GlobalSettings {
case BLACKSMITH -> "hammer";
case SENTINEL -> "shield";
case MINSTREL -> "theater";
case TRADER -> "coins";
};
}

View File

@ -16,6 +16,8 @@ icon:
SENTINEL: "shield"
# The marker used for minstrels
MINSTREL: "theater"
# The marker used for traders
TRADER: "coins"
# Settings for how often markers will be updated
timer:
@ -129,4 +131,15 @@ traits:
# Whether to hide the minstrel icon layer by default
markersHiddenByDefault: false
# Whether to display the list of songs a minstrel is playing
displayMinstrelSongs: true
displayMinstrelSongs: true
# Settings for the trader trait
trader:
enabled: true
# The priority of trader markers. Higher priority markers will display on top of lower priority ones
markerSetPriority: 1
# The id of the trader marker set. Change if it overlaps with an existing set id
markerSetId: "traders"
# The name of the trader marker set. Change it if you want a cooler name
markerSetName: "Traders"
# Whether to hide the trader icon layer by default
markersHiddenByDefault: false