From b7ca245ff1f9ddb0aab97902bc34ace718ecf1f0 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 27 Jan 2020 02:10:37 +0100 Subject: [PATCH] Add dungeon mob API --- .../de/erethon/dungeonsxl/api/DungeonMob.java | 57 +++++++++++++++++++ .../erethon/dungeonsxl/api/DungeonsAPI.java | 54 ++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 api/src/main/java/de/erethon/dungeonsxl/api/DungeonMob.java diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/DungeonMob.java b/api/src/main/java/de/erethon/dungeonsxl/api/DungeonMob.java new file mode 100644 index 00000000..288f0650 --- /dev/null +++ b/api/src/main/java/de/erethon/dungeonsxl/api/DungeonMob.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2014-2020 Daniel Saukel + * + * This library is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) 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 GNULesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package de.erethon.dungeonsxl.api; + +import de.erethon.caliburn.mob.ExMob; +import org.bukkit.entity.LivingEntity; + +/** + * Wrapper for a mob spawned in a dungeon. + * + * @author Daniel Saukel + */ +public interface DungeonMob { + + /** + * Returns the entity that is wrapped by this object. + * + * @return the entity that is wrapped by this object + */ + LivingEntity getEntity(); + + /** + * Returns the Caliburn representation of the mob or null if it is spawned by an external plugin. + * + * @return the Caliburn representation of the mob or null if it is spawned by an external plugin + */ + ExMob getType(); + + /** + * Returns if the mob is spawned by an external plugin. + * + * @return if the mob is spawned by an external plugin + */ + default boolean isExternalMob() { + return getType() == null; + } + + /** + * Returns the String used to identify this mob for example in the context of triggers. + * + * @return the String used to identify this mob for example in the context of triggers + */ + String getTriggerId(); + +} diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/DungeonsAPI.java b/api/src/main/java/de/erethon/dungeonsxl/api/DungeonsAPI.java index b179905e..555a1cf7 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/DungeonsAPI.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/DungeonsAPI.java @@ -14,12 +14,15 @@ */ package de.erethon.dungeonsxl.api; +import de.erethon.caliburn.mob.ExMob; import de.erethon.commons.misc.Registry; import de.erethon.dungeonsxl.api.player.PlayerClass; import de.erethon.dungeonsxl.api.player.PlayerGroup; import de.erethon.dungeonsxl.api.sign.DungeonSign; +import de.erethon.dungeonsxl.api.world.GameWorld; import java.io.File; import java.util.Collection; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -57,7 +60,9 @@ public interface DungeonsAPI extends Plugin { * Returns a {@link Registry} of the trigger types. * * @return a {@link Registry} of the trigger types + * @deprecated stub */ + @Deprecated Registry> getTriggerRegistry(); /** @@ -114,4 +119,53 @@ public interface DungeonsAPI extends Plugin { */ PlayerGroup createGroup(Player leader, Collection members, String name, Dungeon dungeon); + /** + * Wraps the given {@link LivingEntity} object in a {@link DungeonMob} object. + * + * @param entity the entity + * @param gameWorld the game world where the entity is + * @return the wrapped DungeonMob + */ + DungeonMob wrapEntity(LivingEntity entity, GameWorld gameWorld); + + /** + * Wraps the given {@link LivingEntity} object in a {@link DungeonMob} object. + * + * @param entity the entity + * @param gameWorld the game world where the entity is + * @param triggerId the identifier used in mob triggers + * @return the wrapped DungeonMob + */ + DungeonMob wrapEntity(LivingEntity entity, GameWorld gameWorld, String triggerId); + + /** + * Wraps the given {@link LivingEntity} object in a {@link DungeonMob} object. + * + * @param entity the entity + * @param gameWorld the game world where the entity is + * @param type the ExMob type of the entity + * @return the wrapped DungeonMob + */ + DungeonMob wrapEntity(LivingEntity entity, GameWorld gameWorld, ExMob type); + + /** + * Wraps the given {@link LivingEntity} object in a {@link DungeonMob} object. + * + * @param entity the entity + * @param gameWorld the game world where the entity is + * @param type the ExMob type of the entity + * @param triggerId the identifier used in mob triggers + * @return the wrapped DungeonMob + */ + DungeonMob wrapEntity(LivingEntity entity, GameWorld gameWorld, ExMob type, String triggerId); + + /* Getters */ + /** + * Returns an existing {@link DungeonMob} object that wraps the given {@link LivingEntity} object or null if none exists. + * + * @param entity the entity + * @return an existing {@link DungeonMob} object that wraps the given {@link LivingEntity} object or null if none exists + */ + DungeonMob getDungeonMob(LivingEntity entity); + }