Merge branch 'custom-formatting'
All checks were successful
KnarCraft/DynmapCitizens/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2023-10-17 04:11:43 +02:00
commit 87a99ed559
19 changed files with 696 additions and 183 deletions

33
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,33 @@
pipeline {
agent any
tools {
jdk 'JDK17'
}
stages {
stage('Build') {
steps {
echo 'Building...'
sh 'mvn clean & mvn validate & mvn compile'
}
}
stage('Test') {
steps {
echo 'Testing...'
sh 'mvn test'
}
}
stage('Verify') {
steps {
echo 'Verifying...'
sh 'mvn verify -Dmaven.test.skip=true'
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
sh 'mvn deploy -Dmaven.install.skip=true -Dmaven.test.skip=true'
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
}
}
}

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/)

60
pom.xml
View File

@ -13,7 +13,7 @@
<description>A plugin for displaying citizens on the dynmap map</description>
<properties>
<java.version>17</java.version>
<java.version>16</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@ -24,8 +24,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
@ -40,6 +40,20 @@
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>net.knarcraft:knarlib</artifact>
<includes>
<include>net/knarcraft/knarlib/**</include>
</includes>
</filter>
<filter>
<excludes>
<exclude>*.MF</exclude>
<exclude>*.yml</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
@ -54,6 +68,10 @@
</build>
<repositories>
<repository>
<id>knarcraft-repo</id>
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
@ -72,19 +90,29 @@
</repository>
<repository>
<id>citizens-repo</id>
<url>http://repo.citizensnpcs.co/</url>
<url>https://repo.citizensnpcs.co/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>knarcraft-repo</id>
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
</repository>
<snapshotRepository>
<id>knarcraft-repo</id>
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version>
<version>1.19.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -103,13 +131,13 @@
<dependency>
<groupId>me.blackvein.quests</groupId>
<artifactId>quests-api</artifactId>
<version>4.6.0</version>
<version>4.8.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.blackvein.quests</groupId>
<artifactId>quests-core</artifactId>
<version>4.6.0</version>
<version>4.8.1</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -121,7 +149,7 @@
<dependency>
<groupId>net.knarcraft</groupId>
<artifactId>blacksmith</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -131,11 +159,17 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId>
<version>1.7.3</version>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.knarcraft</groupId>
<artifactId>knarlib</artifactId>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mcmonkey</groupId>
<artifactId>sentinel</artifactId>

View File

@ -1,12 +1,18 @@
package net.knarcraft.dynmapcitizens;
import net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage;
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;
import net.knarcraft.dynmapcitizens.settings.GlobalSettings;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.formatting.TranslatableTimeUnit;
import net.knarcraft.knarlib.formatting.Translator;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
@ -18,11 +24,16 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
/**
* DynmapCitizens' main class
*/
@SuppressWarnings("unused")
public final class DynmapCitizens extends JavaPlugin {
private static DynmapCitizens instance;
private DynmapAPI dynmapAPI;
private static Translator translator;
private static StringFormatter stringFormatter;
private DynmapAPI dynmapAPIInstance;
private VaultHandler vaultHandler;
private GlobalSettings globalSettings;
private List<CitizensTraitHandler> traitHandlers;
@ -30,6 +41,7 @@ public final class DynmapCitizens extends JavaPlugin {
@Override
public void onEnable() {
DynmapCitizens.instance = this;
//Initialize quest and dynmap APIs
PluginManager pluginManager = Bukkit.getPluginManager();
Plugin dynmapPlugin = pluginManager.getPlugin("dynmap");
@ -38,7 +50,7 @@ public final class DynmapCitizens extends JavaPlugin {
this.onDisable();
return;
}
this.dynmapAPI = dynmapAPI;
this.dynmapAPIInstance = dynmapAPI;
this.globalSettings = new GlobalSettings();
FileConfiguration configuration = this.getConfig();
@ -49,6 +61,14 @@ public final class DynmapCitizens extends JavaPlugin {
configuration = this.getConfig();
this.globalSettings.load(configuration);
//Load all messages
translator = new Translator();
translator.registerMessageCategory(TranslatableTimeUnit.UNIT_SECOND);
translator.registerMessageCategory(QuestsTranslatableMessage.QUESTS_REQUIREMENTS_FORMAT);
translator.registerMessageCategory(SentinelTranslatableMessage.SENTINEL_DESCRIPTION);
translator.loadLanguages(this.getDataFolder(), "en", "en");
stringFormatter = new StringFormatter(this.getDescription().getName(), translator);
//Initialize all enabled traits
initializeTraitHandlers(configuration);
@ -69,6 +89,24 @@ public final class DynmapCitizens extends JavaPlugin {
//TODO: Perhaps remove icons, just in case?
}
/**
* Gets the translator to use for translation
*
* @return <p>The translator to use</p>
*/
public static Translator getTranslator() {
return translator;
}
/**
* Gets the string formatter to use for formatting
*
* @return <p>The string formatter to use</p>
*/
public static StringFormatter getFormatter() {
return stringFormatter;
}
/**
* Gets the global settings for this plugin
*
@ -93,7 +131,7 @@ public final class DynmapCitizens extends JavaPlugin {
* @return <p>A reference to the Dynmap API</p>
*/
public DynmapAPI getDynmapAPI() {
return this.dynmapAPI;
return this.dynmapAPIInstance;
}
/**
@ -117,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,169 @@
package net.knarcraft.dynmapcitizens.formatting;
import net.knarcraft.knarlib.formatting.TranslatableMessage;
/**
* An enum describing all of DynmapCitizens' translatable messages
*/
public enum QuestsTranslatableMessage implements TranslatableMessage {
/**
* The format for a quest's planner description
*
* <p>Placeholders: {questCoolDown}, {questFrom}, {questUntil}, {questRepeat}</p>
*/
QUESTS_PLANNER_DESCRIPTION,
/**
* The format for a quest's cool-down
*
* <p>Placeholders: {coolDown}</p>
*/
QUESTS_PLANNER_COOL_DOWN,
/**
* The text to display if a quest cannot be repeated
*/
QUESTS_PLANNER_UNREPEATABLE,
/**
* The format for a quest's first availability date
*
* <p>Placeholders: {startDate}</p>
*/
QUESTS_PLANNER_FROM,
/**
* The format for a quest's last availability date
*
* <p>Placeholders: {endDate}</p>
*/
QUESTS_PLANNER_UNTIL,
/**
* The format for a quest's repeat delay
*
* <p>Placeholders: {repeatDelay}</p>
*/
QUEST_PLANNER_REPEAT,
/**
* The format for a quest's requirements
*
* <p>Placeholders: {requirementQuestPoints}, {requirementExp}, {requirementBlockedByQuests},
* {requirementRequiredQuests}, {requirementRequiredItems}, {requirementMCMMOSkills}, {requirementPermissions},
* {requirementCustom}</p>
*/
QUESTS_REQUIREMENTS_FORMAT,
/**
* The format for a quest's quest point requirement
*
* <p>Placeholders: {questPoints}</p>
*/
QUESTS_REQUIREMENTS_QUEST_POINTS,
/**
* The format for a quest's exp requirement
*
* <p>Placeholders: {exp}</p>
*/
QUESTS_REQUIREMENTS_EXP,
/**
* The format for a quest's blocking quests
*
* <p>Placeholders: {blockingQuests}</p>
*/
QUESTS_REQUIREMENTS_BLOCKED_BY_QUEST_FORMAT,
/**
* The format for one of a quest's blocking quests
*
* <p>Placeholders: {questName}</p>
*/
QUESTS_REQUIREMENTS_BLOCKED_BY_QUEST_ITEM,
/**
* The format for a quest's required quests
*
* <p>Placeholders: {requiredQuests}</p>
*/
QUESTS_REQUIREMENTS_REQUIRED_QUEST_FORMAT,
/**
* The format for one of a quest's required quests
*
* <p>Placeholders: {questName}</p>
*/
QUESTS_REQUIREMENTS_REQUIRED_QUEST_ITEM,
/**
* The format for a quest's required items
*
* <p>Placeholders: {requiredItems}</p>
*/
QUESTS_REQUIREMENTS_REQUIRED_ITEM_FORMAT,
/**
* The format for one of a quest's required items
*
* <p>Placeholders: {itemName}</p>
*/
QUESTS_REQUIREMENTS_REQUIRED_ITEM_ITEM,
/**
* The format for a quest's mcMMO skill requirement
*
* <p>Placeholders: {skill}, {level}</p>
*/
QUESTS_REQUIREMENTS_MC_MMO_SKILL,
/**
* The format for a quest's required permissions
*
* <p>Placeholders: {permissions}</p>
*/
QUESTS_REQUIREMENTS_REQUIRED_PERMISSION_FORMAT,
/**
* The format for one of a quest's required permissions
*
* <p>Placeholders: {permission}</p>
*/
QUESTS_REQUIREMENTS_REQUIRED_PERMISSION_ITEM,
/**
* The format for a quest's reach area name
*
* <p>Placeholders: {name}</p>
*/
QUESTS_REACH_AREA_NAME_FORMAT,
/**
* The format for a quest's reach area's description
*
* <p>Placeholders: {areaName}, {questName}</p>
*/
QUESTS_REACH_AREA_DESCRIPTION_FORMAT,
/**
* The format for a quest's kill area name
*
* <p>Placeholders: {name}</p>
*/
QUESTS_KILL_AREA_NAME_FORMAT,
/**
* The format for a quest's kill area description
*
* <p>Placeholders: {areaName}, {questName}, {mobName}, {mobAmount}</p>
*/
QUESTS_KILL_AREA_DESCRIPTION_FORMAT,
;
@Override
public TranslatableMessage[] getAllMessages() {
return QuestsTranslatableMessage.values();
}
}

View File

@ -0,0 +1,31 @@
package net.knarcraft.dynmapcitizens.formatting;
import net.knarcraft.knarlib.formatting.TranslatableMessage;
/**
* An enum describing all translatable messages for sentinels
*/
public enum SentinelTranslatableMessage implements TranslatableMessage {
/**
* The format for the basic description of any sentinel
*
* <p>Placeholders: {name}, {squad}, {sentinelDetails}</p>
*/
SENTINEL_DESCRIPTION,
/**
* The format for the detailed description of any sentinel
*
* <p>Placeholders: {invincible}, {armor}, {health}, {accuracy}, {damage}, {speed}, {allowKnockback}, {range},
* {reach}, {targets}, {avoids}, {ignores}</p>
*/
SENTINEL_DETAILS,
;
@Override
public TranslatableMessage[] getAllMessages() {
return SentinelTranslatableMessage.values();
}
}

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

@ -47,12 +47,14 @@ public class SentinelHandler extends AbstractTraitHandler {
description += "<br><b>Squad:</b> " + trait.squad;
}
if (settings.displaySentinelStats()) {
description += "<br><b>Invincible:</b> " + trait.invincible + "<br><b>Armor:</b> " +
trait.armor + "<br><b>Health:</b> " + trait.health + "<br><b>Accuracy:</b> " + trait.accuracy +
"<br><b>Damage:</b> " + trait.damage + "<br><b>Allow knockback:</b> " + trait.allowKnockback;
description += "<br><b>Invincible:</b> " + trait.invincible + "<br><b>Armor:</b> " + trait.armor;
description += "<br><b>Health:</b> " + trait.health + "<br><b>Accuracy:</b> " + trait.accuracy;
description += "<br><b>Damage:</b> " + trait.damage + "<br><b>Speed:</b> " + trait.speed;
description += "<br><b>Allow knockback:</b> " + trait.allowKnockback;
description += "<br><b>Range:</b> " + trait.range + "<br><b>Reach:</b> " + trait.reach;
description += "<br><b>Targets:</b> " + trait.allTargets.toAllInOneString() + "<br><b>Avoids:</b> " +
trait.allAvoids.toAllInOneString() + "<br><b>Ignores:</b> " + trait.allIgnores.toAllInOneString();
description += "<br><b>Targets:</b> " + trait.allTargets.toAllInOneString();
description += "<br><b>Avoids:</b> " + trait.allAvoids.toAllInOneString();
description += "<br><b>Ignores:</b> " + trait.allIgnores.toAllInOneString();
}
addNPCMarker(npc.getUniqueId(), "Sentinel NPC: ", description,
DynmapCitizens.getInstance().getGlobalSettings().getMarkerIcons().get(Icon.SENTINEL), super.markerSet);

View File

@ -3,9 +3,13 @@ package net.knarcraft.dynmapcitizens.handler.trait.quests;
import me.blackvein.quests.QuestsAPI;
import me.blackvein.quests.quests.IQuest;
import me.blackvein.quests.quests.IStage;
import net.knarcraft.dynmapcitizens.DynmapCitizens;
import net.knarcraft.dynmapcitizens.settings.QuestsSettings;
import net.knarcraft.dynmapcitizens.util.DynmapHelper;
import net.knarcraft.dynmapcitizens.util.QuestsHelper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.formatting.StringReplacer;
import net.knarcraft.knarlib.formatting.Translator;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.dynmap.DynmapAPI;
@ -14,6 +18,11 @@ import org.dynmap.markers.MarkerSet;
import java.util.List;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_KILL_AREA_DESCRIPTION_FORMAT;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_KILL_AREA_NAME_FORMAT;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REACH_AREA_DESCRIPTION_FORMAT;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REACH_AREA_NAME_FORMAT;
/**
* A handler class for quest areas
*/
@ -24,6 +33,7 @@ public class QuestAreaHandler {
private final MarkerSet reachAreaMarkerSet;
private final QuestsSettings settings;
private final List<IQuest> unavailableQuests;
private final StringFormatter formatter;
/**
* Instantiates a new quest area handler
@ -38,6 +48,7 @@ public class QuestAreaHandler {
this.questsAPI = questsAPI;
this.settings = settings;
this.unavailableQuests = unavailableQuests;
this.formatter = DynmapCitizens.getFormatter();
killAreaMarkerSet = DynmapHelper.initializeMarkerSet(dynmapAPI, settings.getKillAreaSettings());
reachAreaMarkerSet = DynmapHelper.initializeMarkerSet(dynmapAPI, settings.getReachAreaSettings());
}
@ -75,11 +86,16 @@ public class QuestAreaHandler {
Location location = stage.getLocationsToReach().get(i);
int radius = stage.getRadiiToReachWithin().get(i);
String areaName = stage.getLocationNames().get(i);
String description = "";
String formattedAreaName;
if (areaName != null) {
description += "<b>" + areaName + "</b><br>";
formattedAreaName = formatter.replacePlaceholder(QUESTS_REACH_AREA_NAME_FORMAT, "{name}", areaName);
} else {
formattedAreaName = "";
}
description += "Target location for " + quest.getName();
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());
}
}
@ -101,13 +117,20 @@ public class QuestAreaHandler {
int mobAmount = stage.getMobNumToKill().get(i);
String areaName = stage.getKillNames().get(i);
String description = "";
String formattedAreaName;
if (areaName != null) {
description += "<b>" + areaName + "</b><br>";
formattedAreaName = formatter.replacePlaceholder(QUESTS_KILL_AREA_NAME_FORMAT, "{name}", areaName);
} else {
formattedAreaName = "";
}
description += "Kill location for " + quest.getName() +
"<br>Kill " + QuestsHelper.normalizeName(mob.name()) + " x " + mobAmount;
DynmapHelper.markLocation(location, radius, description, killAreaMarkerSet, settings.getKillAreaSettings());
Translator translator = DynmapCitizens.getTranslator();
StringReplacer replacer = new StringReplacer(translator.getTranslatedMessage(QUESTS_KILL_AREA_DESCRIPTION_FORMAT));
replacer.add("{areaName}", formattedAreaName);
replacer.add("{questName}", quest.getName());
replacer.add("{mobName}", QuestsHelper.normalizeName(mob.name()));
replacer.add("{mobAmount}", String.valueOf(mobAmount));
DynmapHelper.markLocation(location, radius, replacer.replace(), killAreaMarkerSet, settings.getKillAreaSettings());
}
}

View File

@ -2,7 +2,12 @@ package net.knarcraft.dynmapcitizens.handler.trait.quests;
import me.blackvein.quests.quests.IQuest;
import me.blackvein.quests.quests.Planner;
import net.knarcraft.dynmapcitizens.util.TimeFormatter;
import net.knarcraft.dynmapcitizens.DynmapCitizens;
import net.knarcraft.knarlib.formatting.TimeFormatter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* A class to generate a string containing all information about a quest's planner info
@ -33,7 +38,8 @@ public class QuestPlannerInfoGenerator {
//Quest can be repeated after a cool-down
if (planner.hasCooldown()) {
plannerInfo.append("<li>Quest repeatable after: ");
plannerInfo.append(TimeFormatter.getDurationString(planner.getCooldown() / 1000));
plannerInfo.append(TimeFormatter.getDurationString(DynmapCitizens.getTranslator(),
planner.getCooldown() / 1000));
plannerInfo.append("</li>");
} else {
plannerInfo.append("<li>Quest cannot be repeated!</li>");
@ -42,23 +48,36 @@ public class QuestPlannerInfoGenerator {
//Quest only becomes available after the start date
if (planner.hasStart()) {
plannerInfo.append("<li>Quest available from ");
plannerInfo.append(TimeFormatter.formatTimestamp(planner.getStartInMillis())).append("</li>");
plannerInfo.append(formatTimestamp(planner.getStartInMillis())).append("</li>");
}
//Quest is only available until the end date
if (planner.hasEnd()) {
plannerInfo.append("<li>Quest available until ");
plannerInfo.append(TimeFormatter.formatTimestamp(planner.getEndInMillis())).append("</li>");
plannerInfo.append(formatTimestamp(planner.getEndInMillis())).append("</li>");
}
//Quest availability repeats
if (planner.hasRepeat()) {
plannerInfo.append("<li>Quest will become available again after ");
plannerInfo.append(TimeFormatter.getDurationString(planner.getRepeat() / 1000)).append("</li>");
plannerInfo.append(TimeFormatter.getDurationString(DynmapCitizens.getTranslator(),
planner.getRepeat() / 1000)).append("</li>");
}
plannerInfo.append("</ul>");
return plannerInfo.toString();
}
/**
* Gets a datetime string for the given timestamp
*
* @param timestamp <p>A timestamp in milliseconds</p>
* @return <p>A datetime string</p>
*/
private String formatTimestamp(long timestamp) {
DateFormat format = new SimpleDateFormat("dd MM yyyy HH:mm:ss");
Date date = new Date(timestamp);
return format.format(date);
}
}

View File

@ -1,27 +1,51 @@
package net.knarcraft.dynmapcitizens.handler.trait.quests;
import me.blackvein.quests.QuestsAPI;
import me.blackvein.quests.quests.IQuest;
import me.blackvein.quests.quests.Requirements;
import net.knarcraft.dynmapcitizens.DynmapCitizens;
import net.knarcraft.dynmapcitizens.util.QuestsHelper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.formatting.StringReplacer;
import net.knarcraft.knarlib.formatting.TranslatableMessage;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_BLOCKED_BY_QUEST_FORMAT;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_BLOCKED_BY_QUEST_ITEM;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_EXP;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_FORMAT;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_MC_MMO_SKILL;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_QUEST_POINTS;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_REQUIRED_ITEM_FORMAT;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_REQUIRED_ITEM_ITEM;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_REQUIRED_PERMISSION_FORMAT;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_REQUIRED_PERMISSION_ITEM;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_REQUIRED_QUEST_FORMAT;
import static net.knarcraft.dynmapcitizens.formatting.QuestsTranslatableMessage.QUESTS_REQUIREMENTS_REQUIRED_QUEST_ITEM;
/**
* A class to generate a string containing all information about a quest's requirements
*/
public class QuestRequirementsInfoGenerator {
private final QuestsAPI questsAPI;
private final IQuest quest;
private final StringFormatter formatter;
/**
* Instantiates a new quest requirement info generator
*
* @param quest <p>The quest to generate information about</p>
* @param questsAPI <p>The API to use for getting quest information</p>
* @param quest <p>The quest to generate information about</p>
*/
public QuestRequirementsInfoGenerator(IQuest quest) {
public QuestRequirementsInfoGenerator(QuestsAPI questsAPI, IQuest quest) {
this.questsAPI = questsAPI;
this.quest = quest;
formatter = DynmapCitizens.getFormatter();
}
/**
@ -31,78 +55,140 @@ public class QuestRequirementsInfoGenerator {
*/
public String getQuestRequirementsInfo() {
Requirements requirements = quest.getRequirements();
StringBuilder requirementInfo = new StringBuilder();
if (!requirements.hasRequirement()) {
return requirementInfo.toString();
return "";
}
requirementInfo.append("<b>Requirements: </b><ul>");
StringReplacer replacer = new StringReplacer(DynmapCitizens.getTranslator().getTranslatedMessage(
QUESTS_REQUIREMENTS_FORMAT));
if (requirements.getQuestPoints() > 0) {
requirementInfo.append("<li>").append(requirements.getQuestPoints()).append(" quest points</li>");
}
//Add info about quest point requirement
replacer.add("{requirementQuestPoints}", requirements.getQuestPoints() > 0 ?
formatter.replacePlaceholder(QUESTS_REQUIREMENTS_QUEST_POINTS,
"{questPoints}", String.valueOf(requirements.getQuestPoints())) : "");
if (requirements.getExp() > 0) {
requirementInfo.append("<li>").append(requirements.getExp()).append(" exp</li>");
}
//Add info about exp requirement
replacer.add("{requirementExp}", requirements.getExp() > 0 ? formatter.replacePlaceholder(
QUESTS_REQUIREMENTS_EXP, "{exp}", String.valueOf(requirements.getExp())) : "");
if (!requirements.getBlockQuests().isEmpty()) {
requirementInfo.append("<li>Blocked by quests:<ul>");
for (IQuest blockQuest : requirements.getBlockQuests()) {
requirementInfo.append("<li>").append(blockQuest.getName()).append("</li>");
}
requirementInfo.append("</ul></li>");
}
//Add info about blocking quests
replacer.add("{requirementBlockedByQuests}", !requirements.getBlockQuestIds().isEmpty() ?
getRequirementList(getQuestNames(requirements.getBlockQuestIds()),
QUESTS_REQUIREMENTS_BLOCKED_BY_QUEST_FORMAT, "{blockingQuests}",
QUESTS_REQUIREMENTS_BLOCKED_BY_QUEST_ITEM, "{questName}") : "");
if (!requirements.getNeededQuests().isEmpty()) {
requirementInfo.append("<li>Required quests:<ul>");
for (IQuest neededQuest : requirements.getNeededQuests()) {
requirementInfo.append("<li>").append(neededQuest.getName()).append("</li>");
}
requirementInfo.append("</ul></li>");
}
//Add info about required quests
replacer.add("{requirementRequiredQuests}", !requirements.getBlockQuestIds().isEmpty() ?
getRequirementList(getQuestNames(requirements.getBlockQuestIds()),
QUESTS_REQUIREMENTS_REQUIRED_QUEST_FORMAT, "{requiredQuests}",
QUESTS_REQUIREMENTS_REQUIRED_QUEST_ITEM, "{questName}") : "");
if (!requirements.getItems().isEmpty()) {
requirementInfo.append("<li>Required items:<ul>");
for (ItemStack item : requirements.getItems()) {
requirementInfo.append("<li>").append(QuestsHelper.getUpperCasedItemStackString(item)).append("</li>");
}
requirementInfo.append("</ul></li>");
}
//Add info about required items
replacer.add("{requirementRequiredItems}", !requirements.getItems().isEmpty() ?
getRequirementList(getItemNames(requirements.getItems()), QUESTS_REQUIREMENTS_REQUIRED_ITEM_FORMAT,
"{requiredItems}", QUESTS_REQUIREMENTS_REQUIRED_ITEM_ITEM, "{itemName}") : "");
//Add info about required mcMMO skills
if (!requirements.getMcmmoSkills().isEmpty()) {
List<String> skills = requirements.getMcmmoSkills();
List<Integer> amounts = requirements.getMcmmoAmounts();
StringBuilder mcMMOSkillsBuilder = new StringBuilder();
for (int i = 0; i < skills.size(); i++) {
requirementInfo.append("<li>Requires mcMMO skill ").append(skills.get(i)).append(" at level ");
requirementInfo.append(amounts.get(i)).append("</li>");
mcMMOSkillsBuilder.append(formatter.replacePlaceholders(QUESTS_REQUIREMENTS_MC_MMO_SKILL, new String[]{
"{skill}", "{level}"}, new String[]{skills.get(i), String.valueOf(amounts.get(i))}));
}
replacer.add("{requirementMCMMOSkills}", mcMMOSkillsBuilder.toString());
} else {
replacer.add("{requirementMCMMOSkills}", "");
}
if (!requirements.getPermissions().isEmpty()) {
requirementInfo.append("<li>Required permissions:<ul>");
for (String permission : requirements.getPermissions()) {
requirementInfo.append("<li>").append(permission).append("</li>");
}
requirementInfo.append("</ul></li>");
}
//Add info about required permissions
replacer.add("{requirementPermissions}", !requirements.getPermissions().isEmpty() ?
getRequirementList(requirements.getPermissions(), QUESTS_REQUIREMENTS_REQUIRED_PERMISSION_FORMAT,
"{permissions}", QUESTS_REQUIREMENTS_REQUIRED_PERMISSION_ITEM, "{permission}") : "");
Map<String, Map<String, Object>> customRequirementPlugins = requirements.getCustomRequirements();
StringBuilder customRequirementsBuilder = new StringBuilder();
for (String plugin : customRequirementPlugins.keySet()) {
requirementInfo.append("<li>").append(plugin).append(":<ul>");
customRequirementsBuilder.append("<li>").append(plugin).append(":<ul>");
//Note: The format of custom requirements is kind of weird. First, you have the key for which plugin the
// requirement belongs to. Getting the value of the key gives another map. The map contains as key, the type
// of value, like "Skill Amount" or "Skill Type". The value is the actual value of whatever it is.
Map<String, Object> customRequirementEntry = customRequirementPlugins.get(plugin);
for (String requirementDescription : customRequirementEntry.keySet()) {
requirementInfo.append("<li>").append(requirementDescription).append(" ");
requirementInfo.append(customRequirementEntry.get(requirementDescription)).append("</li>");
customRequirementsBuilder.append("<li>").append(requirementDescription).append(" ");
customRequirementsBuilder.append(customRequirementEntry.get(requirementDescription)).append("</li>");
}
requirementInfo.append("</ul></li>");
customRequirementsBuilder.append("</ul></li>");
}
replacer.add("{requirementCustom}", customRequirementsBuilder.toString());
return replacer.replace();
}
requirementInfo.append("</ul>");
return requirementInfo.toString();
/**
* Gets a list of item names from the given list of items
*
* @param items <p>The items to get the names of</p>
* @return <p>The names of the given items</p>
*/
private List<String> getItemNames(List<ItemStack> items) {
List<String> itemNames = new ArrayList<>();
for (ItemStack itemStack : items) {
itemNames.add(QuestsHelper.getUpperCasedItemStackString(itemStack));
}
return itemNames;
}
/**
* Gets a list of the quest names for the given quests
*
* @param questIds <p>The quests to get names for</p>
* @return <p>A list of quest names</p>
*/
private List<String> getQuestNames(List<String> questIds) {
List<String> questNames = new ArrayList<>(questIds.size());
for (String questId : questIds) {
IQuest quest = getQuest(questId);
if (quest != null) {
questNames.add(quest.getName());
}
}
return questNames;
}
/**
* Gets the quest with the given id
*
* @param questId <p>The id of the quest to get</p>
* @return <p>The quest, or null if not found</p>
*/
private IQuest getQuest(String questId) {
for (IQuest quest : questsAPI.getLoadedQuests()) {
if (quest.getId().equals(questId)) {
return quest;
}
}
return null;
}
/**
* Gets a string for the given list of requirements
*
* @param itemList <p>The items to display in the list of requirements</p>
* @param formatMessage <p>The translatable message describing the list format</p>
* @param formatPlaceholder <p>The placeholder to replace with the list items</p>
* @param itemMessage <p>The translatable message describing each item's format</p>
* @param itemPlaceholder <p>The placeholder to replace with each item in the list</p>
* @return <p>The string corresponding to the given requirement list</p>
*/
private String getRequirementList(List<String> itemList, TranslatableMessage formatMessage, String formatPlaceholder,
TranslatableMessage itemMessage, String itemPlaceholder) {
StringBuilder blockedBuilder = new StringBuilder();
for (Object requirements : itemList) {
blockedBuilder.append(formatter.replacePlaceholder(itemMessage, itemPlaceholder,
String.valueOf(requirements)));
}
return formatter.replacePlaceholder(formatMessage, formatPlaceholder, blockedBuilder.toString());
}
}

View File

@ -94,6 +94,9 @@ public class QuestStagesInfoGenerator {
for (UUID npcId : stage.getNpcsToKill()) {
questInfo.append("<li>Kill NPC ").append(registry.getByUniqueId(npcId).getName()).append("</li>");
}
for (UUID npcId : stage.getNpcsToInteract()) {
questInfo.append("<li>Talk to ").append(registry.getByUniqueId(npcId).getName()).append("</li>");
}
questInfo.append(getQuestItemsTaskString(stage.getBlocksToBreak(), "<li>Break ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getBlocksToCut(), "<li>Cut ")).append("</li>");

View File

@ -163,7 +163,7 @@ public class QuestsHandler extends AbstractTraitHandler {
stringBuilder.append(new QuestRewardsInfoGenerator(quest).getQuestRewardsInfo());
}
if (settings.displayRequirementInfo()) {
stringBuilder.append(new QuestRequirementsInfoGenerator(quest).getQuestRequirementsInfo());
stringBuilder.append(new QuestRequirementsInfoGenerator(questsAPI, quest).getQuestRequirementsInfo());
}
if (settings.displayPlannerInfo()) {
stringBuilder.append(new QuestPlannerInfoGenerator(quest).getQuestPlannerInfo());

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

@ -1,98 +0,0 @@
package net.knarcraft.dynmapcitizens.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static net.knarcraft.blacksmith.formatting.StringFormatter.replacePlaceholder;
/**
* A helper class for time formatting
*/
public class TimeFormatter {
/**
* Gets a datetime string for the given timestamp
*
* @param timestamp <p>A timestamp in milliseconds</p>
* @return <p>A datetime string</p>
*/
public static String formatTimestamp(long timestamp) {
DateFormat format = new SimpleDateFormat("dd MM yyyy HH:mm:ss");
Date date = new Date(timestamp);
return format.format(date);
}
/**
* Gets the string used for displaying this sign's duration
*
* @return <p>The string used for displaying this sign's duration</p>
*/
public static String getDurationString(long duration) {
if (duration == 0) {
return "immediately";
} else {
double minute = 60;
double hour = minute * 60;
double day = hour * 24;
double week = day * 7;
double month = day * 30;
double year = day * 365;
double decade = year * 10;
Map<Double, String[]> timeUnits = new HashMap<>();
timeUnits.put(decade, new String[]{"decade", "decades"});
timeUnits.put(year, new String[]{"year", "years"});
timeUnits.put(month, new String[]{"month", "months"});
timeUnits.put(week, new String[]{"week", "weeks"});
timeUnits.put(day, new String[]{"day", "days"});
timeUnits.put(hour, new String[]{"hour", "hours"});
timeUnits.put(minute, new String[]{"minute", "minutes"});
timeUnits.put(1D, new String[]{"second", "seconds"});
List<Double> sortedUnits = new ArrayList<>(timeUnits.keySet());
Collections.sort(sortedUnits);
Collections.reverse(sortedUnits);
for (Double unit : sortedUnits) {
if (duration / unit >= 1) {
double units = round(duration / unit);
return formatDurationString(units, timeUnits.get(unit)[units == 1 ? 0 : 1],
(units * 10) % 10 == 0);
}
}
return formatDurationString(duration, "seconds", false);
}
}
/**
* Rounds a number to its last two digits
*
* @param number <p>The number to round</p>
* @return <p>The rounded number</p>
*/
private static double round(double number) {
return Math.round(number * 100.0) / 100.0;
}
/**
* Formats a duration string
*
* @param duration <p>The duration to display</p>
* @param translatableMessage <p>The time unit to display</p>
* @param castToInt <p>Whether to cast the duration to an int</p>
* @return <p>The formatted duration string</p>
*/
private static String formatDurationString(double duration, String translatableMessage, boolean castToInt) {
String durationFormat = "{duration} {unit}";
durationFormat = replacePlaceholder(durationFormat, "{unit}", translatableMessage);
return replacePlaceholder(durationFormat, "{duration}", castToInt ? String.valueOf((int) duration) :
String.valueOf(duration));
}
}

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

View File

@ -0,0 +1,76 @@
en:
SENTINEL_DESCRIPTION: |
<h2>{name}</h2>
<br><b>Squad:</b> {squad}
{sentinelDetails}
SENTINEL_DETAILS: |
<ul>
<li><b>Invincible:</b> {invincible}</li>
<li><b>Armor:</b> {armor}</li>
<li><b>Health:</b> {health}</li>
<li><b>Accuracy:</b> {accuracy}</li>
<li><b>Damage:</b> {damage}</li>
<li><b>Speed:</b> {speed}</li>
<li><b>Allow knockback:</b> {allowKnockback}</li>
<li><b>Range:</b> {range}</li>
<li><b>Reach:</b> {reach}</li>
<li><b>Targets:</b> {targets}</li>
<li><b>Avoids:</b> {avoids}</li>
<li><b>Ignores:</b> {ignores}</li>
</ul>
QUESTS_PLANNER_DESCRIPTION: |
<b>Planner:</b><ul>
{questCoolDown}
{questFrom}
{questUntil}
{questRepeat}
</ul>
QUESTS_PLANNER_COOL_DOWN: "<li>Quest repeatable after: {coolDown}</li>"
QUESTS_PLANNER_UNREPEATABLE: "<li>Quest cannot be repeated!</li>"
QUESTS_PLANNER_FROM: "<li>Quest available from {startDate}</li>"
QUESTS_PLANNER_UNTIL: "<li>Quest available until {endDate}</li>"
QUEST_PLANNER_REPEAT: "<li>Quest will become available again after {repeatDelay}</li>"
QUESTS_REQUIREMENTS_FORMAT: |
<b>Requirements: </b><ul>
{requirementQuestPoints}
{requirementExp}
{requirementBlockedByQuests}
{requirementRequiredQuests}
{requirementRequiredItems}
{requirementMCMMOSkills}
{requirementPermissions}
{requirementCustom}
</ul>
QUESTS_REQUIREMENTS_QUEST_POINTS: "<li>{questPoints} quest points</li>"
QUESTS_REQUIREMENTS_EXP: "<li>{exp} exp</li>"
QUESTS_REQUIREMENTS_BLOCKED_BY_QUEST_FORMAT: "<li>Blocked by quests:<ul>{blockingQuests}</ul></li>"
QUESTS_REQUIREMENTS_BLOCKED_BY_QUEST_ITEM: "<li>{questName}</li>"
QUESTS_REQUIREMENTS_REQUIRED_QUEST_FORMAT: "<li>Required quests:<ul>{requiredQuests}</ul></li>"
QUESTS_REQUIREMENTS_REQUIRED_QUEST_ITEM: "<li>{questName}</li>"
QUESTS_REQUIREMENTS_REQUIRED_ITEM_FORMAT: "<li>Required items:<ul>{requiredItems}</ul></li>"
QUESTS_REQUIREMENTS_REQUIRED_ITEM_ITEM: "<li>{itemName}</li>"
QUESTS_REQUIREMENTS_MC_MMO_SKILL: "<li>Requires mcMMO skill {skill} at level {level}</li>"
QUESTS_REQUIREMENTS_REQUIRED_PERMISSION_FORMAT: "<li>Required permissions:<ul>{permissions}</ul></li>"
QUESTS_REQUIREMENTS_REQUIRED_PERMISSION_ITEM: "<li>{permission}</li>"
QUESTS_REACH_AREA_NAME_FORMAT: "<b>{name}</b><br>"
QUESTS_REACH_AREA_DESCRIPTION_FORMAT: "{areaName}Target location for {questName}"
QUESTS_KILL_AREA_NAME_FORMAT: "<b>{name}</b><br>"
QUESTS_KILL_AREA_DESCRIPTION_FORMAT: "{areaName}Kill location for {questName}<br>Kill {mobName} x {mobAmount}"
DURATION_FORMAT: "in {time} {unit}"
UNIT_NOW: "imminently"
UNIT_SECOND: "second"
UNIT_SECONDS: "seconds"
UNIT_MINUTE: "minute"
UNIT_MINUTES: "minutes"
UNIT_HOUR: "hour"
UNIT_HOURS: "hours"
UNIT_DAY: "day"
UNIT_DAYS: "days"
UNIT_WEEK: "week"
UNIT_WEEKS: "weeks"
UNIT_MONTH: "month"
UNIT_MONTHS: "months"
UNIT_YEAR: "year"
UNIT_YEARS: "years"
UNIT_DECADE: "decade"
UNIT_DECADES: "decades"