Added support for Shearing and Bucket quests and fixed some minor things.
This commit is contained in:
parent
e0d3251bc9
commit
8eb28ea5f6
|
|
@ -70,6 +70,8 @@ public final class AQuest extends JavaPlugin {
|
|||
getServer().getPluginManager().registerEvents(new DonNotMessWithNPC(), this);
|
||||
getServer().getPluginManager().registerEvents(new DataLock(), this);
|
||||
getServer().getPluginManager().registerEvents(new ItemCaught(), this);
|
||||
getServer().getPluginManager().registerEvents(new PotionBrewingStarted(), this);
|
||||
getServer().getPluginManager().registerEvents(new PotionBrewingFinished(), this);
|
||||
// getServer().getMessenger().registerOutgoingPluginChannel(this, "aquest:player-data");
|
||||
// getServer().getMessenger().registerIncomingPluginChannel(this, "aquest:player-data", new PluginMessageListener());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,7 @@ import com.alttd.altitudequests.AQuest;
|
|||
import com.alttd.altitudequests.commands.SubCommand;
|
||||
import com.alttd.altitudequests.config.MessagesConfig;
|
||||
import com.alttd.altitudequests.objects.Quest;
|
||||
import com.alttd.altitudequests.objects.quests.BreedMobsQuest;
|
||||
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.objects.quests.*;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -17,8 +14,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandSetQuest extends SubCommand {
|
||||
|
|
@ -68,6 +63,7 @@ public class CommandSetQuest extends SubCommand {
|
|||
case "collectdropsquest" -> res.addAll(CollectDropsQuest.getSubTypes());
|
||||
case "killmobsquest" -> res.addAll(KillMobsQuest.getSubTypes());
|
||||
case "minequest" -> res.addAll(MineQuest.getSubTypes());
|
||||
case "otherquest" -> res.addAll(OtherQuest.getSubTypes());
|
||||
default -> res.add("invalid quest type");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,10 +157,10 @@ public class QuestsConfig extends AbstractConfig {
|
|||
|
||||
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!");
|
||||
public static Material item;
|
||||
public static EntityType entityType;
|
||||
|
||||
private static void loadOtherQuests() {
|
||||
OTHER_QUEST.clear();
|
||||
|
|
@ -172,11 +172,23 @@ public class QuestsConfig extends AbstractConfig {
|
|||
Set<String> keys = configurationSection.getKeys(false);
|
||||
for (String key : keys) {
|
||||
try {
|
||||
Material item = Material.valueOf(configurationSection.getString(key + ".item"));
|
||||
if (configurationSection.getString(key + ".item") == null) {
|
||||
item = null;
|
||||
}
|
||||
else {
|
||||
item = Material.valueOf(configurationSection.getString(key + ".item"));
|
||||
}
|
||||
if (configurationSection.getString(key + ".mob") == null) {
|
||||
entityType = null;
|
||||
}
|
||||
else {
|
||||
entityType = EntityType.valueOf(configurationSection.getString(key + ".mob"));
|
||||
}
|
||||
OTHER_QUEST.add(new OtherQuestObject(key,
|
||||
configurationSection.getString(key + ".name"),
|
||||
configurationSection.getString(key + ".category"),
|
||||
item,
|
||||
entityType,
|
||||
configurationSection.getStringList(key + ".quest-pages"),
|
||||
configurationSection.getStringList(key + ".done-pages"),
|
||||
configurationSection.getInt(key + ".amount-min"),
|
||||
|
|
@ -191,8 +203,8 @@ public class QuestsConfig extends AbstractConfig {
|
|||
}
|
||||
}
|
||||
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_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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,27 +2,28 @@ package com.alttd.altitudequests.events;
|
|||
|
||||
import com.alttd.altitudequests.objects.Quest;
|
||||
import com.alttd.altitudequests.objects.quests.CollectDropsQuest;
|
||||
import com.alttd.altitudequests.objects.quests.OtherQuest;
|
||||
import org.bukkit.entity.Entity;
|
||||
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.PlayerBucketFillEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EntityBucketed implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBucketFill(PlayerBucketFillEvent event) {
|
||||
public void onBucketFill(PlayerBucketEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Quest dailyQuest = Quest.getDailyQuest(player.getUniqueId());
|
||||
if (dailyQuest == null || dailyQuest.isDone())
|
||||
return;
|
||||
if (dailyQuest instanceof CollectDropsQuest collectDropsQuest) {
|
||||
ItemStack itemStack = event.getItemStack();
|
||||
if (itemStack != null)
|
||||
collectDropsQuest.collectDrops(List.of(itemStack));
|
||||
if (dailyQuest instanceof OtherQuest otherQuest) {
|
||||
ItemStack itemStack = event.getEntityBucket();
|
||||
Entity entity = event.getEntity();
|
||||
if (itemStack != null && entity != null)
|
||||
otherQuest.bucket(itemStack, entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
package com.alttd.altitudequests.events;
|
||||
|
||||
import com.alttd.altitudequests.objects.Quest;
|
||||
import com.alttd.altitudequests.objects.quests.CollectDropsQuest;
|
||||
import com.alttd.altitudequests.objects.quests.OtherQuest;
|
||||
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.PlayerShearEntityEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EntitySheared implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
|
|
@ -18,8 +16,8 @@ public class EntitySheared implements Listener {
|
|||
Quest dailyQuest = Quest.getDailyQuest(player.getUniqueId());
|
||||
if (dailyQuest == null || dailyQuest.isDone())
|
||||
return;
|
||||
if (dailyQuest instanceof CollectDropsQuest collectDropsQuest) {
|
||||
collectDropsQuest.collectDrops(List.of(event.getItem()));
|
||||
if (dailyQuest instanceof OtherQuest otherQuest) {
|
||||
otherQuest.shear(event.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,10 +12,14 @@ 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.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
|
@ -101,8 +105,8 @@ public class OtherQuest extends Quest {
|
|||
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("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);
|
||||
|
|
@ -145,7 +149,8 @@ public class OtherQuest extends Quest {
|
|||
|
||||
@Override
|
||||
public Component getDisplayName() {
|
||||
return MiniMessage.miniMessage().deserialize(QuestsConfig.OTHER_QUEST_NAME+"<green>: </green>"+OtherQuestObject.getCategory());
|
||||
return MiniMessage.miniMessage().deserialize("<green>%s: </green>".formatted( otherQuestObject.getCategory()));
|
||||
//return MiniMessage.miniMessage().deserialize("%s<green>: </green>%s".formatted(QuestsConfig.OTHER_QUEST_NAME, otherQuestObject.getCategory()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -154,11 +159,36 @@ public class OtherQuest extends Quest {
|
|||
}
|
||||
|
||||
public void fish(ItemStack caughtItem){
|
||||
if (isDone() || !caughtItem.getType().equals(otherQuestObject.getMaterial()) ||getAmount() == getStep1())
|
||||
if (isDone() || !caughtItem.getType().equals(otherQuestObject.getMaterial()) || getAmount() == getStep1()) {
|
||||
return;
|
||||
}
|
||||
addStep1(1);
|
||||
checkDone();
|
||||
}
|
||||
|
||||
public void shear(Entity entity) {
|
||||
if (isDone() || !entity.getType().equals(otherQuestObject.getEntity()) || getAmount() == getStep1()) {
|
||||
return;
|
||||
}
|
||||
DyeColor color = getDyeColorFromItemStack(otherQuestObject.getMaterial());
|
||||
if (entity instanceof Sheep) {
|
||||
Sheep sheep = (Sheep) entity;
|
||||
if (sheep.getColor() != color) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
addStep1(1);
|
||||
checkDone();
|
||||
}
|
||||
|
||||
public void bucket(ItemStack bucket, Entity entity) {
|
||||
if (isDone() || !entity.getType().equals(otherQuestObject.getEntity()) || getAmount() == getStep1()) {
|
||||
return;
|
||||
}
|
||||
addStep1(1);
|
||||
checkDone();
|
||||
}
|
||||
|
||||
public void raid(){}
|
||||
public void collectDrops(List<ItemStack> drops) {
|
||||
if (isDone() || getAmount() == getStep1())
|
||||
|
|
@ -173,7 +203,28 @@ public class OtherQuest extends Quest {
|
|||
checkDone();
|
||||
}
|
||||
|
||||
public void brewingStarted(ItemStack ingredient, Location brewingStandLocation){
|
||||
Logger.warning("Brewing Started");
|
||||
}
|
||||
|
||||
public void brewingFinished(List <ItemStack> results, Location brewingStandLocation) {
|
||||
Logger.warning("Brewing Finished");
|
||||
}
|
||||
|
||||
public static List<String> getSubTypes() {
|
||||
return QuestsConfig.OTHER_QUEST.stream().map(Variant::getInternalName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static DyeColor getDyeColorFromItemStack(Material material) {
|
||||
if (material != null && material.name().contains("_WOOL")) {
|
||||
String colorName = material.name().replace("_WOOL", "");
|
||||
try {
|
||||
return DyeColor.valueOf(colorName);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
// This will be thrown if the color name doesn't match the enum
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,20 +2,23 @@ package com.alttd.altitudequests.objects.variants;
|
|||
|
||||
import com.alttd.altitudequests.objects.Variant;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
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;
|
||||
private final EntityType entity;
|
||||
private final String step1;
|
||||
private final String step2;
|
||||
private final String category;
|
||||
|
||||
public OtherQuestObject(String internalName, String name, String category, Material item,
|
||||
public OtherQuestObject(String internalName, String name, String category, Material item, EntityType entity,
|
||||
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.entity = entity;
|
||||
this.step1 = step1;
|
||||
this.step2 = step2;
|
||||
this.category = category;
|
||||
|
|
@ -24,7 +27,8 @@ public class OtherQuestObject extends Variant {
|
|||
public Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
public static String getStep1() {return step1;}
|
||||
public static String getStep2() {return step2;}
|
||||
public static String getCategory() {return category;}
|
||||
public EntityType getEntity() {return entity;}
|
||||
public String getStep1() {return step1;}
|
||||
public String getStep2() {return step2;}
|
||||
public String getCategory() {return category;}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user