Work on mine quest
This commit is contained in:
parent
1ecf4508e8
commit
66316ff578
|
|
@ -4,7 +4,10 @@ dependencyResolutionManagement {
|
|||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
maven("https://papermc.io/repo/repository/maven-public/") // Paper
|
||||
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
|
||||
maven("https://jitpack.io") { // Vault
|
||||
content { includeGroup("com.github.milkbowl") }
|
||||
}
|
||||
}
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.alttd.altitudequests.commands.SubCommand;
|
|||
import com.alttd.altitudequests.config.Config;
|
||||
import com.alttd.altitudequests.config.LocalConfig;
|
||||
import com.alttd.altitudequests.config.MessagesConfig;
|
||||
import com.alttd.altitudequests.util.Logger;
|
||||
import com.alttd.altitudequests.util.Utilities;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
|
||||
|
|
@ -15,6 +16,7 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
public class CommandCreateScruff extends SubCommand {
|
||||
|
|
@ -31,8 +33,14 @@ public class CommandCreateScruff extends SubCommand {
|
|||
commandSender.sendMiniMessage(getHelpMessage(), null);
|
||||
return true;
|
||||
}
|
||||
Location location = new Location(world, Double.parseDouble(args[2]),Double.parseDouble(args[3]), Double.parseDouble(args[4]),
|
||||
Float.parseFloat(args[5]), Float.parseFloat(args[6]));
|
||||
Location location;
|
||||
try {
|
||||
location = new Location(world, Double.parseDouble(args[2]), Double.parseDouble(args[3]), Double.parseDouble(args[4]),
|
||||
Float.parseFloat(args[5]), Float.parseFloat(args[6]));
|
||||
} catch (NumberFormatException exception) {
|
||||
commandSender.sendMiniMessage("<red>Invalid arguments.</red>", null);
|
||||
return true;
|
||||
}
|
||||
Wolf wolf = (Wolf) world.spawnEntity(location, EntityType.WOLF, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
wolf.setPersistent(true);
|
||||
wolf.setInvulnerable(true);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
package com.alttd.altitudequests.config;;
|
||||
|
||||
import com.alttd.altitudequests.objects.MineQuestObject;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class QuestsConfig extends AbstractConfig {
|
||||
static QuestsConfig config;
|
||||
static int version;
|
||||
|
||||
public QuestsConfig() {
|
||||
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "AltitudeQuests"), "quests.yml");
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
config = new QuestsConfig();
|
||||
|
||||
version = config.getInt("config-version", 1);
|
||||
config.set("config-version", 1);
|
||||
|
||||
config.readConfig(QuestsConfig.class, null);
|
||||
}
|
||||
|
||||
String getString(String path, String def) {
|
||||
yaml.addDefault(path, def);
|
||||
return yaml.getString(path, yaml.getString(path));
|
||||
}
|
||||
|
||||
public static List<MineQuestObject> MINE_QUESTS = new ArrayList<>();
|
||||
private static void loadMineQuests() {
|
||||
MINE_QUESTS.clear();
|
||||
ConfigurationSection configurationSection = config.getConfigurationSection("mining.possible_tasks");
|
||||
Set<String> keys = configurationSection.getKeys(false);
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
for (String key : keys) {
|
||||
Material material = Material.valueOf(configurationSection.getString(key + "material"));
|
||||
|
||||
TemplateResolver resolver = TemplateResolver.resolving(Template.template("block", material.name().toLowerCase()));
|
||||
List<Component> collect = configurationSection.getStringList(key + "pages").stream()
|
||||
.map(page -> miniMessage.deserialize(page, resolver))
|
||||
.collect(Collectors.toList());
|
||||
MINE_QUESTS.add(new MineQuestObject(key,
|
||||
configurationSection.getString(key + "name"),
|
||||
material,
|
||||
configurationSection.getInt(key + "amount"),
|
||||
collect));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package com.alttd.altitudequests.database;
|
||||
|
||||
import com.alttd.altitudequests.objects.GoalType;
|
||||
import com.alttd.altitudequests.util.Logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
|
@ -9,19 +8,17 @@ import java.util.UUID;
|
|||
|
||||
public class Queries {
|
||||
|
||||
public static int setUserProgress(UUID uuid, GoalType goalType, int progress) {
|
||||
String sql = "INSERT VALUES (?, ?, ?) INTO user_seen " +
|
||||
"WHERE uuid = ? AND goal_type = ? " +
|
||||
public static int setUserProgress(UUID uuid, int progress) {
|
||||
String sql = "INSERT VALUES (?, ?) INTO user_seen " +
|
||||
"WHERE uuid = ?" +
|
||||
"ON DUPLICATE KEY UPDATE progress = ?";
|
||||
long time;
|
||||
|
||||
try {
|
||||
PreparedStatement preparedStatement = Database.connection.prepareStatement(sql);
|
||||
preparedStatement.setString(1, uuid.toString());
|
||||
preparedStatement.setString(2, goalType.name());
|
||||
preparedStatement.setInt(3, progress);
|
||||
preparedStatement.setString(4, uuid.toString());
|
||||
preparedStatement.setString(5, goalType.name());
|
||||
preparedStatement.setInt(6, progress);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class MineBlocks implements Listener {
|
|||
if (quest == null || quest.isDone())
|
||||
return;
|
||||
if (quest instanceof MineQuest mineQuest)
|
||||
mineQuest.mine(event.getBlock(), player);
|
||||
mineQuest.mine(event.getBlock());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,54 @@
|
|||
package com.alttd.altitudequests.events;
|
||||
|
||||
import com.alttd.altitudequests.AQuests;
|
||||
import com.alttd.altitudequests.config.Config;
|
||||
import com.alttd.altitudequests.config.LocalConfig;
|
||||
import net.kyori.adventure.inventory.Book;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TalkToQuest implements Listener {
|
||||
|
||||
private static final Book book;
|
||||
static {
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
book = Book.builder()
|
||||
.author(miniMessage.deserialize(Config.QUEST_BOOK_AUTHOR))
|
||||
.title(miniMessage.deserialize(Config.QUEST_BOOK_TITLE))
|
||||
.pages(Config.QUEST_PAGES.stream()
|
||||
.map(miniMessage::deserialize)
|
||||
.collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityInteract(PlayerInteractEntityEvent event) {
|
||||
if (LocalConfig.activeNPC == null || !LocalConfig.activeNPC.equals(event.getRightClicked().getUniqueId()))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().openBook(book);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
event.getPlayer().openBook(getBook(event));
|
||||
}
|
||||
}.runTaskTimerAsynchronously(AQuests.getInstance(), 0, 0);
|
||||
//TODO make it so there can be one book config per quest
|
||||
//TODO make it so everything can be done with commands and just don't let them tab complete and do them through the book instead
|
||||
//TODO in config allow a multitude of events to be prepared and randomly select from them at certain times of day?
|
||||
}
|
||||
|
||||
private Book getBook (PlayerInteractEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
return Book.builder()
|
||||
.author(miniMessage.deserialize(Config.QUEST_BOOK_AUTHOR))
|
||||
.title(miniMessage.deserialize(Config.QUEST_BOOK_TITLE))
|
||||
.pages(getPages(player).stream()
|
||||
.map(page -> miniMessage.deserialize(page, TemplateResolver.templates(Template.template("player", player.getName()))))
|
||||
.collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
|
||||
private List<String> getPages(Player player) {
|
||||
return (Config.QUEST_PAGES);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package com.alttd.altitudequests.objects;
|
||||
|
||||
public enum GoalType {
|
||||
TALK,
|
||||
MONEY,
|
||||
MINE,
|
||||
WALK
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.alttd.altitudequests.objects;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MineQuestObject {
|
||||
|
||||
String internalName;
|
||||
String name;
|
||||
Material material;
|
||||
int amount;
|
||||
List<Component> pages;
|
||||
|
||||
public MineQuestObject(String internalName, String name, Material material, int amount, List<Component> pages) {
|
||||
this.internalName = internalName;
|
||||
this.name = name;
|
||||
this.material = material;
|
||||
this.amount = amount;
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
public String getInternalName() {
|
||||
return internalName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public List<Component> getPages() {
|
||||
return pages;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +1,52 @@
|
|||
package com.alttd.altitudequests.objects;
|
||||
|
||||
import com.alttd.altitudequests.config.QuestsConfig;
|
||||
import com.alttd.altitudequests.objects.quests.MineQuest;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class Quest {
|
||||
|
||||
private static Quest dailyQuest = null;
|
||||
private static final HashMap<UUID, Quest> dailyQuests = new HashMap<>();
|
||||
private static Quest weeklyQuest = null;
|
||||
private static final String[] possibleQuests;
|
||||
|
||||
private String name;
|
||||
private GoalType goalType;
|
||||
//TODO add all data every quest needs
|
||||
|
||||
static {
|
||||
possibleQuests = new String[]{"MineQuest"};
|
||||
}
|
||||
|
||||
public Quest(String name, GoalType goalType) {
|
||||
this.name = name;
|
||||
this.goalType = goalType;
|
||||
public Quest() {
|
||||
}
|
||||
|
||||
public static void createDailyQuest(Player player) {
|
||||
Random random = new Random();
|
||||
String questName = possibleQuests[random.nextInt(0, possibleQuests.length - 1)];
|
||||
Quest quest = null;
|
||||
switch (questName) {
|
||||
case "MineQuest" -> {
|
||||
quest = new MineQuest(QuestsConfig.MINE_QUESTS.get(random.nextInt(0, QuestsConfig.MINE_QUESTS.size() - 1)));
|
||||
}
|
||||
}
|
||||
if (quest == null)
|
||||
return; //TODO error
|
||||
dailyQuests.put(player.getUniqueId(), quest);
|
||||
}
|
||||
|
||||
public static Quest getDailyQuest(UUID uuid) {
|
||||
if (!dailyQuests.containsKey(uuid))
|
||||
dailyQuests.put(uuid, dailyQuest.initQuest());
|
||||
if (!dailyQuests.containsKey(uuid)) {
|
||||
return null;
|
||||
}
|
||||
return dailyQuests.get(uuid);
|
||||
}
|
||||
|
||||
public static void setActiveDailyQuest(Quest newQuest) {
|
||||
Quest.dailyQuest = newQuest;
|
||||
}
|
||||
public static void setActiveWeeklyQuest(Quest newQuest) {
|
||||
Quest.weeklyQuest = newQuest;
|
||||
}
|
||||
|
||||
public abstract boolean isDone();
|
||||
|
||||
public abstract Quest initQuest();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,44 @@
|
|||
package com.alttd.altitudequests.objects.quests;
|
||||
|
||||
import com.alttd.altitudequests.objects.GoalType;
|
||||
import com.alttd.altitudequests.config.QuestsConfig;
|
||||
import com.alttd.altitudequests.objects.MineQuestObject;
|
||||
import com.alttd.altitudequests.objects.Quest;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MineQuest extends Quest {
|
||||
|
||||
public MineQuest(String name, GoalType goalType) {
|
||||
super(name, goalType);
|
||||
int mined;
|
||||
int turnedIn;
|
||||
MineQuestObject mineQuestObject;
|
||||
boolean isDone = false;
|
||||
|
||||
public MineQuest(MineQuestObject mineQuestObject) {
|
||||
mined = 0;
|
||||
turnedIn = 0;
|
||||
this.mineQuestObject = mineQuestObject;
|
||||
}
|
||||
|
||||
public MineQuest(int mined, int turnedIn, String internalName) {
|
||||
this.mined = mined;
|
||||
this.turnedIn = turnedIn;
|
||||
Optional<MineQuestObject> any = QuestsConfig.MINE_QUESTS.stream().filter(object -> internalName.equals(object.getInternalName())).findAny();
|
||||
if (any.isEmpty())
|
||||
return; //TODO error
|
||||
this.mineQuestObject = any.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return false;
|
||||
return isDone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Quest initQuest() {
|
||||
return new MineQuest("Mine", GoalType.MINE);
|
||||
}
|
||||
|
||||
public void mine(Block block, Player player) {
|
||||
|
||||
public void mine(Block block) {
|
||||
if (!isDone && !block.getType().equals(mineQuestObject.getMaterial()))
|
||||
return;
|
||||
mined += 1;
|
||||
if (mined == mineQuestObject.getAmount())
|
||||
isDone = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user