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>
</dependency>
<dependency>
<groupId>me.blackvein.quests</groupId>
<groupId>me.pikamug.quests</groupId>
<artifactId>quests-api</artifactId>
<version>4.8.1</version>
<version>5.0.0-rc.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.blackvein.quests</groupId>
<groupId>me.pikamug.quests</groupId>
<artifactId>quests-core</artifactId>
<version>4.8.1</version>
<version>5.0.0-rc.3</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -1,9 +1,9 @@
package net.knarcraft.questmobspawns;
import me.blackvein.quests.QuestsAPI;
import me.blackvein.quests.player.IQuester;
import me.blackvein.quests.quests.IQuest;
import me.blackvein.quests.quests.IStage;
import me.pikamug.quests.Quests;
import me.pikamug.quests.player.Quester;
import me.pikamug.quests.quests.Quest;
import me.pikamug.quests.quests.components.Stage;
import net.knarcraft.questmobspawns.listener.MobBlockDamageListener;
import net.knarcraft.questmobspawns.listener.MobDeathListener;
import net.knarcraft.questmobspawns.util.QuestMobHelper;
@ -36,7 +36,7 @@ public final class QuestMobSpawns extends JavaPlugin {
private final Random random = new Random();
private static QuestMobSpawns plugin;
private QuestsAPI questsAPI;
private Quests questsAPI;
public static QuestMobSpawns getPlugin() {
return plugin;
@ -46,7 +46,7 @@ public final class QuestMobSpawns extends JavaPlugin {
public void onEnable() {
plugin = this;
// Set up the quests API
questsAPI = (QuestsAPI) Bukkit.getServer().getPluginManager().getPlugin("Quests");
questsAPI = (Quests) Bukkit.getServer().getPluginManager().getPlugin("Quests");
if (questsAPI == null) {
this.setEnabled(false);
return;
@ -64,22 +64,22 @@ public final class QuestMobSpawns extends JavaPlugin {
*/
private void spawnMobs() {
// Find the players taking each quest
Set<IQuest> questsWithPlayers = new HashSet<>();
Map<IStage, Set<IQuester>> stagePlayerMap = new HashMap<>();
Collection<IQuester> onlineQuestTakers = questsAPI.getOnlineQuesters();
Set<Quest> questsWithPlayers = new HashSet<>();
Map<Stage, Set<Quester>> stagePlayerMap = new HashMap<>();
Collection<Quester> onlineQuestTakers = questsAPI.getOnlineQuesters();
// If no quest takers are online, abort
if (onlineQuestTakers == null || onlineQuestTakers.isEmpty()) {
return;
}
for (IQuester questPlayer : onlineQuestTakers) {
for (IQuest quest : questPlayer.getQuestData().keySet()) {
for (Quester questPlayer : onlineQuestTakers) {
for (Quest quest : questPlayer.getCurrentQuests().keySet()) {
questsWithPlayers.add(quest);
IStage playerStage = questPlayer.getCurrentStage(quest);
Stage playerStage = questPlayer.getCurrentStage(quest);
for (int i = 0; i < playerStage.getMobsToKill().size(); i++) {
// 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;
}
@ -97,13 +97,13 @@ public final class QuestMobSpawns extends JavaPlugin {
return;
}
for (IQuest quest : questsAPI.getLoadedQuests()) {
for (Quest quest : questsAPI.getLoadedQuests()) {
// Ignore quests with no players
if (!questsWithPlayers.contains(quest)) {
continue;
}
for (IStage stage : quest.getStages()) {
for (Stage stage : quest.getStages()) {
for (int i = 0; i < stage.getLocationsToKillWithin().size(); 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 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,
@NotNull IStage stage, int index) {
Location killLocation = stage.getLocationsToKillWithin().get(index).clone();
private void spawnMobsForStage(@NotNull Map<Stage, @NotNull Set<Quester>> questPlayerMap, @NotNull Quest quest,
@NotNull Stage stage, int index) {
Location killLocation = ((Location) stage.getLocationsToKillWithin().get(index)).clone();
int radius = stage.getRadiiToKillWithin().get(index);
// 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
EntityType entityType = stage.getMobsToKill().get(index);
EntityType entityType = (EntityType) stage.getMobsToKill().get(index);
int nearby = entitiesInKillZone(killLocation, radius, entityType);
if (nearby >= maxMobs) {
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>
* @return <p>The number of mobs to spawn</p>
*/
private int calculateMobNumber(@NotNull Map<IStage, @NotNull Set<IQuester>> questPlayerMap, @NotNull IQuest quest,
@NotNull IStage stage, int index, @NotNull Location killLocation, int radius,
private int calculateMobNumber(@NotNull Map<Stage, @NotNull Set<Quester>> questPlayerMap, @NotNull Quest quest,
@NotNull Stage stage, int index, @NotNull Location killLocation, int radius,
int maxMobs) {
int mobsToSpawn = 0;
for (IQuester player : questPlayerMap.get(stage)) {
for (Quester player : questPlayerMap.get(stage)) {
Location playerLocation = player.getPlayer().getLocation().clone();
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) {
mobsToSpawn++;
}

View File

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