Prints the correct currency if Vault is available

This commit is contained in:
Kristian Knarvik 2022-11-01 17:54:11 +01:00
parent 7767a3f3eb
commit 3e93b4a733
5 changed files with 101 additions and 12 deletions

10
pom.xml
View File

@ -74,6 +74,10 @@
<id>citizens-repo</id>
<url>http://repo.citizensnpcs.co/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
</repositories>
<dependencies>
@ -126,6 +130,12 @@
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId>
<version>1.7.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mcmonkey</groupId>
<artifactId>sentinel</artifactId>

View File

@ -26,6 +26,7 @@ public final class DynmapCitizens extends JavaPlugin {
private static DynmapCitizens instance;
private DynmapAPI dynmapAPI;
private Map<Icon, MarkerIcon> markerIcons;
private VaultHandler vaultHandler;
@Override
public void onEnable() {
@ -69,11 +70,22 @@ public final class DynmapCitizens extends JavaPlugin {
//TODO: It would probably make more sense to have individual timers for each marker based on whether the
// NPC is likely to move about.
}, 5 * 20, 5 * 20);
vaultHandler = new VaultHandler(this.getServer().getServicesManager());
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
/**
* Gets the Vault handler to use for anything Vault-related
*
* @return <p>The Vault handler</p>
*/
public VaultHandler getVaultHandler() {
return vaultHandler;
}
/**

View File

@ -0,0 +1,48 @@
package net.knarcraft.dynmapcitizens;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicesManager;
/**
* A class to keep track of everything Vault
*/
public class VaultHandler {
private Economy economy = null;
/**
* Instantiates a new Vault handler
*
* @param servicesManager <p>The services manager to get the Vault service from</p>
*/
public VaultHandler(ServicesManager servicesManager) {
RegisteredServiceProvider<Economy> economyProvider = servicesManager.getRegistration(Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
}
}
/**
* Gets whether Vault is enabled
*
* @return <p>True if Vault is enabled</p>
*/
public boolean isEnabled() {
return economy != null && economy.isEnabled();
}
/**
* Gets the name of the used currency
*
* @return <p>The currency name</p>
*/
public String getCurrency(boolean plural) {
if (plural) {
return economy.currencyNamePlural();
} else {
return economy.currencyNameSingular();
}
}
}

View File

@ -12,6 +12,7 @@ import net.citizensnpcs.api.npc.NPCRegistry;
import net.knarcraft.dynmapcitizens.DynmapCitizens;
import net.knarcraft.dynmapcitizens.Icon;
import net.knarcraft.dynmapcitizens.UpdateRate;
import net.knarcraft.dynmapcitizens.VaultHandler;
import net.knarcraft.dynmapcitizens.trait.AbstractTraitHandler;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -169,14 +170,12 @@ public class QuestsHandler extends AbstractTraitHandler {
StringBuilder plannerInfo = new StringBuilder();
plannerInfo.append("<b>Planner:</b><ul>");
//Quest is repeatable
if (planner.hasRepeat()) {
plannerInfo.append("<li>Can be repeated after ").append(getDurationString(planner.getRepeat() / 1000));
}
//Quest has cool-down
//Quest can be repeated after a cool-down
if (planner.hasCooldown()) {
plannerInfo.append("<li>Cool-down: ").append(getDurationString(planner.getCooldown() / 1000)).append("</li>");
plannerInfo.append("<li>Quest repeatable after: ").append(getDurationString(planner.getCooldown() / 1000));
plannerInfo.append("</li>");
} else {
plannerInfo.append("<li>Quest cannot be repeated!</li>");
}
//Quest only becomes available after the start date
@ -193,6 +192,12 @@ public class QuestsHandler extends AbstractTraitHandler {
plannerInfo.append("<li>Quest available until ").append(format.format(date)).append("</li>");
}
//Quest availability repeats
if (planner.hasRepeat()) {
plannerInfo.append("<li>Quest will become available again after ");
plannerInfo.append(getDurationString(planner.getRepeat() / 1000)).append("</li>");
}
plannerInfo.append("</ul>");
return plannerInfo.toString();
}
@ -357,12 +362,11 @@ public class QuestsHandler extends AbstractTraitHandler {
rewardInfo.append("<b>Rewards:</b><ul>");
if (reward.getMoney() > 0) {
//TODO: Get the currency from Vault
rewardInfo.append("<li>").append(reward.getMoney()).append(" money").append("</li>");
rewardInfo.append("<li>").append(reward.getMoney()).append(" ").append(getCurrency(reward.getMoney())).append("</li>");
}
if (reward.getExp() > 0) {
rewardInfo.append("<li>").append(reward.getMoney()).append(" exp").append("</li>");
rewardInfo.append("<li>").append(reward.getExp()).append(" exp").append("</li>");
}
for (String permission : reward.getPermissions()) {
@ -381,6 +385,21 @@ public class QuestsHandler extends AbstractTraitHandler {
return rewardInfo.toString();
}
/**
* Gets the currency to print for the given amount of money
*
* @param money <p>The amount to pay/use</p>
* @return <p>The currency name to use</p>
*/
private String getCurrency(double money) {
VaultHandler vaultHandler = DynmapCitizens.getInstance().getVaultHandler();
if (vaultHandler.isEnabled()) {
return vaultHandler.getCurrency(money != 1);
} else {
return "money";
}
}
/**
* Gets the marker title to use for the given quest NPC type
*

View File

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