NEW cow milking objective

This commit is contained in:
PikaMug 2020-01-19 03:35:38 -05:00
parent 669d93887a
commit e8f15411c7
9 changed files with 178 additions and 10 deletions

View File

@ -1255,12 +1255,23 @@ public class QuestData {
}
};
private int cowsMilked = 0;
private int fishCaught = 0;
private int playersKilled = 0;
private long delayStartTime = 0;
private long delayTimeLeft = -1;
private boolean delayOver = true;
public int getCowsMilked() {
return cowsMilked;
}
public void setCowsMilked(int cowsMilked) {
this.cowsMilked = cowsMilked;
if (doJournalUpdate)
quester.updateJournal();
}
public int getFishCaught() {
return fishCaught;
}

View File

@ -788,6 +788,9 @@ public class QuestFactory implements ConversationAbandonedListener {
}
cc.setSessionData(pref + CK.S_BREW_ITEMS, items);
}
if (stage.cowsToMilk != null) {
cc.setSessionData(pref + CK.S_COW_MILK, stage.cowsToMilk);
}
if (stage.fishToCatch != null) {
cc.setSessionData(pref + CK.S_FISH, stage.fishToCatch);
}
@ -1715,6 +1718,7 @@ public class QuestFactory implements ConversationAbandonedListener {
LinkedList<Integer> enchantmentIds;
LinkedList<Integer> enchantmentAmounts;
LinkedList<ItemStack> brewItems;
Integer cows;
Integer fish;
Integer players;
LinkedList<ItemStack> deliveryItems;
@ -1778,6 +1782,7 @@ public class QuestFactory implements ConversationAbandonedListener {
enchantmentIds = null;
enchantmentAmounts = null;
brewItems = null;
cows = null;
fish = null;
players = null;
deliveryItems = null;
@ -1856,6 +1861,9 @@ public class QuestFactory implements ConversationAbandonedListener {
if (cc.getSessionData(pref + CK.S_BREW_ITEMS) != null) {
brewItems = (LinkedList<ItemStack>) cc.getSessionData(pref + CK.S_BREW_ITEMS);
}
if (cc.getSessionData(pref + CK.S_COW_MILK) != null) {
cows = (Integer) cc.getSessionData(pref + CK.S_COW_MILK);
}
if (cc.getSessionData(pref + CK.S_FISH) != null) {
fish = (Integer) cc.getSessionData(pref + CK.S_FISH);
}
@ -1985,6 +1993,7 @@ public class QuestFactory implements ConversationAbandonedListener {
} else {
stage.set("items-to-brew", null);
}
stage.set("cows-to-milk", cows);
stage.set("fish-to-catch", fish);
stage.set("players-to-kill", players);
if (deliveryItems != null && deliveryItems.isEmpty() == false) {

View File

@ -724,6 +724,15 @@ public class Quester {
finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + brewed + "/" + amt);
}
}
if (getCurrentStage(quest).cowsToMilk != null) {
if (getQuestData(quest).getCowsMilked() < getCurrentStage(quest).cowsToMilk) {
unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "milkCow") + ChatColor.GREEN + ": "
+ getQuestData(quest).getCowsMilked() + "/" + getCurrentStage(quest).cowsToMilk);
} else {
finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "milkCow") + ChatColor.GRAY + ": "
+ getQuestData(quest).getCowsMilked() + "/" + getCurrentStage(quest).cowsToMilk);
}
}
if (getCurrentStage(quest).fishToCatch != null) {
if (getQuestData(quest).getFishCaught() < getCurrentStage(quest).fishToCatch) {
unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "catchFish") + ChatColor.GREEN + ": "
@ -966,7 +975,7 @@ public class Quester {
* Check if player's current stage has the specified objective<p>
*
* Accepted strings are: breakBlock, damageBlock, placeBlock, useBlock,
* cutBlock, craftItem, smeltItem, enchantItem, brewItem, catchFish,
* cutBlock, craftItem, smeltItem, enchantItem, brewItem, milkCow, catchFish,
* killMob, deliverItem, killPlayer, talkToNPC, killNPC, tameMob,
* shearSheep, password, reachLocation
*
@ -983,7 +992,7 @@ public class Quester {
* Check if player's current stage has the specified objective<p>
*
* Accepted strings are: breakBlock, damageBlock, placeBlock, useBlock,
* cutBlock, craftItem, smeltItem, enchantItem, brewItem, catchFish,
* cutBlock, craftItem, smeltItem, enchantItem, brewItem, milkCow, catchFish,
* killMob, deliverItem, killPlayer, talkToNPC, killNPC, tameMob,
* shearSheep, password, reachLocation
*
@ -1013,6 +1022,8 @@ public class Quester {
return !getCurrentStage(quest).itemsToEnchant.isEmpty();
} else if (s.equalsIgnoreCase("brewItem")) {
return !getCurrentStage(quest).itemsToBrew.isEmpty();
} else if (s.equalsIgnoreCase("milkCow")) {
return getCurrentStage(quest).cowsToMilk != null;
} else if (s.equalsIgnoreCase("catchFish")) {
return getCurrentStage(quest).fishToCatch != null;
} else if (s.equalsIgnoreCase("killMob")) {
@ -1583,6 +1594,31 @@ public class Quester {
}
}
/**
* Mark cow as milked if Quester has such an objective
*
* @param quest The quest for which the fish is being caught
*/
public void milkCow(Quest quest) {
final int cowsToMilk = getCurrentStage(quest).cowsToMilk;
if (getQuestData(quest).getCowsMilked() < cowsToMilk) {
getQuestData(quest).setCowsMilked(getQuestData(quest).getCowsMilked() + 1);
if (getQuestData(quest).getCowsMilked() == cowsToMilk) {
finishObjective(quest, "milkCow", new ItemStack(Material.AIR, 1),
new ItemStack(Material.AIR, cowsToMilk), null, null, null, null, null, null, null, null);
// Multiplayer
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> {
q.getQuestData(quest).setCowsMilked(cowsToMilk);
q.finishObjective(quest, "milkCow", new ItemStack(Material.AIR, 1),
new ItemStack(Material.AIR, cowsToMilk), null, null, null, null, null, null, null, null);
return null;
});
}
}
}
/**
* Mark fish as caught if Quester has such an objective
*
@ -2137,6 +2173,10 @@ public class Quester {
} else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(is)));
}
} else if (objective.equalsIgnoreCase("milkCow")) {
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "milkCow") + " ";
message = message + " " + goal.getAmount() + "/" + goal.getAmount();
p.sendMessage(message);
} else if (objective.equalsIgnoreCase("catchFish")) {
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "catchFish") + " ";
message = message + " " + goal.getAmount() + "/" + goal.getAmount();
@ -2321,6 +2361,7 @@ public class Quester {
}
}
}
data.setCowsMilked(0);
data.setFishCaught(0);
data.setPlayersKilled(0);
if (quest.getStage(stage).itemsToDeliver.isEmpty() == false) {
@ -2536,6 +2577,9 @@ public class Quester {
}
questSec.set("item-brew-amounts", brewAmounts);
}
if (getCurrentStage(quest).cowsToMilk != null) {
questSec.set("cows-milked", questData.getCowsMilked());
}
if (getCurrentStage(quest).fishToCatch != null) {
questSec.set("fish-caught", questData.getFishCaught());
}
@ -2949,6 +2993,9 @@ public class Quester {
}
}
}
if (questSec.contains("cows-milked")) {
getQuestData(quest).setCowsMilked(questSec.getInt("cows-milked"));
}
if (questSec.contains("fish-caught")) {
getQuestData(quest).setFishCaught(questSec.getInt("fish-caught"));
}
@ -3373,7 +3420,7 @@ public class Quester {
* Dispatch player event to fellow questers<p>
*
* Accepted strings are: breakBlock, damageBlock, placeBlock, useBlock,
* cutBlock, craftItem, smeltItem, enchantItem, brewItem, catchFish,
* cutBlock, craftItem, smeltItem, enchantItem, brewItem, milkCow, catchFish,
* killMob, deliverItem, killPlayer, talkToNPC, killNPC, tameMob,
* shearSheep, password, reachLocation
*

View File

@ -923,6 +923,21 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
}
}
if (stage.cowsToMilk != null) {
ChatColor color = data.getCowsMilked() < stage.cowsToMilk ? ChatColor.GREEN : ChatColor.GRAY;
String message = "";
if (!ignoreOverrides && quester.getCurrentStage(quest).objectiveOverride != null) {
message = color + quester.getCurrentStage(quest).objectiveOverride
+ color + ": " + data.getCowsMilked() + "/" + stage.cowsToMilk;
} else {
message = color + Lang.get(quester.getPlayer(), "milkCow")
+ color + ": " + data.getCowsMilked() + "/" + stage.cowsToMilk;
}
if (depends.getPlaceholderApi() != null) {
message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message);
}
quester.getPlayer().sendMessage(message);
}
if (stage.fishToCatch != null) {
ChatColor color = data.getFishCaught() < stage.fishToCatch ? ChatColor.GREEN : ChatColor.GRAY;
String message = "";
@ -2321,6 +2336,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
}
}
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".cows-to-milk")) {
if (config.getInt("quests." + questKey + ".stages.ordered." + stageNum + ".cows-to-milk", -999) != -999) {
oStage.cowsToMilk = config.getInt("quests." + questKey + ".stages.ordered." + stageNum
+ ".cows-to-milk");
} else {
failStageProcess("cows-to-milk is not a number", quest, stageNum);
}
}
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".fish-to-catch")) {
if (config.getInt("quests." + questKey + ".stages.ordered." + stageNum + ".fish-to-catch", -999) != -999) {
oStage.fishToCatch = config.getInt("quests." + questKey + ".stages.ordered." + stageNum

View File

@ -35,6 +35,7 @@ public class Stage {
protected LinkedList<ItemStack> blocksToPlace = new LinkedList<ItemStack>();
protected LinkedList<ItemStack> blocksToUse = new LinkedList<ItemStack>();
protected LinkedList<ItemStack> blocksToCut = new LinkedList<ItemStack>();
protected Integer cowsToMilk;
protected Integer fishToCatch;
protected Integer playersToKill;
protected LinkedList<ItemStack> itemsToCraft = new LinkedList<ItemStack>();
@ -171,6 +172,14 @@ public class Stage {
public void setBlocksToCut(LinkedList<ItemStack> blocksToCut) {
this.blocksToCut = blocksToCut;
}
public Integer getCowsToMilk() {
return cowsToMilk;
}
public void setCowsToMilk(Integer cowsToMilk) {
this.cowsToMilk = cowsToMilk;
}
public Integer getFishToCatch() {
return fishToCatch;
@ -512,6 +521,7 @@ public class Stage {
if (blocksToPlace.isEmpty() == false) { return true; }
if (blocksToUse.isEmpty() == false) { return true; }
if (blocksToCut.isEmpty() == false) { return true; }
if (cowsToMilk != null) { return true; }
if (fishToCatch != null) { return true; }
if (playersToKill != null) { return true; }
if (itemsToCraft.isEmpty() == false) { return true; }

View File

@ -52,6 +52,7 @@ import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
@ -389,6 +390,26 @@ public class PlayerListener implements Listener {
}
}
}
@EventHandler
public void onPlayerBucketFill(PlayerBucketFillEvent evt) {
if (evt.getItemStack().getType() == Material.MILK_BUCKET) {
Player player = evt.getPlayer();
if (plugin.canUseQuests(player.getUniqueId())) {
Quester quester = plugin.getQuester(player.getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "milkCow")) {
quester.milkCow(quest);
}
quester.dispatchMultiplayerEverything(quest, "milkCow", (Quester q) -> {
q.milkCow(quest);
return null;
});
}
}
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent evt) {

View File

@ -44,7 +44,7 @@ public class MobsPrompt extends FixedSetPrompt {
private final QuestFactory questFactory;
public MobsPrompt(Quests plugin, int stageNum, QuestFactory qf) {
super("1", "2", "3", "4", "5");
super("1", "2", "3", "4", "5", "6");
this.plugin = plugin;
this.stageNum = stageNum;
this.pref = "stage" + stageNum;
@ -95,11 +95,20 @@ public class MobsPrompt extends FixedSetPrompt {
+ "- " + Lang.get("stageEditorCatchFish") + " " + ChatColor.GRAY + "(" + ChatColor.AQUA + fish
+ " " + Lang.get("stageEditorFish") + ChatColor.GRAY + ")\n";
}
if (context.getSessionData(pref + CK.S_TAME_TYPES) == null) {
if (context.getSessionData(pref + CK.S_COW_MILK) == null) {
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "3 " + ChatColor.RESET + ChatColor.LIGHT_PURPLE
+ "- " + Lang.get("stageEditorMilkCows") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n";
} else {
Integer cows = (Integer) context.getSessionData(pref + CK.S_COW_MILK);
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "3 " + ChatColor.RESET + ChatColor.LIGHT_PURPLE
+ "- " + Lang.get("stageEditorMilkCows") + " " + ChatColor.GRAY + "(" + ChatColor.AQUA + cows
+ " " + Lang.get("stageEditorCows") + ChatColor.GRAY + ")\n";
}
if (context.getSessionData(pref + CK.S_TAME_TYPES) == null) {
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "4 " + ChatColor.RESET + ChatColor.LIGHT_PURPLE
+ "- " + Lang.get("stageEditorTameMobs") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n";
} else {
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "3 " + ChatColor.RESET + ChatColor.LIGHT_PURPLE
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "4 " + ChatColor.RESET + ChatColor.LIGHT_PURPLE
+ "- " + Lang.get("stageEditorTameMobs") + "\n";
LinkedList<String> mobs = (LinkedList<String>) context.getSessionData(pref + CK.S_TAME_TYPES);
LinkedList<Integer> amounts = (LinkedList<Integer>) context.getSessionData(pref + CK.S_TAME_AMOUNTS);
@ -109,10 +118,10 @@ public class MobsPrompt extends FixedSetPrompt {
}
}
if (context.getSessionData(pref + CK.S_SHEAR_COLORS) == null) {
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "4 " + ChatColor.RESET + ChatColor.LIGHT_PURPLE
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "5 " + ChatColor.RESET + ChatColor.LIGHT_PURPLE
+ "- " + Lang.get("stageEditorShearSheep") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n";
} else {
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "4 " + ChatColor.RESET + ChatColor.LIGHT_PURPLE
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "5 " + ChatColor.RESET + ChatColor.LIGHT_PURPLE
+ "- " + Lang.get("stageEditorShearSheep") + "\n";
LinkedList<String> colors = (LinkedList<String>) context.getSessionData(pref + CK.S_SHEAR_COLORS);
LinkedList<Integer> amounts = (LinkedList<Integer>) context.getSessionData(pref + CK.S_SHEAR_AMOUNTS);
@ -121,7 +130,7 @@ public class MobsPrompt extends FixedSetPrompt {
+ ChatColor.AQUA + amounts.get(i) + "\n";
}
}
text += ChatColor.GREEN + "" + ChatColor.BOLD + "5 " + ChatColor.RESET + ChatColor.DARK_PURPLE + "- "
text += ChatColor.GREEN + "" + ChatColor.BOLD + "6 " + ChatColor.RESET + ChatColor.DARK_PURPLE + "- "
+ Lang.get("done") + "\n";
return text;
}
@ -133,8 +142,10 @@ public class MobsPrompt extends FixedSetPrompt {
} else if (input.equalsIgnoreCase("2")) {
return new FishPrompt();
} else if (input.equalsIgnoreCase("3")) {
return new TameListPrompt();
return new CowsPrompt();
} else if (input.equalsIgnoreCase("4")) {
return new TameListPrompt();
} else if (input.equalsIgnoreCase("5")) {
return new ShearListPrompt();
}
try {
@ -544,6 +555,37 @@ public class MobsPrompt extends FixedSetPrompt {
}
}
private class CowsPrompt extends StringPrompt {
@Override
public String getPromptText(ConversationContext context) {
return ChatColor.YELLOW + Lang.get("stageEditorMilkCowsPrompt");
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
try {
int i = Integer.parseInt(input);
if (i < 0) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorPositiveAmount"));
return new CowsPrompt();
} else if (i > 0) {
context.setSessionData(pref + CK.S_COW_MILK, i);
}
} catch (NumberFormatException e) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqNotANumber")
.replace("<input>", input));
return new CowsPrompt();
}
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
context.setSessionData(pref + CK.S_COW_MILK, null);
}
return new StageMainPrompt(plugin, stageNum, questFactory);
}
}
private class TameListPrompt extends FixedSetPrompt {
public TameListPrompt() {

View File

@ -60,6 +60,7 @@ public class CK {
public static final String S_CUT_NAMES = "cutNames";
public static final String S_CUT_AMOUNTS = "cutAmounts";
public static final String S_CUT_DURABILITY = "cutDurability";
public static final String S_COW_MILK = "cowMilk";
public static final String S_FISH = "fish";
public static final String S_PLAYER_KILL = "playerKill";
public static final String S_CRAFT_ITEMS = "craftItems";

View File

@ -130,6 +130,8 @@ stageEditorMobs: "Mobs"
stageEditorKillMobs: "Kill mobs"
stageEditorCatchFish: "Catch fish"
stageEditorFish: "fish"
stageEditorMilkCows: "Milk cows"
stageEditorCows: "cows"
stageEditorReachLocs: "Reach locations"
stageEditorReachRadii1: "Reach within"
stageEditorReachRadii2: "blocks of"
@ -193,6 +195,7 @@ stageEditorEnterBlockNames: "Enter block names, <space>, <cancel>"
stageEditorEnterBlockAmounts: "Enter block amounts, <space>, <cancel>"
stageEditorEnterBlockDurability: "Enter block durabilities (numbers), <space>, <cancel>"
stageEditorCatchFishPrompt: "Enter number of fish to catch, <clear>, <cancel>"
stageEditorMilkCowsPrompt: "Enter number of cows to milk, <clear>, <cancel>"
stageEditorKillPlayerPrompt: "Enter number of players to kill, <clear>, <cancel>"
stageEditorEnchantTypePrompt: "Enter enchantment names, <space>, <cancel>"
stageEditorEnchantAmountsPrompt: "Enter enchant amounts (numbers), <space>, <cancel>"
@ -617,6 +620,7 @@ smelt: "Smelt"
enchantItem: "Enchant <item> with <enchantment>"
brew: "Brew"
catchFish: "Catch Fish"
milkCow: "Milk Cow"
kill: "Kill"
killAtLocation: "Kill <mob> at <location>"
killPlayer: "Kill a Player"