Compare commits

..

1 Commits

Author SHA1 Message Date
efb7ed2d58 Updates quest classes to 5.0.0 2024-01-07 05:23:03 +01:00
3 changed files with 40 additions and 40 deletions

View File

@ -71,15 +71,15 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.blackvein.quests</groupId> <groupId>me.pikamug.quests</groupId>
<artifactId>quests-api</artifactId> <artifactId>quests-api</artifactId>
<version>4.8.1</version> <version>5.0.0-rc.3</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.blackvein.quests</groupId> <groupId>me.pikamug.quests</groupId>
<artifactId>quests-core</artifactId> <artifactId>quests-core</artifactId>
<version>4.8.1</version> <version>5.0.0-rc.3</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,9 +1,9 @@
package net.knarcraft.questmobspawns; package net.knarcraft.questmobspawns;
import me.blackvein.quests.QuestsAPI; import me.pikamug.quests.Quests;
import me.blackvein.quests.player.IQuester; import me.pikamug.quests.player.Quester;
import me.blackvein.quests.quests.IQuest; import me.pikamug.quests.quests.Quest;
import me.blackvein.quests.quests.IStage; import me.pikamug.quests.quests.components.Stage;
import net.knarcraft.questmobspawns.listener.MobBlockDamageListener; import net.knarcraft.questmobspawns.listener.MobBlockDamageListener;
import net.knarcraft.questmobspawns.listener.MobDeathListener; import net.knarcraft.questmobspawns.listener.MobDeathListener;
import net.knarcraft.questmobspawns.util.QuestMobHelper; import net.knarcraft.questmobspawns.util.QuestMobHelper;
@ -36,7 +36,7 @@ public final class QuestMobSpawns extends JavaPlugin {
private final Random random = new Random(); private final Random random = new Random();
private static QuestMobSpawns plugin; private static QuestMobSpawns plugin;
private QuestsAPI questsAPI; private Quests questsAPI;
public static QuestMobSpawns getPlugin() { public static QuestMobSpawns getPlugin() {
return plugin; return plugin;
@ -46,7 +46,7 @@ public final class QuestMobSpawns extends JavaPlugin {
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
// Set up the quests API // Set up the quests API
questsAPI = (QuestsAPI) Bukkit.getServer().getPluginManager().getPlugin("Quests"); questsAPI = (Quests) Bukkit.getServer().getPluginManager().getPlugin("Quests");
if (questsAPI == null) { if (questsAPI == null) {
this.setEnabled(false); this.setEnabled(false);
return; return;
@ -64,22 +64,22 @@ public final class QuestMobSpawns extends JavaPlugin {
*/ */
private void spawnMobs() { private void spawnMobs() {
// Find the players taking each quest // Find the players taking each quest
Set<IQuest> questsWithPlayers = new HashSet<>(); Set<Quest> questsWithPlayers = new HashSet<>();
Map<IStage, Set<IQuester>> stagePlayerMap = new HashMap<>(); Map<Stage, Set<Quester>> stagePlayerMap = new HashMap<>();
Collection<IQuester> onlineQuestTakers = questsAPI.getOnlineQuesters(); Collection<Quester> onlineQuestTakers = questsAPI.getOnlineQuesters();
// If no quest takers are online, abort // If no quest takers are online, abort
if (onlineQuestTakers == null || onlineQuestTakers.isEmpty()) { if (onlineQuestTakers == null || onlineQuestTakers.isEmpty()) {
return; return;
} }
for (IQuester questPlayer : onlineQuestTakers) { for (Quester questPlayer : onlineQuestTakers) {
for (IQuest quest : questPlayer.getQuestData().keySet()) { for (Quest quest : questPlayer.getCurrentQuests().keySet()) {
questsWithPlayers.add(quest); questsWithPlayers.add(quest);
IStage playerStage = questPlayer.getCurrentStage(quest); Stage playerStage = questPlayer.getCurrentStage(quest);
for (int i = 0; i < playerStage.getMobsToKill().size(); i++) { for (int i = 0; i < playerStage.getMobsToKill().size(); i++) {
// If the player has not killed enough mobs, spawn the mobs // If the player has not killed enough mobs, spawn the mobs
if (questPlayer.getQuestData(quest).getMobNumKilled().get(i) >= playerStage.getMobNumToKill().get(i)) { if (questPlayer.getQuestDataOrDefault(quest).getMobNumKilled().get(i) >= playerStage.getMobNumToKill().get(i)) {
continue; continue;
} }
@ -97,13 +97,13 @@ public final class QuestMobSpawns extends JavaPlugin {
return; return;
} }
for (IQuest quest : questsAPI.getLoadedQuests()) { for (Quest quest : questsAPI.getLoadedQuests()) {
// Ignore quests with no players // Ignore quests with no players
if (!questsWithPlayers.contains(quest)) { if (!questsWithPlayers.contains(quest)) {
continue; continue;
} }
for (IStage stage : quest.getStages()) { for (Stage stage : quest.getStages()) {
for (int i = 0; i < stage.getLocationsToKillWithin().size(); i++) { for (int i = 0; i < stage.getLocationsToKillWithin().size(); i++) {
spawnMobsForStage(stagePlayerMap, quest, stage, i); spawnMobsForStage(stagePlayerMap, quest, stage, i);
} }
@ -119,9 +119,9 @@ public final class QuestMobSpawns extends JavaPlugin {
* @param stage <p>The stage to spawn mobs for</p> * @param stage <p>The stage to spawn mobs for</p>
* @param index <p>The index of the kill location to spawn mobs for</p> * @param index <p>The index of the kill location to spawn mobs for</p>
*/ */
private void spawnMobsForStage(@NotNull Map<IStage, @NotNull Set<IQuester>> questPlayerMap, @NotNull IQuest quest, private void spawnMobsForStage(@NotNull Map<Stage, @NotNull Set<Quester>> questPlayerMap, @NotNull Quest quest,
@NotNull IStage stage, int index) { @NotNull Stage stage, int index) {
Location killLocation = stage.getLocationsToKillWithin().get(index).clone(); Location killLocation = ((Location) stage.getLocationsToKillWithin().get(index)).clone();
int radius = stage.getRadiiToKillWithin().get(index); int radius = stage.getRadiiToKillWithin().get(index);
// TODO: De-spawn custom mobs if players are no longer in the area (should probably save the state) // TODO: De-spawn custom mobs if players are no longer in the area (should probably save the state)
@ -139,7 +139,7 @@ public final class QuestMobSpawns extends JavaPlugin {
} }
// If there are a bunch of mobs in the area, don't spawn more // If there are a bunch of mobs in the area, don't spawn more
EntityType entityType = stage.getMobsToKill().get(index); EntityType entityType = (EntityType) stage.getMobsToKill().get(index);
int nearby = entitiesInKillZone(killLocation, radius, entityType); int nearby = entitiesInKillZone(killLocation, radius, entityType);
if (nearby >= maxMobs) { if (nearby >= maxMobs) {
return; return;
@ -206,14 +206,14 @@ public final class QuestMobSpawns extends JavaPlugin {
* @param maxMobs <p>The maximum amount of mobs allowed in the kill zone</p> * @param maxMobs <p>The maximum amount of mobs allowed in the kill zone</p>
* @return <p>The number of mobs to spawn</p> * @return <p>The number of mobs to spawn</p>
*/ */
private int calculateMobNumber(@NotNull Map<IStage, @NotNull Set<IQuester>> questPlayerMap, @NotNull IQuest quest, private int calculateMobNumber(@NotNull Map<Stage, @NotNull Set<Quester>> questPlayerMap, @NotNull Quest quest,
@NotNull IStage stage, int index, @NotNull Location killLocation, int radius, @NotNull Stage stage, int index, @NotNull Location killLocation, int radius,
int maxMobs) { int maxMobs) {
int mobsToSpawn = 0; int mobsToSpawn = 0;
for (IQuester player : questPlayerMap.get(stage)) { for (Quester player : questPlayerMap.get(stage)) {
Location playerLocation = player.getPlayer().getLocation().clone(); Location playerLocation = player.getPlayer().getLocation().clone();
playerLocation.setY(0); playerLocation.setY(0);
if (player.getQuestData(quest).getMobNumKilled().get(index) < stage.getMobNumToKill().get(index) && if (player.getQuestDataOrDefault(quest).getMobNumKilled().get(index) < stage.getMobNumToKill().get(index) &&
QuestMobHelper.get2dDistance(killLocation, playerLocation) < radius) { QuestMobHelper.get2dDistance(killLocation, playerLocation) < radius) {
mobsToSpawn++; mobsToSpawn++;
} }

View File

@ -1,9 +1,9 @@
package net.knarcraft.questmobspawns.listener; package net.knarcraft.questmobspawns.listener;
import me.blackvein.quests.QuestsAPI; import me.pikamug.quests.Quests;
import me.blackvein.quests.player.IQuester; import me.pikamug.quests.player.Quester;
import me.blackvein.quests.quests.IQuest; import me.pikamug.quests.quests.Quest;
import me.blackvein.quests.quests.IStage; import me.pikamug.quests.quests.components.Stage;
import net.knarcraft.questmobspawns.util.QuestMobHelper; import net.knarcraft.questmobspawns.util.QuestMobHelper;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -26,9 +26,9 @@ import org.jetbrains.annotations.Nullable;
*/ */
public class MobBlockDamageListener implements Listener { public class MobBlockDamageListener implements Listener {
private final QuestsAPI questsAPI; private final Quests questsAPI;
public MobBlockDamageListener(@NotNull QuestsAPI questsAPI) { public MobBlockDamageListener(@NotNull Quests questsAPI) {
this.questsAPI = questsAPI; this.questsAPI = questsAPI;
} }
@ -95,12 +95,12 @@ public class MobBlockDamageListener implements Listener {
* @return <p>True if the player has the quest stored in the entity</p> * @return <p>True if the player has the quest stored in the entity</p>
*/ */
private Boolean hasQuest(@NotNull Entity entity, @NotNull Player player) { private Boolean hasQuest(@NotNull Entity entity, @NotNull Player player) {
IQuester questPlayer = questsAPI.getQuester(player.getUniqueId()); Quester questPlayer = questsAPI.getQuester(player.getUniqueId());
String questId = QuestMobHelper.getQuestId(entity); String questId = QuestMobHelper.getQuestId(entity);
if (questId == null) { if (questId == null) {
return false; return false;
} }
IQuest quest = getQuest(questId); Quest quest = getQuest(questId);
if (quest == null) { if (quest == null) {
// Remove the entity if the quest it belongs to no longer exists // Remove the entity if the quest it belongs to no longer exists
entity.remove(); entity.remove();
@ -110,13 +110,13 @@ public class MobBlockDamageListener implements Listener {
if (stageId == null) { if (stageId == null) {
return false; return false;
} }
IStage stage = quest.getStage(stageId); Stage stage = quest.getStage(stageId);
Integer index = QuestMobHelper.getIndex(entity); Integer index = QuestMobHelper.getIndex(entity);
if (index == null) { if (index == null) {
return false; return false;
} }
return questPlayer.getQuestData().containsKey(quest) && questPlayer.getCurrentStage(quest) == stage && return questPlayer.getCurrentQuests().containsKey(quest) && questPlayer.getCurrentStage(quest) == stage &&
questPlayer.getQuestData(quest).getMobNumKilled().get(index) < stage.getMobNumToKill().get(index); questPlayer.getQuestDataOrDefault(quest).getMobNumKilled().get(index) < stage.getMobNumToKill().get(index);
} }
/** /**
@ -125,8 +125,8 @@ public class MobBlockDamageListener implements Listener {
* @param questId <p>The id of the quest to get</p> * @param questId <p>The id of the quest to get</p>
* @return <p>The quest, or null if no such quest exists</p> * @return <p>The quest, or null if no such quest exists</p>
*/ */
private @Nullable IQuest getQuest(@NotNull String questId) { private @Nullable Quest getQuest(@NotNull String questId) {
for (IQuest quest : questsAPI.getLoadedQuests()) { for (Quest quest : questsAPI.getLoadedQuests()) {
if (quest.getId().equalsIgnoreCase(questId)) { if (quest.getId().equalsIgnoreCase(questId)) {
return quest; return quest;
} }