Added the ability to put a range in for quest types
This commit is contained in:
parent
c3fa337d2a
commit
cdff96fb4d
|
|
@ -48,9 +48,10 @@ public class QuestsConfig extends AbstractConfig {
|
|||
MINE_QUESTS.add(new MineQuestObject(key,
|
||||
configurationSection.getString(key + ".name"),
|
||||
material,
|
||||
configurationSection.getInt(key + ".amount"),
|
||||
configurationSection.getStringList(key + ".quest-pages"),
|
||||
configurationSection.getStringList(key + ".done-pages")));
|
||||
configurationSection.getStringList(key + ".done-pages"),
|
||||
configurationSection.getInt(key + ".amount-min"),
|
||||
configurationSection.getInt(key + ".amount-max")));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -84,9 +85,10 @@ public class QuestsConfig extends AbstractConfig {
|
|||
KILL_MOB_QUEST.add(new KillMobsQuestObject(key,
|
||||
configurationSection.getString(key + ".name"),
|
||||
entityType,
|
||||
configurationSection.getInt(key + ".amount"),
|
||||
configurationSection.getStringList(key + ".quest-pages"),
|
||||
configurationSection.getStringList(key + ".done-pages")));
|
||||
configurationSection.getStringList(key + ".done-pages"),
|
||||
configurationSection.getInt(key + ".amount-min"),
|
||||
configurationSection.getInt(key + ".amount-max")));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -120,9 +122,10 @@ public class QuestsConfig extends AbstractConfig {
|
|||
COLLECT_DROPS_QUEST.add(new CollectDropsQuestObject(key,
|
||||
configurationSection.getString(key + ".name"),
|
||||
item,
|
||||
configurationSection.getInt(key + ".amount"),
|
||||
configurationSection.getStringList(key + ".quest-pages"),
|
||||
configurationSection.getStringList(key + ".done-pages")));
|
||||
configurationSection.getStringList(key + ".done-pages"),
|
||||
configurationSection.getInt(key + ".amount-min"),
|
||||
configurationSection.getInt(key + ".amount-max")));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -156,9 +159,10 @@ public class QuestsConfig extends AbstractConfig {
|
|||
BREED_MOB_QUEST.add(new BreedMobsQuestObject(key,
|
||||
configurationSection.getString(key + ".name"),
|
||||
entityType,
|
||||
configurationSection.getInt(key + ".amount"),
|
||||
configurationSection.getStringList(key + ".quest-pages"),
|
||||
configurationSection.getStringList(key + ".done-pages")));
|
||||
configurationSection.getStringList(key + ".done-pages"),
|
||||
configurationSection.getInt(key + ".amount-min"),
|
||||
configurationSection.getInt(key + ".amount-max")));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.alttd.altitudequests.objects;
|
|||
import com.alttd.altitudequests.AQuest;
|
||||
import com.alttd.altitudequests.config.Config;
|
||||
import com.alttd.altitudequests.config.MessagesConfig;
|
||||
import com.alttd.altitudequests.database.Database;
|
||||
import com.alttd.altitudequests.objects.quests.BreedMobsQuest;
|
||||
import com.alttd.altitudequests.objects.quests.CollectDropsQuest;
|
||||
import com.alttd.altitudequests.objects.quests.KillMobsQuest;
|
||||
|
|
@ -20,6 +21,9 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -42,6 +46,7 @@ public abstract class Quest {
|
|||
private final Variant variant;
|
||||
private boolean isDone;
|
||||
private boolean rewardReceived;
|
||||
private final int amount;
|
||||
|
||||
public Quest(UUID uuid, int step1, int step2, Variant variant, boolean rewardReceived) {
|
||||
this.uuid = uuid;
|
||||
|
|
@ -50,6 +55,28 @@ public abstract class Quest {
|
|||
this.variant = variant;
|
||||
this.isDone = rewardReceived;
|
||||
this.rewardReceived = rewardReceived;
|
||||
if (variant == null)
|
||||
amount = 0;
|
||||
else
|
||||
amount = variant.calculateAmount(loadQuestsDoneThisMonth(uuid));
|
||||
}
|
||||
|
||||
private int loadQuestsDoneThisMonth(UUID uuid) {
|
||||
String sql = "SELECT COUNT(uuid) AS total FROM quest_log WHERE uuid = ? AND year = ? AND month = ?";
|
||||
try {
|
||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||
statement.setString(1, uuid.toString());
|
||||
Calendar instance = Calendar.getInstance();
|
||||
instance.setTime(new Date());
|
||||
statement.setInt(2, instance.get(Calendar.YEAR));
|
||||
statement.setInt(3, instance.get(Calendar.MONTH));
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next())
|
||||
return resultSet.getInt("total");
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void createDailyQuest(Player player) {
|
||||
|
|
@ -173,7 +200,7 @@ public abstract class Quest {
|
|||
protected void checkDone() {
|
||||
if (isDone())
|
||||
return;
|
||||
if (getStep1() == variant.getAmount() && getStep2() == variant.getAmount()) {
|
||||
if (getStep1() == getAmount() && getStep2() == getAmount()) {
|
||||
setDone(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -182,6 +209,7 @@ public abstract class Quest {
|
|||
checkDone();
|
||||
if (!isDone)
|
||||
return;
|
||||
//TODO add completed quest to database
|
||||
QuestCompleteEvent event = new QuestCompleteEvent(player, this, true);
|
||||
event.callEvent();
|
||||
}
|
||||
|
|
@ -227,6 +255,10 @@ public abstract class Quest {
|
|||
}
|
||||
|
||||
public int getMaxToTurnIn() {
|
||||
return Math.min(variant.getAmount() - getStep2(), getStep1() - getStep2());
|
||||
return Math.min(getAmount() - getStep2(), getStep1() - getStep2());
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,19 +4,22 @@ import net.kyori.adventure.text.Component;
|
|||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class Variant {
|
||||
|
||||
private final String internalName;
|
||||
private final Component name;
|
||||
private final int amount;
|
||||
private final int rangeMin;
|
||||
private final int rangeMax;
|
||||
private final List<String> questPages;
|
||||
private final List<String> donePages;
|
||||
|
||||
public Variant(String internalName, String name, int amount, List<String> questPages, List<String> donePages) {
|
||||
public Variant(String internalName, String name, List<String> questPages, List<String> donePages, int rangeMin, int rangeMax) {
|
||||
this.internalName = internalName;
|
||||
this.name = MiniMessage.miniMessage().deserialize(name);
|
||||
this.amount = amount;
|
||||
this.rangeMin = rangeMin;
|
||||
this.rangeMax = rangeMax;
|
||||
this.questPages = questPages;
|
||||
this.donePages = donePages;
|
||||
}
|
||||
|
|
@ -29,10 +32,6 @@ public abstract class Variant {
|
|||
return name;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public List<String> getQuestPages() {
|
||||
return questPages;
|
||||
}
|
||||
|
|
@ -40,4 +39,9 @@ public abstract class Variant {
|
|||
public List<String> getDonePages() {
|
||||
return donePages;
|
||||
}
|
||||
|
||||
public int calculateAmount(int questsCompleted) {
|
||||
int difficultyOffset = ((rangeMax - rangeMin) / 40) * questsCompleted;
|
||||
return new Random().nextInt(Integer.min(rangeMax - 1, rangeMin + difficultyOffset), rangeMax);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,12 +86,12 @@ public class BreedMobsQuest extends Quest {
|
|||
public TagResolver getTagResolvers() {
|
||||
TagResolver resolver = TagResolver.resolver(
|
||||
Placeholder.unparsed("mob", Utilities.formatName(breedMobsQuestObject.getEntityType().name())),
|
||||
Placeholder.parsed("step_1_progress", getStep1() == breedMobsQuestObject.getAmount() ?
|
||||
Placeholder.parsed("step_1_progress", getStep1() == getAmount() ?
|
||||
"<green>" + getStep1() + "</green>" : "<red>" + getStep1() + "</red>"),
|
||||
Placeholder.parsed("step_1_total", String.valueOf(breedMobsQuestObject.getAmount())),
|
||||
Placeholder.parsed("step_2_progress", getStep2() == breedMobsQuestObject.getAmount() ?
|
||||
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(breedMobsQuestObject.getAmount())),
|
||||
Placeholder.parsed("step_2_total", String.valueOf(getAmount())),
|
||||
Placeholder.unparsed("step_1", QuestsConfig.BREED_STEP_1),
|
||||
Placeholder.unparsed("step_2", QuestsConfig.BREED_STEP_2)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -89,12 +89,12 @@ public class CollectDropsQuest extends Quest {
|
|||
public TagResolver getTagResolvers() {
|
||||
TagResolver resolver = TagResolver.resolver(
|
||||
Placeholder.unparsed("item", Utilities.formatName(collectDropsQuestObject.getMaterial().name())),
|
||||
Placeholder.parsed("step_1_progress", getStep1() == collectDropsQuestObject.getAmount() ?
|
||||
Placeholder.parsed("step_1_progress", getStep1() == getAmount() ?
|
||||
"<green>" + getStep1() + "</green>" : "<red>" + getStep1() + "</red>"),
|
||||
Placeholder.parsed("step_1_total", String.valueOf(collectDropsQuestObject.getAmount())),
|
||||
Placeholder.parsed("step_2_progress", getStep2() == collectDropsQuestObject.getAmount() ?
|
||||
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(collectDropsQuestObject.getAmount())),
|
||||
Placeholder.parsed("step_2_total", String.valueOf(getAmount())),
|
||||
Placeholder.unparsed("step_1", QuestsConfig.COLLECT_DROPS_STEP_1),
|
||||
Placeholder.unparsed("step_2", QuestsConfig.COLLECT_DROPS_STEP_2),
|
||||
Placeholder.unparsed("turn_in_text", QuestsConfig.COLLECT_DROPS_TURN_IN)
|
||||
|
|
@ -123,11 +123,11 @@ public class CollectDropsQuest extends Quest {
|
|||
.forEach(itemStack -> {
|
||||
if (ref.tmpAmount == 0)
|
||||
return;
|
||||
if (itemStack.getAmount() > ref.tmpAmount) {
|
||||
itemStack.setAmount(itemStack.getAmount() - ref.tmpAmount);
|
||||
if (getAmount() > ref.tmpAmount) {
|
||||
itemStack.setAmount(getAmount() - ref.tmpAmount);
|
||||
ref.tmpAmount = 0;
|
||||
} else {
|
||||
ref.tmpAmount -= itemStack.getAmount();
|
||||
ref.tmpAmount -= getAmount();
|
||||
itemStack.setAmount(0);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -86,12 +86,12 @@ public class KillMobsQuest extends Quest {
|
|||
public TagResolver getTagResolvers() {
|
||||
TagResolver resolver = TagResolver.resolver(
|
||||
Placeholder.unparsed("mob", Utilities.formatName(killMobsQuestObject.getEntityType().name())),
|
||||
Placeholder.parsed("step_1_progress", getStep1() == killMobsQuestObject.getAmount() ?
|
||||
Placeholder.parsed("step_1_progress", getStep1() == getAmount() ?
|
||||
"<green>" + getStep1() + "</green>" : "<red>" + getStep1() + "</red>"),
|
||||
Placeholder.parsed("step_1_total", String.valueOf(killMobsQuestObject.getAmount())),
|
||||
Placeholder.parsed("step_2_progress", getStep2() == killMobsQuestObject.getAmount() ?
|
||||
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(killMobsQuestObject.getAmount())),
|
||||
Placeholder.parsed("step_2_total", String.valueOf(getAmount())),
|
||||
Placeholder.unparsed("step_1", QuestsConfig.KILL_MOB_STEP_1),
|
||||
Placeholder.unparsed("step_2", QuestsConfig.KILL_MOB_STEP_2)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -87,12 +87,12 @@ public class MineQuest extends Quest {
|
|||
public TagResolver getTagResolvers() {
|
||||
TagResolver resolver = TagResolver.resolver(
|
||||
Placeholder.unparsed("block", Utilities.formatName(mineQuestObject.getMaterial().name())),
|
||||
Placeholder.parsed("step_1_progress", getStep1() == mineQuestObject.getAmount() ?
|
||||
Placeholder.parsed("step_1_progress", getStep1() == getAmount() ?
|
||||
"<green>" + getStep1() + "</green>" : "<red>" + getStep1() + "</red>"),
|
||||
Placeholder.parsed("step_1_total", String.valueOf(mineQuestObject.getAmount())),
|
||||
Placeholder.parsed("step_2_progress", getStep2() == mineQuestObject.getAmount() ?
|
||||
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(mineQuestObject.getAmount())),
|
||||
Placeholder.parsed("step_2_total", String.valueOf(getAmount())),
|
||||
Placeholder.unparsed("step_1", QuestsConfig.MINE_STEP_1),
|
||||
Placeholder.unparsed("step_2", QuestsConfig.MINE_STEP_2)
|
||||
);
|
||||
|
|
@ -120,11 +120,11 @@ public class MineQuest extends Quest {
|
|||
.forEach(itemStack -> {
|
||||
if (ref.tmpAmount == 0)
|
||||
return;
|
||||
if (itemStack.getAmount() > ref.tmpAmount) {
|
||||
itemStack.setAmount(itemStack.getAmount() - ref.tmpAmount);
|
||||
if (getAmount() > ref.tmpAmount) {
|
||||
itemStack.setAmount(getAmount() - ref.tmpAmount);
|
||||
ref.tmpAmount = 0;
|
||||
} else {
|
||||
ref.tmpAmount -= itemStack.getAmount();
|
||||
ref.tmpAmount -= getAmount();
|
||||
itemStack.setAmount(0);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ public class BreedMobsQuestObject extends Variant {
|
|||
|
||||
private final EntityType entityType;
|
||||
|
||||
public BreedMobsQuestObject(String internalName, String name, EntityType entityType, int amount,
|
||||
List<String> questPages, List<String> donePages) {
|
||||
super(internalName, name, amount, questPages, donePages);
|
||||
public BreedMobsQuestObject(String internalName, String name, EntityType entityType,
|
||||
List<String> questPages, List<String> donePages, int min, int max) {
|
||||
super(internalName, name, questPages, donePages, min, max);
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,9 @@ public class CollectDropsQuestObject extends Variant {
|
|||
|
||||
private final Material material;
|
||||
|
||||
public CollectDropsQuestObject(String internalName, String name, Material item, int amount, List<String> questPages, List<String> donePages) {
|
||||
super(internalName, name, amount, questPages, donePages);
|
||||
public CollectDropsQuestObject(String internalName, String name, Material item,
|
||||
List<String> questPages, List<String> donePages, int min, int max) {
|
||||
super(internalName, name, questPages, donePages, min, max);
|
||||
this.material = item;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ public class KillMobsQuestObject extends Variant {
|
|||
|
||||
private final EntityType entityType;
|
||||
|
||||
public KillMobsQuestObject(String internalName, String name, EntityType entityType, int amount,
|
||||
List<String> questPages, List<String> donePages) {
|
||||
super(internalName, name, amount, questPages, donePages);
|
||||
public KillMobsQuestObject(String internalName, String name, EntityType entityType,
|
||||
List<String> questPages, List<String> donePages, int min, int max) {
|
||||
super(internalName, name, questPages, donePages, min, max);
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ public class MineQuestObject extends Variant {
|
|||
|
||||
private final Material material;
|
||||
|
||||
public MineQuestObject(String internalName, String name, Material material, int amount,
|
||||
List<String> questPages, List<String> donePages) {
|
||||
super(internalName, name, amount, questPages, donePages);
|
||||
public MineQuestObject(String internalName, String name, Material material,
|
||||
List<String> questPages, List<String> donePages, int min, int max) {
|
||||
super(internalName, name, questPages, donePages, min, max);
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user