diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index c9097bc6..b7bac5fc 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -52,6 +52,7 @@ dependencies { compileOnly(files("libs/CustomCrops-api.jar")) compileOnly(files("libs/mcMMO-api.jar")) compileOnly(files("libs/ClueScrolls-4.8.7-api.jar")) + compileOnly(files("libs/notquests-5.17.1.jar")) // api module implementation(project(":api")) diff --git a/plugin/libs/notquests-5.17.1.jar b/plugin/libs/notquests-5.17.1.jar new file mode 100644 index 00000000..d308c7bf Binary files /dev/null and b/plugin/libs/notquests-5.17.1.jar differ diff --git a/plugin/src/main/java/net/momirealms/customfishing/compatibility/IntegrationManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/compatibility/IntegrationManagerImpl.java index 4d353b77..e959e41a 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/compatibility/IntegrationManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/compatibility/IntegrationManagerImpl.java @@ -32,6 +32,7 @@ import net.momirealms.customfishing.compatibility.item.*; import net.momirealms.customfishing.compatibility.level.*; import net.momirealms.customfishing.compatibility.quest.BetonQuestHook; import net.momirealms.customfishing.compatibility.quest.ClueScrollsHook; +import net.momirealms.customfishing.compatibility.quest.NotQuestHook; import net.momirealms.customfishing.compatibility.season.CustomCropsSeasonImpl; import net.momirealms.customfishing.compatibility.season.RealisticSeasonsImpl; import org.bukkit.Bukkit; @@ -135,14 +136,20 @@ public class IntegrationManagerImpl implements IntegrationManager { } if (plugin.isHookedPluginEnabled("ClueScrolls")) { ClueScrollsHook clueScrollsHook = new ClueScrollsHook(); - Bukkit.getPluginManager().registerEvents(clueScrollsHook, plugin); + clueScrollsHook.register(); hookMessage("ClueScrolls"); } if (plugin.isHookedPluginEnabled("BetonQuest")) { if (Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("BetonQuest")).getPluginMeta().getVersion().startsWith("2")) { BetonQuestHook.register(); + hookMessage("BetonQuest"); } } + if (plugin.isHookedPluginEnabled("NotQuests")) { + NotQuestHook notQuestHook = new NotQuestHook(); + notQuestHook.register(); + hookMessage("NotQuests"); + } } @Override diff --git a/plugin/src/main/java/net/momirealms/customfishing/compatibility/quest/ClueScrollsHook.java b/plugin/src/main/java/net/momirealms/customfishing/compatibility/quest/ClueScrollsHook.java index 64694b7a..08878cc0 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/compatibility/quest/ClueScrollsHook.java +++ b/plugin/src/main/java/net/momirealms/customfishing/compatibility/quest/ClueScrollsHook.java @@ -21,6 +21,7 @@ import com.electro2560.dev.cluescrolls.api.*; import net.momirealms.customfishing.api.CustomFishingPlugin; import net.momirealms.customfishing.api.event.FishingResultEvent; import net.momirealms.customfishing.api.mechanic.loot.Loot; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -35,6 +36,10 @@ public class ClueScrollsHook implements Listener { groupClue = ClueScrollsAPI.getInstance().registerCustomClue(CustomFishingPlugin.getInstance(), "group", new ClueConfigData("group", DataType.STRING)); } + public void register() { + Bukkit.getPluginManager().registerEvents(this, CustomFishingPlugin.get()); + } + @EventHandler public void onFish(FishingResultEvent event) { if (event.isCancelled() || event.getResult() == FishingResultEvent.Result.FAILURE) diff --git a/plugin/src/main/java/net/momirealms/customfishing/compatibility/quest/NotQuestHook.java b/plugin/src/main/java/net/momirealms/customfishing/compatibility/quest/NotQuestHook.java new file mode 100644 index 00000000..aec0f0c1 --- /dev/null +++ b/plugin/src/main/java/net/momirealms/customfishing/compatibility/quest/NotQuestHook.java @@ -0,0 +1,180 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customfishing.compatibility.quest; + +import net.momirealms.customfishing.api.CustomFishingPlugin; +import net.momirealms.customfishing.api.event.FishingResultEvent; +import net.momirealms.customfishing.api.mechanic.loot.Loot; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.checkerframework.checker.nullness.qual.Nullable; +import rocks.gravili.notquests.paper.NotQuests; +import rocks.gravili.notquests.paper.structs.ActiveObjective; +import rocks.gravili.notquests.paper.structs.ActiveQuest; +import rocks.gravili.notquests.paper.structs.QuestPlayer; +import rocks.gravili.notquests.paper.structs.objectives.Objective; + +import java.util.Map; + +public class NotQuestHook implements Listener { + + private final NotQuests notQuestsInstance; + + public NotQuestHook() { + this.notQuestsInstance = NotQuests.getInstance(); + } + + @EventHandler + public void onFish(FishingResultEvent event) { + if (event.isCancelled() || event.getResult() == FishingResultEvent.Result.FAILURE) + return; + Loot loot = event.getLoot(); + Player player = event.getPlayer(); + final QuestPlayer questPlayer = notQuestsInstance.getQuestPlayerManager().getActiveQuestPlayer(player.getUniqueId()); + if (questPlayer != null) { + if (questPlayer.getActiveQuests().size() > 0) { + for (final ActiveQuest activeQuest : questPlayer.getActiveQuests()) { + for (final ActiveObjective activeObjective : activeQuest.getActiveObjectives()) { + if (activeObjective.getObjective() instanceof GroupObjective groupObjective) { + if (activeObjective.isUnlocked()) { + final String[] groups = loot.getLootGroup(); + if (groups != null) + for (String group : groups) { + if (group.equals(groupObjective.getGroupToFish())) { + activeObjective.addProgress(event.getAmount()); + } + } + } + } else if (activeObjective.getObjective() instanceof LootObjective lootObjective) { + if (activeObjective.isUnlocked()) { + if (lootObjective.getLootID().equals(loot.getID()) || lootObjective.getLootID().equals("any")) { + activeObjective.addProgress(event.getAmount()); + } + } + } + } + activeQuest.removeCompletedObjectives(true); + } + questPlayer.removeCompletedQuests(); + } + } + } + + public void register() { + Bukkit.getPluginManager().registerEvents(this, CustomFishingPlugin.get()); + notQuestsInstance.getObjectiveManager().registerObjective("CustomFishingGroup", GroupObjective.class); + notQuestsInstance.getObjectiveManager().registerObjective("CustomFishingGroup", GroupObjective.class); + } + + public static class GroupObjective extends Objective { + + private String group; + + public GroupObjective(NotQuests main) { + super(main); + } + + @Override + protected String getTaskDescriptionInternal(QuestPlayer questPlayer, @Nullable ActiveObjective activeObjective) { + return main.getLanguageManager() + .getString( + "chat.objectives.taskDescription.customfishingGroup.base", + questPlayer, + activeObjective, + Map.of("%CUSTOMFISHINGGROUP%", getGroupToFish())); + } + + @Override + public void save(FileConfiguration fileConfiguration, String initialPath) { + fileConfiguration.set(initialPath + ".specifics.group", getGroupToFish()); + } + + @Override + public void load(FileConfiguration fileConfiguration, String initialPath) { + group = fileConfiguration.getString(initialPath + ".specifics.group"); + } + + @Override + public void onObjectiveUnlock(ActiveObjective activeObjective, boolean b) { + } + + @Override + public void onObjectiveCompleteOrLock(ActiveObjective activeObjective, boolean b, boolean b1) { + } + + public String getGroupToFish() { + return group; + } + } + + public static class LootObjective extends Objective { + + private String loot; + + public LootObjective(NotQuests main) { + super(main); + } + + @Override + protected String getTaskDescriptionInternal(QuestPlayer questPlayer, @Nullable ActiveObjective activeObjective) { + String toReturn; + if (!getLootID().isBlank() && !getLootID().equals("any")) { + toReturn = + main.getLanguageManager() + .getString( + "chat.objectives.taskDescription.customfishingLoot.base", + questPlayer, + activeObjective, + Map.of("%CUSTOMFISHINGLOOT%", getLootID())); + } else { + toReturn = + main.getLanguageManager() + .getString( + "chat.objectives.taskDescription.customfishingLoot.any", + questPlayer, + activeObjective); + } + return toReturn; + } + + @Override + public void save(FileConfiguration fileConfiguration, String initialPath) { + fileConfiguration.set(initialPath + ".specifics.id", getLootID()); + } + + @Override + public void load(FileConfiguration fileConfiguration, String initialPath) { + loot = fileConfiguration.getString(initialPath + ".specifics.id"); + } + + @Override + public void onObjectiveUnlock(ActiveObjective activeObjective, boolean b) { + } + + @Override + public void onObjectiveCompleteOrLock(ActiveObjective activeObjective, boolean b, boolean b1) { + } + + public String getLootID() { + return loot; + } + } +}