Added support for other quests.
Support for other quests of the fishing type was added.
This commit is contained in:
parent
241dce0537
commit
5929582e71
Binary file not shown.
|
|
@ -69,6 +69,7 @@ public final class AQuest extends JavaPlugin {
|
||||||
getServer().getPluginManager().registerEvents(new EntityBreed(), this);
|
getServer().getPluginManager().registerEvents(new EntityBreed(), this);
|
||||||
getServer().getPluginManager().registerEvents(new DonNotMessWithNPC(), this);
|
getServer().getPluginManager().registerEvents(new DonNotMessWithNPC(), this);
|
||||||
getServer().getPluginManager().registerEvents(new DataLock(), this);
|
getServer().getPluginManager().registerEvents(new DataLock(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new ItemCaught(), this);
|
||||||
// getServer().getMessenger().registerOutgoingPluginChannel(this, "aquest:player-data");
|
// getServer().getMessenger().registerOutgoingPluginChannel(this, "aquest:player-data");
|
||||||
// getServer().getMessenger().registerIncomingPluginChannel(this, "aquest:player-data", new PluginMessageListener());
|
// getServer().getMessenger().registerIncomingPluginChannel(this, "aquest:player-data", new PluginMessageListener());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,12 @@ public final class Config extends AbstractConfig {
|
||||||
public static int KILL_QUEST_FREQ = 1;
|
public static int KILL_QUEST_FREQ = 1;
|
||||||
public static int COLLECT_QUEST_FREQ = 1;
|
public static int COLLECT_QUEST_FREQ = 1;
|
||||||
public static int BREED_QUEST_FREQ = 1;
|
public static int BREED_QUEST_FREQ = 1;
|
||||||
|
public static int OTHER_QUEST_FRQ = 1;
|
||||||
private static void loadQuestTypeFrequency() {
|
private static void loadQuestTypeFrequency() {
|
||||||
MINE_QUEST_FREQ = config.getInt("quest-type-frequency.mine", MINE_QUEST_FREQ);
|
MINE_QUEST_FREQ = config.getInt("quest-type-frequency.mine", MINE_QUEST_FREQ);
|
||||||
KILL_QUEST_FREQ = config.getInt("quest-type-frequency.kill", KILL_QUEST_FREQ);
|
KILL_QUEST_FREQ = config.getInt("quest-type-frequency.kill", KILL_QUEST_FREQ);
|
||||||
COLLECT_QUEST_FREQ = config.getInt("quest-type-frequency.collect", COLLECT_QUEST_FREQ);
|
COLLECT_QUEST_FREQ = config.getInt("quest-type-frequency.collect", COLLECT_QUEST_FREQ);
|
||||||
BREED_QUEST_FREQ = config.getInt("quest-type-frequency.breed", BREED_QUEST_FREQ);
|
BREED_QUEST_FREQ = config.getInt("quest-type-frequency.breed", BREED_QUEST_FREQ);
|
||||||
|
OTHER_QUEST_FRQ = config.getInt("quest-type-frequency.other", OTHER_QUEST_FRQ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.alttd.altitudequests.objects.variants.BreedMobsQuestObject;
|
||||||
import com.alttd.altitudequests.objects.variants.CollectDropsQuestObject;
|
import com.alttd.altitudequests.objects.variants.CollectDropsQuestObject;
|
||||||
import com.alttd.altitudequests.objects.variants.KillMobsQuestObject;
|
import com.alttd.altitudequests.objects.variants.KillMobsQuestObject;
|
||||||
import com.alttd.altitudequests.objects.variants.MineQuestObject;
|
import com.alttd.altitudequests.objects.variants.MineQuestObject;
|
||||||
|
import com.alttd.altitudequests.objects.variants.OtherQuestObject;
|
||||||
import com.alttd.altitudequests.util.Logger;
|
import com.alttd.altitudequests.util.Logger;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
@ -154,6 +155,48 @@ public class QuestsConfig extends AbstractConfig {
|
||||||
COLLECT_DROPS_COMMANDS = config.getStringList("collect_drops.commands", COLLECT_DROPS_COMMANDS);
|
COLLECT_DROPS_COMMANDS = config.getStringList("collect_drops.commands", COLLECT_DROPS_COMMANDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<OtherQuestObject> OTHER_QUEST = new ArrayList<>();
|
||||||
|
public static String OTHER_QUEST_NAME = "<green>Other quest</green>";
|
||||||
|
public static String OTHER_STEP_1 = "Obtained";
|
||||||
|
public static String OTHER_STEP_2 = "Turned in";
|
||||||
|
public static String OTHER_TURN_IN = "<gold>Click here to turn in your <item></gold>";
|
||||||
|
public static List<String> OTHER_COMMANDS = List.of("broadcast <player> Finished their daily quest!");
|
||||||
|
|
||||||
|
private static void loadOtherQuests() {
|
||||||
|
OTHER_QUEST.clear();
|
||||||
|
ConfigurationSection configurationSection = config.getConfigurationSection("other.possible_tasks");
|
||||||
|
if (configurationSection == null) {
|
||||||
|
Logger.warning("No other quests in config");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Set<String> keys = configurationSection.getKeys(false);
|
||||||
|
for (String key : keys) {
|
||||||
|
try {
|
||||||
|
Material item = Material.valueOf(configurationSection.getString(key + ".item"));
|
||||||
|
OTHER_QUEST.add(new OtherQuestObject(key,
|
||||||
|
configurationSection.getString(key + ".name"),
|
||||||
|
configurationSection.getString(key + ".category"),
|
||||||
|
item,
|
||||||
|
configurationSection.getStringList(key + ".quest-pages"),
|
||||||
|
configurationSection.getStringList(key + ".done-pages"),
|
||||||
|
configurationSection.getInt(key + ".amount-min"),
|
||||||
|
configurationSection.getInt(key + ".amount-max"),
|
||||||
|
configurationSection.getString(key + ".step-1"),
|
||||||
|
configurationSection.getString(key + ".step-2")));
|
||||||
|
if (Config.DEBUG)
|
||||||
|
Logger.info("Loaded Collect drops quest " + key);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OTHER_QUEST_NAME = config.getString("other.name", OTHER_QUEST_NAME);
|
||||||
|
OTHER_STEP_1 = config.getString("other.step-1", OTHER_STEP_1);
|
||||||
|
OTHER_STEP_2 = config.getString("other.step-2", OTHER_STEP_2);
|
||||||
|
OTHER_TURN_IN = config.getString("other.turn-in", OTHER_TURN_IN);
|
||||||
|
OTHER_COMMANDS = config.getStringList("other.commands", OTHER_COMMANDS);
|
||||||
|
}
|
||||||
|
|
||||||
public static List<BreedMobsQuestObject> BREED_MOB_QUEST = new ArrayList<>();
|
public static List<BreedMobsQuestObject> BREED_MOB_QUEST = new ArrayList<>();
|
||||||
public static String BREED_MOB_QUEST_NAME = "<green>Breed mobs quest</green>";
|
public static String BREED_MOB_QUEST_NAME = "<green>Breed mobs quest</green>";
|
||||||
public static String BREED_STEP_1 = "Bred";
|
public static String BREED_STEP_1 = "Bred";
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,7 @@ import com.alttd.altitudequests.AQuest;
|
||||||
import com.alttd.altitudequests.config.Config;
|
import com.alttd.altitudequests.config.Config;
|
||||||
import com.alttd.altitudequests.config.MessagesConfig;
|
import com.alttd.altitudequests.config.MessagesConfig;
|
||||||
import com.alttd.altitudequests.database.Database;
|
import com.alttd.altitudequests.database.Database;
|
||||||
import com.alttd.altitudequests.objects.quests.BreedMobsQuest;
|
import com.alttd.altitudequests.objects.quests.*;
|
||||||
import com.alttd.altitudequests.objects.quests.CollectDropsQuest;
|
|
||||||
import com.alttd.altitudequests.objects.quests.KillMobsQuest;
|
|
||||||
import com.alttd.altitudequests.objects.quests.MineQuest;
|
|
||||||
import com.alttd.altitudequests.util.Logger;
|
import com.alttd.altitudequests.util.Logger;
|
||||||
import com.alttd.altitudequests.util.Utilities;
|
import com.alttd.altitudequests.util.Utilities;
|
||||||
import com.alttd.datalock.DataLockAPI;
|
import com.alttd.datalock.DataLockAPI;
|
||||||
|
|
@ -41,6 +38,8 @@ public abstract class Quest {
|
||||||
possibleQuests.add(CollectDropsQuest.class);
|
possibleQuests.add(CollectDropsQuest.class);
|
||||||
for (int i = 0; i < Config.BREED_QUEST_FREQ; i++)
|
for (int i = 0; i < Config.BREED_QUEST_FREQ; i++)
|
||||||
possibleQuests.add(BreedMobsQuest.class);
|
possibleQuests.add(BreedMobsQuest.class);
|
||||||
|
for (int i = 0; i < Config.OTHER_QUEST_FRQ; i++)
|
||||||
|
possibleQuests.add(OtherQuest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ public class MineQuest extends Quest {
|
||||||
return QuestsConfig.MINE_COMMANDS;
|
return QuestsConfig.MINE_COMMANDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkBlock(Block block) { //this can probably be simplified but I didn't realy know how
|
public boolean checkBlock(Block block) {
|
||||||
|
|
||||||
BlockData blockData = block.getBlockData();
|
BlockData blockData = block.getBlockData();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,179 @@
|
||||||
|
package com.alttd.altitudequests.objects.quests;
|
||||||
|
|
||||||
|
import com.alttd.altitudequests.config.Config;
|
||||||
|
import com.alttd.altitudequests.config.QuestsConfig;
|
||||||
|
import com.alttd.altitudequests.database.Database;
|
||||||
|
import com.alttd.altitudequests.objects.Quest;
|
||||||
|
import com.alttd.altitudequests.objects.Variant;
|
||||||
|
import com.alttd.altitudequests.objects.variants.OtherQuestObject;
|
||||||
|
import com.alttd.altitudequests.util.Logger;
|
||||||
|
import com.alttd.altitudequests.util.Utilities;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class OtherQuest extends Quest {
|
||||||
|
|
||||||
|
private final OtherQuestObject otherQuestObject;
|
||||||
|
|
||||||
|
public OtherQuest(UUID uuid) {
|
||||||
|
super(uuid, 0, 0,
|
||||||
|
QuestsConfig.OTHER_QUEST.get(Utilities.randomOr0(QuestsConfig.OTHER_QUEST.size() - 1)), -1, false);
|
||||||
|
if (getVariant() instanceof OtherQuestObject otherQuestObject)
|
||||||
|
this.otherQuestObject = otherQuestObject;
|
||||||
|
else
|
||||||
|
this.otherQuestObject = null;
|
||||||
|
if (otherQuestObject == null) {
|
||||||
|
Logger.warning("Tried to create OtherQuest but unable to find variant: %.", "unknown");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public OtherQuest(UUID uuid, int step1, int step2, String variant, int amount, boolean rewardReceived) {
|
||||||
|
super(uuid, step1, step2, QuestsConfig.OTHER_QUEST.stream()
|
||||||
|
.filter(object -> variant.equals(object.getInternalName()))
|
||||||
|
.findAny().orElse(null), amount, rewardReceived);
|
||||||
|
if (getVariant() instanceof OtherQuestObject otherQuestObject)
|
||||||
|
this.otherQuestObject = otherQuestObject;
|
||||||
|
else
|
||||||
|
this.otherQuestObject = null;
|
||||||
|
if (otherQuestObject == null) {
|
||||||
|
Logger.warning("Tried to create OtherQuest but unable to find variant: %.", variant);
|
||||||
|
Logger.warning("Possible variants: %", QuestsConfig.OTHER_QUEST.stream().map(Variant::getInternalName).collect(Collectors.joining(", ")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
checkDone();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
String sql = "INSERT INTO generic_quest_progress " +
|
||||||
|
"(year_day, uuid, quest, quest_variant, step_1_progress, step_2_progress, amount, reward_received) " +
|
||||||
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?) " +
|
||||||
|
"ON DUPLICATE KEY UPDATE " +
|
||||||
|
"quest = ?, quest_variant = ?, step_1_progress = ?, step_2_progress = ?, year_day = ?, amount = ?, reward_received = ?";
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||||
|
int yearDay = Utilities.getYearDay();
|
||||||
|
if (Config.DEBUG)
|
||||||
|
Logger.info("Saving user for year day %.", String.valueOf(yearDay));
|
||||||
|
statement.setInt(1, yearDay);
|
||||||
|
statement.setString(2, getUuid().toString());
|
||||||
|
statement.setString(3, this.getClass().getSimpleName());
|
||||||
|
statement.setString(4, otherQuestObject.getInternalName());
|
||||||
|
statement.setInt(5, getStep1());
|
||||||
|
statement.setInt(6, getStep2());
|
||||||
|
statement.setInt(7, getAmount());
|
||||||
|
statement.setInt(8, isRewardReceived() ? 1 : 0);
|
||||||
|
statement.setString(9, this.getClass().getSimpleName());
|
||||||
|
statement.setString(10, otherQuestObject.getInternalName());
|
||||||
|
statement.setInt(11, getStep1());
|
||||||
|
statement.setInt(12, getStep2());
|
||||||
|
statement.setInt(13, yearDay);
|
||||||
|
statement.setInt(14, getAmount());
|
||||||
|
statement.setInt(15, isRewardReceived() ? 1 : 0);
|
||||||
|
statement.execute();
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TagResolver getTagResolvers() {
|
||||||
|
TagResolver resolver = TagResolver.resolver(
|
||||||
|
Placeholder.unparsed("item", Utilities.formatName(otherQuestObject.getMaterial().name())),
|
||||||
|
Placeholder.parsed("step_1_progress", getStep1() == getAmount() ?
|
||||||
|
"<green>" + getStep1() + "</green>" : "<red>" + getStep1() + "</red>"),
|
||||||
|
Placeholder.parsed("step_1_total", String.valueOf(getAmount())),
|
||||||
|
Placeholder.parsed("step_2_progress", getStep2() == getAmount() ?
|
||||||
|
"<green>" + getStep2() + "</green>" : "<red>" + getStep2() + "</red>"),
|
||||||
|
Placeholder.parsed("step_2_total", String.valueOf(getAmount())),
|
||||||
|
Placeholder.unparsed("step_1", OtherQuestObject.getStep1()),
|
||||||
|
Placeholder.unparsed("step_2", OtherQuestObject.getStep2()),
|
||||||
|
Placeholder.unparsed("turn_in_text", QuestsConfig.OTHER_TURN_IN)
|
||||||
|
);
|
||||||
|
Component turnInText = MiniMessage.miniMessage().deserialize(QuestsConfig.OTHER_TURN_IN, resolver);
|
||||||
|
return TagResolver.resolver(
|
||||||
|
resolver,
|
||||||
|
Placeholder.component("turn_in_text", turnInText)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int turnIn(Player player) {
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
int maxToTurnIn = getMaxToTurnIn();
|
||||||
|
|
||||||
|
if (maxToTurnIn == 0)
|
||||||
|
return 0;
|
||||||
|
var ref = new Object() {
|
||||||
|
int tmpAmount = maxToTurnIn;
|
||||||
|
};
|
||||||
|
|
||||||
|
Arrays.stream(inventory.getContents())
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(itemStack -> itemStack.getType().equals(otherQuestObject.getMaterial()))
|
||||||
|
.forEach(itemStack -> {
|
||||||
|
if (ref.tmpAmount == 0)
|
||||||
|
return;
|
||||||
|
if (itemStack.getAmount() > ref.tmpAmount) {
|
||||||
|
itemStack.setAmount(itemStack.getAmount() - ref.tmpAmount);
|
||||||
|
ref.tmpAmount = 0;
|
||||||
|
} else {
|
||||||
|
ref.tmpAmount -= itemStack.getAmount();
|
||||||
|
itemStack.setAmount(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
int totalTurnedIn = maxToTurnIn - ref.tmpAmount;
|
||||||
|
addStep2(totalTurnedIn);
|
||||||
|
checkDone(player);
|
||||||
|
return totalTurnedIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getDisplayName() {
|
||||||
|
return MiniMessage.miniMessage().deserialize(QuestsConfig.OTHER_QUEST_NAME+"<green>: </green>"+OtherQuestObject.getCategory());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getRewardCommand() {
|
||||||
|
return QuestsConfig.COLLECT_DROPS_COMMANDS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fish(ItemStack caughtItem){
|
||||||
|
if (isDone() || !caughtItem.getType().equals(otherQuestObject.getMaterial()) ||getAmount() == getStep1())
|
||||||
|
return;
|
||||||
|
addStep1(1);
|
||||||
|
checkDone();
|
||||||
|
}
|
||||||
|
public void raid(){}
|
||||||
|
public void collectDrops(List<ItemStack> drops) {
|
||||||
|
if (isDone() || getAmount() == getStep1())
|
||||||
|
return;
|
||||||
|
int total = drops.stream()
|
||||||
|
.filter(itemStack -> itemStack.getType().equals(otherQuestObject.getMaterial()))
|
||||||
|
.mapToInt(ItemStack::getAmount)
|
||||||
|
.sum();
|
||||||
|
if (total == 0)
|
||||||
|
return;
|
||||||
|
addStep1(Math.min(total, getAmount() - getStep1()));
|
||||||
|
checkDone();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getSubTypes() {
|
||||||
|
return QuestsConfig.OTHER_QUEST.stream().map(Variant::getInternalName).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.alttd.altitudequests.objects.variants;
|
||||||
|
|
||||||
|
import com.alttd.altitudequests.objects.Variant;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class OtherQuestObject extends Variant {
|
||||||
|
|
||||||
|
private final Material material;
|
||||||
|
private static String step1 = null;
|
||||||
|
private static String step2 = null;
|
||||||
|
private static String category = null;
|
||||||
|
|
||||||
|
public OtherQuestObject(String internalName, String name, String category, Material item,
|
||||||
|
List<String> questPages, List<String> donePages, int min, int max, String step1, String step2) {
|
||||||
|
super(internalName, name, questPages, donePages, min, max);
|
||||||
|
this.material = item;
|
||||||
|
this.step1 = step1;
|
||||||
|
this.step2 = step2;
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getMaterial() {
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
public static String getStep1() {return step1;}
|
||||||
|
public static String getStep2() {return step2;}
|
||||||
|
public static String getCategory() {return category;}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user