-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the ability to include MythicMobs in Blueprints. Fixes #2316
- Loading branch information
1 parent
cb7c63a
commit 4810c4c
Showing
14 changed files
with
455 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/world/bentobox/bentobox/hooks/MythicMobsHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package world.bentobox.bentobox.hooks; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.entity.Entity; | ||
|
||
import io.lumine.mythic.bukkit.BukkitAdapter; | ||
import io.lumine.mythic.bukkit.MythicBukkit; | ||
import io.lumine.mythic.core.mobs.ActiveMob; | ||
import world.bentobox.bentobox.api.hooks.Hook; | ||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity.MythicMobRecord; | ||
|
||
/** | ||
* Provides implementation and interfacing to interact with MythicMobs. | ||
* | ||
* @author tastybento | ||
* @since 2.2.0 | ||
*/ | ||
public class MythicMobsHook extends Hook { | ||
|
||
public MythicMobsHook() { | ||
super("MythicMobs", Material.CREEPER_HEAD); | ||
} | ||
|
||
public boolean isMythicMob(Entity bukkitEntity) { | ||
return MythicBukkit.inst().getMobManager().isMythicMob(bukkitEntity); | ||
} | ||
|
||
public MythicMobRecord getMythicMob(Entity bukkitEntity) { | ||
ActiveMob mm = MythicBukkit.inst().getMobManager().getActiveMob(bukkitEntity.getUniqueId()).orElse(null); | ||
if (mm != null) { | ||
return new MythicMobRecord(mm.getMobType(), mm.getDisplayName(), mm.getLevel(), | ||
mm.getPower(), | ||
mm.getStance()); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public boolean hook() { | ||
return true; // The hook process shouldn't fail | ||
} | ||
|
||
@Override | ||
public String getFailureCause() { | ||
return null; // The hook process shouldn't fail | ||
} | ||
|
||
/** | ||
* Spawn a MythicMob | ||
* @param mmr MythicMobRecord | ||
* @param spawnLocation location | ||
* @return true if spawn is successful | ||
*/ | ||
public boolean spawnMythicMob(MythicMobRecord mmr, Location spawnLocation) { | ||
return MythicBukkit.inst().getMobManager().getMythicMob(mmr.type()).map(mob -> { | ||
// A delay is required before spawning, I assume because the blocks are pasted using NMS | ||
Bukkit.getScheduler().runTaskLater(getPlugin(), () -> { | ||
// spawns mob | ||
ActiveMob activeMob = mob.spawn(BukkitAdapter.adapt(spawnLocation), mmr.level()); | ||
activeMob.setDisplayName(mmr.displayName()); | ||
activeMob.setPower(mmr.power()); | ||
activeMob.setStance(mmr.stance()); | ||
}, 40L); | ||
return true; | ||
}).orElse(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.