mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-19 14:59:19 +00:00
Fix fauna discovery not working if mythicmobs isn't installed
This commit is contained in:
@@ -19,6 +19,7 @@ import net.islandearth.rpgregions.effects.RegionEffectRegistry;
|
||||
import net.islandearth.rpgregions.effects.VanishEffect;
|
||||
import net.islandearth.rpgregions.exception.CouldNotStartException;
|
||||
import net.islandearth.rpgregions.fauna.FaunaDiscoverer;
|
||||
import net.islandearth.rpgregions.fauna.MythicFaunaDiscoverer;
|
||||
import net.islandearth.rpgregions.folia.schedule.FoliaScheduler;
|
||||
import net.islandearth.rpgregions.gson.AbstractAdapter;
|
||||
import net.islandearth.rpgregions.gson.ItemStackAdapter;
|
||||
@@ -211,9 +212,13 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
|
||||
pm.registerEvents(new RegionListener(this), this);
|
||||
pm.registerEvents(new FaunaListener(this), this);
|
||||
pm.registerEvents(new MoveListener(this), this);
|
||||
if (Bukkit.getPluginManager().getPlugin("CustomStructures") != null) {
|
||||
if (pm.getPlugin("CustomStructures") != null) {
|
||||
pm.registerEvents(new CustomStructuresListener(this), this);
|
||||
}
|
||||
|
||||
if (pm.getPlugin("MythicMobs") != null) {
|
||||
pm.registerEvents(new MythicFaunaDiscoverer(this), this);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package net.islandearth.rpgregions.fauna;
|
||||
|
||||
import io.lumine.mythic.bukkit.events.MythicMobDeathEvent;
|
||||
import io.lumine.mythic.core.mobs.ActiveMob;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.api.events.FaunaDiscoverEvent;
|
||||
import net.islandearth.rpgregions.fauna.trigger.FaunaTrigger;
|
||||
@@ -64,24 +62,7 @@ public class FaunaDiscoverer implements Runnable, Listener {
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onKill(MythicMobDeathEvent event) {
|
||||
final ActiveMob mob = event.getMob();
|
||||
if (!(event.getKiller() instanceof Player killer) || !killer.hasPermission("rpgregions.bestiary")) return;
|
||||
plugin.getManagers().getStorageManager().getAccount(killer.getUniqueId()).thenAccept(account -> {
|
||||
for (FaunaInstance<?> fauna : plugin.getManagers().getFaunaCache().getFauna()) {
|
||||
if (fauna instanceof MythicMobFaunaInstance mythicInstance) {
|
||||
if (!mythicInstance.getType().equals(mob.getType())) continue;
|
||||
if (account.hasDiscovered(fauna.getIdentifier())) continue;
|
||||
if (!fauna.hasTrigger(KillFaunaTrigger.class)) continue;
|
||||
discover(killer, account, fauna);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void discover(Player player, RPGRegionsAccount account, FaunaInstance<?> fauna) {
|
||||
public static void discover(Player player, RPGRegionsAccount account, FaunaInstance<?> fauna) {
|
||||
WorldDiscovery discovery = new WorldDiscovery(LocalDateTime.now(), fauna.getIdentifier());
|
||||
account.addDiscovery(discovery);
|
||||
Bukkit.getPluginManager().callEvent(new FaunaDiscoverEvent(player, fauna, discovery));
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package net.islandearth.rpgregions.fauna;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class FaunaListener implements Listener {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.islandearth.rpgregions.fauna;
|
||||
|
||||
import io.lumine.mythic.bukkit.events.MythicMobDeathEvent;
|
||||
import io.lumine.mythic.core.mobs.ActiveMob;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.fauna.trigger.KillFaunaTrigger;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import static net.islandearth.rpgregions.fauna.FaunaDiscoverer.discover;
|
||||
|
||||
public record MythicFaunaDiscoverer(RPGRegions plugin) implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onKill(MythicMobDeathEvent event) {
|
||||
final ActiveMob mob = event.getMob();
|
||||
if (!(event.getKiller() instanceof Player killer) || !killer.hasPermission("rpgregions.bestiary")) return;
|
||||
plugin.getManagers().getStorageManager().getAccount(killer.getUniqueId()).thenAccept(account -> {
|
||||
for (FaunaInstance<?> fauna : plugin.getManagers().getFaunaCache().getFauna()) {
|
||||
if (fauna instanceof MythicMobFaunaInstance mythicInstance) {
|
||||
if (!mythicInstance.getType().equals(mob.getType())) continue;
|
||||
if (account.hasDiscovered(fauna.getIdentifier())) continue;
|
||||
if (!fauna.hasTrigger(KillFaunaTrigger.class)) continue;
|
||||
discover(killer, account, fauna);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user