From cdd95e2a9b64123e26a0fce84d89e4d9720f5bfb Mon Sep 17 00:00:00 2001 From: montlikadani Date: Sat, 9 Nov 2019 19:50:09 +0100 Subject: [PATCH] Added cost for skipping quests --- Changelog.txt | 1 + .../jobs/commands/list/skipquest.java | 17 +++++++++++++++++ .../jobs/config/GeneralConfigManager.java | 5 ++++- .../gamingmesh/jobs/config/LanguageManager.java | 3 ++- .../jobs/economy/BufferedEconomy.java | 4 ++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 7c6d680b..e662229f 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,5 +1,6 @@ # 4.15.0 - Fixed issue when the quest description only showed one lines of list. +- Added cost for skipping quests # 4.14.0 - Fixed %titlename% placeholder does not showed anything diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java b/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java index da22740c..581ab324 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java @@ -13,6 +13,7 @@ import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Quest; import com.gamingmesh.jobs.container.QuestProgression; +import com.gamingmesh.jobs.economy.BufferedEconomy; public class skipquest implements Cmd { @@ -77,10 +78,26 @@ public class skipquest implements Cmd { if (Jobs.getGCManager().getDailyQuestsSkips() <= jPlayer.getSkippedQuests()) return false; + double amount = Jobs.getGCManager().skipQuestCost; + BufferedEconomy econ = Jobs.getEconomy(); + if (amount > 0) { + if (!econ.getEconomy().hasMoney(jPlayer.getPlayer(), amount)) { + sender.sendMessage(Jobs.getLanguage().getMessage("economy.error.nomoney")); + return false; + } + + econ.getEconomy().withdrawPlayer(jPlayer.getPlayer(), amount); + } + jPlayer.replaceQuest(old); if (jPlayer.isOnline()) Bukkit.dispatchCommand(jPlayer.getPlayer(), "jobs quests"); + + if (amount > 0) { + sender.sendMessage(Jobs.getLanguage().getMessage("command.skipquest.output.questSkipForCost", "%amount%", amount)); + } + return true; } } diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 7331ca09..c5db7154 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -78,6 +78,7 @@ public class GeneralConfigManager { private int ResetTimeHour; private int ResetTimeMinute; private int DailyQuestsSkips; + public double skipQuestCost; private ConfigReader c = null; // Limits @@ -526,8 +527,10 @@ public class GeneralConfigManager { "Any daily quests given before reset will be invalid and new ones will be given out"); ResetTimeHour = c.get("DailyQuests.ResetTime.Hour", 4); ResetTimeMinute = c.get("DailyQuests.ResetTime.Minute", 0); - c.addComment("DailyQuests.Skips", "Defines amount of skips player can do on a quest","This allows player to abandon current quest and get new one"); + c.addComment("DailyQuests.Skips", "Defines amount of skips player can do on a quest", "This allows player to abandon current quest and get new one"); DailyQuestsSkips = c.get("DailyQuests.Skips", 1); + c.addComment("DailyQuests.SkipQuestCost", "The cost of the quest skip (money).", "Default 0, disabling cost of skipping quest."); + skipQuestCost = c.get("DailyQuests.SkipQuestCost", 0d); c.addComment("ScheduleManager", "Enables the schedule manager to boost the server.", "By default this has been disabled for causing memory leak."); enableSchedule = c.get("ScheduleManager.Use", true); diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index 502dec33..7583eff8 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -507,7 +507,8 @@ public class LanguageManager { c.get("command.skipquest.help.info", "Skip defined quest and get new one"); c.get("command.skipquest.help.args", "[jobname] [questname] (playerName)"); - + c.get("command.skipquest.output.questSkipForCost", "&2You skipped the quest and paid:&e %amount%$"); + c.get("command.quests.help.info", "List available quests"); c.get("command.quests.help.args", "[playername]"); Jobs.getGCManager().getCommandArgs().put("quests", Arrays.asList("[playername]")); diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java index 30b3e0b1..c89b7242 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java @@ -49,6 +49,10 @@ public class BufferedEconomy { this.economy = economy; } + public Economy getEconomy() { + return economy; + } + /** * Add payment to player's payment buffer * @param player - player to be paid