Skip to content

Commit

Permalink
Add MythicMobs item & entity matchers (#404)
Browse files Browse the repository at this point in the history
* Add Entity and Item MythicMobs matchers

* Verify the matcher when there's no ID

* Separate the matchers

* Imports

* Can just check the UUID

* Minor cleanup

* Fixes from review
  • Loading branch information
tal5 committed Apr 14, 2023
1 parent 6750698 commit b66fded
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
@@ -1,5 +1,6 @@
package com.denizenscript.depenizen.bukkit.bridges;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.objects.PlayerTag;
Expand All @@ -23,13 +24,13 @@
import com.denizenscript.depenizen.bukkit.properties.mythicmobs.MythicMobsEntityProperties;
import com.denizenscript.depenizen.bukkit.properties.mythicmobs.MythicMobsPlayerProperties;
import com.denizenscript.depenizen.bukkit.utilities.mythicmobs.MythicMobsLoaders;
import io.lumine.mythic.api.mobs.MobManager;
import io.lumine.mythic.api.mobs.MythicMob;
import io.lumine.mythic.bukkit.BukkitAPIHelper;
import io.lumine.mythic.bukkit.BukkitAdapter;
import io.lumine.mythic.bukkit.MythicBukkit;
import io.lumine.mythic.core.items.MythicItem;
import io.lumine.mythic.core.mobs.ActiveMob;
import io.lumine.mythic.core.mobs.MobExecutor;
import io.lumine.mythic.core.skills.variables.*;
import io.lumine.mythic.core.spawning.spawners.MythicSpawner;
import io.lumine.mythic.core.spawning.spawners.SpawnerManager;
Expand Down Expand Up @@ -57,6 +58,39 @@ public void init() {
DenizenCore.commandRegistry.registerCommand(MythicSkillCommand.class);
new MythicMobsLoaders().RegisterEvents();

EntityTag.tagProcessor.custommatchers.add((entityTag, matcher) -> {
if (matcher.equals("mythic_mob")) {
return entityTag.getUUID() != null && getMobManager().isActiveMob(entityTag.getUUID());
}
if (matcher.startsWith("mythic_mob:")) {
Entity entity = entityTag.getBukkitEntity();
ActiveMob activeMob = entity != null ? getActiveMob(entity) : null;
return activeMob != null && ScriptEvent.runGenericCheck(matcher.substring("mythic_mob:".length()), activeMob.getType().getInternalName());
}
return null;
});
ItemTag.tagProcessor.custommatchers.add((itemTag, matcher) -> {
if (matcher.equals("mythic_item")) {
return MythicBukkit.inst().getItemManager().isMythicItem(itemTag.getItemStack());
}
if (matcher.startsWith("mythic_item:")) {
String mythicID = MythicBukkit.inst().getItemManager().getMythicTypeFromItem(itemTag.getItemStack());
return mythicID != null && ScriptEvent.runGenericCheck(matcher.substring("mythic_item:".length()), mythicID);
}
return null;
});

// <--[data]
// @name not_switches
// @values mythic_mob, mythic_item
// -->
ScriptEvent.ScriptPath.notSwitches.add("mythic_mob");
EntityTag.specialEntityMatchables.add("mythic_mob");
BukkitScriptEvent.entityCouldMatchPrefixes.add("mythic_mob");
ScriptEvent.ScriptPath.notSwitches.add("mythic_item");
BukkitScriptEvent.itemCouldMatchableText.add("mythic_item");
BukkitScriptEvent.itemCouldMatchPrefixes.add("mythic_item");

// <--[tag]
// @attribute <mythic_item[<name>]>
// @returns ItemTag
Expand Down Expand Up @@ -163,7 +197,7 @@ public static MythicMob getMythicMob(String name) {
return MythicBukkit.inst().getMobManager().getMythicMob(name).orElse(null);
}

public static MobManager getMobManager() {
public static MobExecutor getMobManager() {
return MythicBukkit.inst().getMobManager();
}

Expand Down
Expand Up @@ -22,8 +22,14 @@ public void RegisterEvents() {
// @group Depenizen Bridges
// @plugin Depenizen, MythicMobs
// @description
// In addition to the the tags, commands, and events found by searching for "mythicmobs" throughout the meta documentation,
// Depenizen adds additional features to Mythic Mobs: 2 Targeters, and a Condition.
// In addition to the tags, commands, and events found by searching for "mythicmobs" throughout the meta documentation,
// Depenizen adds 4 new Denizen matchers, and additional features to Mythic Mobs: 2 Targeters, and a Condition.
//
// Depenizen provides additional <@link objecttype EntityTag> and <@link objecttype ItemTag> matchers to match MythicMobs mobs/items:
// - "mythic_mob" plaintext EntityTag matcher, matches if the entity is a mythic mob.
// - "mythic_mob:<MythicMobID>" EntityTag matcher, matches if the entity is a mythic mob, and its ID matches the advanced matcher specified.
// - "mythic_item" plaintext ItemTag matcher, matches if the item is a mythic item.
// - "mythic_item:<MythicItemID>" ItemTag matcher, matches if the item is a mythic item, and its ID matches the advanced matcher specified.
//
// Depenizen provides two additional targeters via the MythicMobs API: @DenizenEntity is an entity-based targeter, @DenizenLocation is a location-based targeter.
// Both targeters can parse tags; they accept input of either an EntityTag or LocationTag respectively.
Expand All @@ -34,7 +40,7 @@ public void RegisterEvents() {
// The syntax for calling a Denizen tag as a condition is DenizenCondition.
// The tag should return an ElementTag of a boolean value (true or false).
// <context.location> is available for location-based checks,
// <context.entity> is available for for entity- and caster-based checks,
// <context.entity> is available for entity-based and caster-based checks,
// and <context.target> is available for target-based checks.
// NOTE: TriggerConditions are NOT currently supported.
//
Expand Down

0 comments on commit b66fded

Please sign in to comment.