Added quest support for harvesting plants.
This commit is contained in:
parent
4e2aa4258d
commit
241dce0537
|
|
@ -33,6 +33,8 @@ public class QuestsConfig extends AbstractConfig {
|
||||||
public static String MINE_STEP_2 = "Turned in";
|
public static String MINE_STEP_2 = "Turned in";
|
||||||
public static String MINE_TURN_IN = "<gold>Click here to turn in your <block></gold>";
|
public static String MINE_TURN_IN = "<gold>Click here to turn in your <block></gold>";
|
||||||
public static List<String> MINE_COMMANDS = List.of("broadcast <player> Finished their daily quest!");
|
public static List<String> MINE_COMMANDS = List.of("broadcast <player> Finished their daily quest!");
|
||||||
|
public static Material material;
|
||||||
|
public static Material turnInMaterial;
|
||||||
|
|
||||||
private static void loadMineQuests() {
|
private static void loadMineQuests() {
|
||||||
MINE_QUESTS.clear();
|
MINE_QUESTS.clear();
|
||||||
|
|
@ -44,10 +46,18 @@ public class QuestsConfig extends AbstractConfig {
|
||||||
Set<String> keys = configurationSection.getKeys(false);
|
Set<String> keys = configurationSection.getKeys(false);
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
try {
|
try {
|
||||||
Material material = Material.valueOf(configurationSection.getString(key + ".material"));
|
material = Material.valueOf(configurationSection.getString(key + ".material"));
|
||||||
|
if (configurationSection.getString(key + ".turnInMaterial") == null) {
|
||||||
|
turnInMaterial = material;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
turnInMaterial = Material.valueOf(configurationSection.getString(key + ".turnInMaterial"));
|
||||||
|
}
|
||||||
|
|
||||||
MINE_QUESTS.add(new MineQuestObject(key,
|
MINE_QUESTS.add(new MineQuestObject(key,
|
||||||
configurationSection.getString(key + ".name"),
|
configurationSection.getString(key + ".name"),
|
||||||
material,
|
material,
|
||||||
|
turnInMaterial,
|
||||||
configurationSection.getStringList(key + ".quest-pages"),
|
configurationSection.getStringList(key + ".quest-pages"),
|
||||||
configurationSection.getStringList(key + ".done-pages"),
|
configurationSection.getStringList(key + ".done-pages"),
|
||||||
configurationSection.getInt(key + ".amount-min"),
|
configurationSection.getInt(key + ".amount-min"),
|
||||||
|
|
|
||||||
|
|
@ -22,5 +22,4 @@ public class MineBlocks implements Listener {
|
||||||
if (quest instanceof MineQuest mineQuest)
|
if (quest instanceof MineQuest mineQuest)
|
||||||
mineQuest.mine(event.getBlock());
|
mineQuest.mine(event.getBlock());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.block.data.Ageable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
|
@ -91,7 +93,7 @@ public class MineQuest extends Quest {
|
||||||
@Override
|
@Override
|
||||||
public TagResolver getTagResolvers() {
|
public TagResolver getTagResolvers() {
|
||||||
TagResolver resolver = TagResolver.resolver(
|
TagResolver resolver = TagResolver.resolver(
|
||||||
Placeholder.unparsed("block", Utilities.formatName(mineQuestObject.getMaterial().name())),
|
Placeholder.unparsed("block", Utilities.formatName(mineQuestObject.getTurnInMaterial().name())),
|
||||||
Placeholder.parsed("step_1_progress", getStep1() == getAmount() ?
|
Placeholder.parsed("step_1_progress", getStep1() == getAmount() ?
|
||||||
"<green>" + getStep1() + "</green>" : "<red>" + getStep1() + "</red>"),
|
"<green>" + getStep1() + "</green>" : "<red>" + getStep1() + "</red>"),
|
||||||
Placeholder.parsed("step_1_total", String.valueOf(getAmount())),
|
Placeholder.parsed("step_1_total", String.valueOf(getAmount())),
|
||||||
|
|
@ -121,7 +123,7 @@ public class MineQuest extends Quest {
|
||||||
|
|
||||||
Arrays.stream(inventory.getContents())
|
Arrays.stream(inventory.getContents())
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.filter(itemStack -> itemStack.getType().equals(mineQuestObject.getMaterial()))
|
.filter(itemStack -> itemStack.getType().equals(mineQuestObject.getTurnInMaterial()))
|
||||||
.forEach(itemStack -> {
|
.forEach(itemStack -> {
|
||||||
if (ref.tmpAmount == 0)
|
if (ref.tmpAmount == 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -149,8 +151,23 @@ 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
|
||||||
|
|
||||||
|
BlockData blockData = block.getBlockData();
|
||||||
|
|
||||||
|
if (!block.getType().equals(mineQuestObject.getMaterial())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (blockData instanceof Ageable) {
|
||||||
|
Ageable ageable = (Ageable) blockData;
|
||||||
|
if (ageable.getAge() != ageable.getMaximumAge()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
public void mine(Block block) {
|
public void mine(Block block) {
|
||||||
if (isDone() || !block.getType().equals(mineQuestObject.getMaterial()) || getAmount() == getStep1())
|
if (isDone() || checkBlock(block) || getAmount() == getStep1())
|
||||||
return;
|
return;
|
||||||
addStep1(1);
|
addStep1(1);
|
||||||
checkDone();
|
checkDone();
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,19 @@ import java.util.List;
|
||||||
public class MineQuestObject extends Variant {
|
public class MineQuestObject extends Variant {
|
||||||
|
|
||||||
private final Material material;
|
private final Material material;
|
||||||
|
private final Material turnInMaterial;
|
||||||
|
|
||||||
public MineQuestObject(String internalName, String name, Material material,
|
public MineQuestObject(String internalName, String name, Material material, Material turnInMaterial,
|
||||||
List<String> questPages, List<String> donePages, int min, int max) {
|
List<String> questPages, List<String> donePages, int min, int max) {
|
||||||
super(internalName, name, questPages, donePages, min, max);
|
super(internalName, name, questPages, donePages, min, max);
|
||||||
this.material = material;
|
this.material = material;
|
||||||
|
this.turnInMaterial = turnInMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getMaterial() {
|
public Material getMaterial() {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
public Material getTurnInMaterial() {
|
||||||
|
return turnInMaterial;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user