diff --git a/pom.xml b/pom.xml index 96c2504..ca25666 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,10 @@ citizens-repo http://repo.citizensnpcs.co/ + + vault-repo + http://nexus.hc.to/content/repositories/pub_releases + @@ -126,6 +130,12 @@ 1.0-SNAPSHOT provided + + net.milkbowl.vault + Vault + 1.7.3 + provided + org.mcmonkey sentinel diff --git a/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java b/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java index 57df48a..99afdf6 100644 --- a/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java +++ b/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java @@ -26,6 +26,7 @@ public final class DynmapCitizens extends JavaPlugin { private static DynmapCitizens instance; private DynmapAPI dynmapAPI; private Map 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

The Vault handler

+ */ + public VaultHandler getVaultHandler() { + return vaultHandler; } /** diff --git a/src/main/java/net/knarcraft/dynmapcitizens/VaultHandler.java b/src/main/java/net/knarcraft/dynmapcitizens/VaultHandler.java new file mode 100644 index 0000000..1ea5723 --- /dev/null +++ b/src/main/java/net/knarcraft/dynmapcitizens/VaultHandler.java @@ -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

The services manager to get the Vault service from

+ */ + public VaultHandler(ServicesManager servicesManager) { + RegisteredServiceProvider economyProvider = servicesManager.getRegistration(Economy.class); + if (economyProvider != null) { + economy = economyProvider.getProvider(); + } + } + + /** + * Gets whether Vault is enabled + * + * @return

True if Vault is enabled

+ */ + public boolean isEnabled() { + return economy != null && economy.isEnabled(); + } + + /** + * Gets the name of the used currency + * + * @return

The currency name

+ */ + public String getCurrency(boolean plural) { + if (plural) { + return economy.currencyNamePlural(); + } else { + return economy.currencyNameSingular(); + } + } + +} diff --git a/src/main/java/net/knarcraft/dynmapcitizens/trait/quests/QuestsHandler.java b/src/main/java/net/knarcraft/dynmapcitizens/trait/quests/QuestsHandler.java index 5a3f226..3e69e57 100644 --- a/src/main/java/net/knarcraft/dynmapcitizens/trait/quests/QuestsHandler.java +++ b/src/main/java/net/knarcraft/dynmapcitizens/trait/quests/QuestsHandler.java @@ -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("Planner:
    "); - //Quest is repeatable - if (planner.hasRepeat()) { - plannerInfo.append("
  • 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("
  • Cool-down: ").append(getDurationString(planner.getCooldown() / 1000)).append("
  • "); + plannerInfo.append("
  • Quest repeatable after: ").append(getDurationString(planner.getCooldown() / 1000)); + plannerInfo.append("
  • "); + } else { + plannerInfo.append("
  • Quest cannot be repeated!
  • "); } //Quest only becomes available after the start date @@ -193,6 +192,12 @@ public class QuestsHandler extends AbstractTraitHandler { plannerInfo.append("
  • Quest available until ").append(format.format(date)).append("
  • "); } + //Quest availability repeats + if (planner.hasRepeat()) { + plannerInfo.append("
  • Quest will become available again after "); + plannerInfo.append(getDurationString(planner.getRepeat() / 1000)).append("
  • "); + } + plannerInfo.append("
"); return plannerInfo.toString(); } @@ -357,12 +362,11 @@ public class QuestsHandler extends AbstractTraitHandler { rewardInfo.append("Rewards:
    "); if (reward.getMoney() > 0) { - //TODO: Get the currency from Vault - rewardInfo.append("
  • ").append(reward.getMoney()).append(" money").append("
  • "); + rewardInfo.append("
  • ").append(reward.getMoney()).append(" ").append(getCurrency(reward.getMoney())).append("
  • "); } if (reward.getExp() > 0) { - rewardInfo.append("
  • ").append(reward.getMoney()).append(" exp").append("
  • "); + rewardInfo.append("
  • ").append(reward.getExp()).append(" exp").append("
  • "); } 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

    The amount to pay/use

    + * @return

    The currency name to use

    + */ + 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 * diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b31a804..44e9440 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -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