Skip to content

Commit

Permalink
advanced_matches tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 27, 2021
1 parent 426837f commit 22b21f0
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ public boolean matches(ScriptPath path) {
//
// -->

public boolean tryWorld(WorldTag world, String comparedto) {
public static boolean tryWorld(WorldTag world, String comparedto) {
if (comparedto.equals("world")) {
return true;
}
Expand All @@ -862,7 +862,7 @@ public boolean tryWorld(WorldTag world, String comparedto) {
return runGenericCheck(comparedto, world.getName());
}

public boolean compareInventoryToMatch(InventoryTag inv, MatchHelper matcher) {
public static boolean compareInventoryToMatch(InventoryTag inv, MatchHelper matcher) {
if (matcher instanceof InverseMatchHelper) {
return !compareInventoryToMatch(inv, ((InverseMatchHelper) matcher).matcher);
}
Expand All @@ -885,7 +885,7 @@ public boolean compareInventoryToMatch(InventoryTag inv, MatchHelper matcher) {
return false;
}

public boolean tryInventory(InventoryTag inv, String comparedto) {
public static boolean tryInventory(InventoryTag inv, String comparedto) {
comparedto = CoreUtilities.toLowerCase(comparedto);
if (comparedto.equals("inventory")) {
return true;
Expand All @@ -900,7 +900,7 @@ public boolean tryInventory(InventoryTag inv, String comparedto) {
return compareInventoryToMatch(inv, matcher);
}

public boolean tryItem(ItemTag item, String comparedto) {
public static boolean tryItem(ItemTag item, String comparedto) {
if (comparedto == null || comparedto.isEmpty() || item == null) {
return false;
}
Expand Down Expand Up @@ -933,7 +933,7 @@ public boolean tryItem(ItemTag item, String comparedto) {
return false;
}

public boolean tryMaterial(MaterialTag mat, String comparedto) {
public static boolean tryMaterial(MaterialTag mat, String comparedto) {
if (comparedto == null || comparedto.isEmpty() || mat == null) {
return false;
}
Expand All @@ -957,7 +957,7 @@ public boolean tryMaterial(MaterialTag mat, String comparedto) {
return false;
}

public boolean tryEntity(EntityTag entity, String comparedto) {
public static boolean tryEntity(EntityTag entity, String comparedto) {
if (comparedto == null || comparedto.isEmpty() || entity == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.nms.interfaces.EntityAnimation;
import com.denizenscript.denizen.nms.interfaces.PlayerHelper;
import com.denizenscript.denizen.objects.properties.entity.EntityAge;
Expand Down Expand Up @@ -2493,6 +2494,20 @@ else if (object.getBukkitEntity() instanceof Hanging) {
}
return new EntityTag(object.entity_type, waitingMechs);
});

// <--[tag]
// @attribute <EntityTag.advanced_matches[<matcher>]>
// @returns ElementTag(Boolean)
// @group element checking
// @description
// Returns whether the entity matches some matcher text, using the system behind <@link language Advanced Script Event Matching>.
// -->
registerTag("advanced_matches", (attribute, object) -> {
if (!attribute.hasContext(1)) {
return null;
}
return new ElementTag(BukkitScriptEvent.tryEntity(object, attribute.getContext(1)));
});
}

public static ObjectTagProcessor<EntityTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.scripts.containers.core.InventoryScriptContainer;
import com.denizenscript.denizen.scripts.containers.core.InventoryScriptHelper;
import com.denizenscript.denizen.scripts.containers.core.ItemScriptHelper;
Expand Down Expand Up @@ -2232,6 +2233,20 @@ else if ((object.inventory instanceof FurnaceInventory)) {
return null;
});
tagProcessor.registerFutureTagDeprecation("smelting", "input");

// <--[tag]
// @attribute <InventoryTag.advanced_matches[<matcher>]>
// @returns ElementTag(Boolean)
// @group element checking
// @description
// Returns whether the inventory matches some matcher text, using the system behind <@link language Advanced Script Event Matching>.
// -->
registerTag("advanced_matches", (attribute, object) -> {
if (!attribute.hasContext(1)) {
return null;
}
return new ElementTag(BukkitScriptEvent.tryInventory(object, attribute.getContext(1)));
});
}

public static ObjectTagProcessor<InventoryTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.properties.item.*;
import com.denizenscript.denizen.scripts.containers.core.BookScriptContainer;
import com.denizenscript.denizen.scripts.containers.core.ItemScriptContainer;
Expand Down Expand Up @@ -713,6 +714,20 @@ else if (container != null) {
registerTag("formatted", (attribute, object) -> {
return new ElementTag(object.formattedName());
});

// <--[tag]
// @attribute <ItemTag.advanced_matches[<matcher>]>
// @returns ElementTag(Boolean)
// @group element checking
// @description
// Returns whether the item matches some matcher text, using the system behind <@link language Advanced Script Event Matching>.
// -->
registerTag("advanced_matches", (attribute, object) -> {
if (!attribute.hasContext(1)) {
return null;
}
return new ElementTag(BukkitScriptEvent.tryItem(object, attribute.getContext(1)));
});
}

public String formattedName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.properties.material.*;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.DenizenCore;
Expand Down Expand Up @@ -706,6 +707,20 @@ public static void registerTags() {
Tag<Material> tagItem = Bukkit.getTag("items", key, Material.class);
return new ElementTag((tagBlock != null && tagBlock.isTagged(object.getMaterial()) || (tagItem != null && tagItem.isTagged(object.getMaterial()))));
});

// <--[tag]
// @attribute <MaterialTag.advanced_matches[<matcher>]>
// @returns ElementTag(Boolean)
// @group element checking
// @description
// Returns whether the material matches some matcher text, using the system behind <@link language Advanced Script Event Matching>.
// -->
registerTag("advanced_matches", (attribute, object) -> {
if (!attribute.hasContext(1)) {
return null;
}
return new ElementTag(BukkitScriptEvent.tryMaterial(object, attribute.getContext(1)));
});
}

public static ObjectTagProcessor<MaterialTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.flags.WorldFlagHandler;
Expand Down Expand Up @@ -780,6 +781,20 @@ else if (time >= 12500) {
}
return map;
});

// <--[tag]
// @attribute <WorldTag.advanced_matches[<matcher>]>
// @returns ElementTag(Boolean)
// @group element checking
// @description
// Returns whether the world matches some matcher text, using the system behind <@link language Advanced Script Event Matching>.
// -->
registerTag("advanced_matches", (attribute, object) -> {
if (!attribute.hasContext(1)) {
return null;
}
return new ElementTag(BukkitScriptEvent.tryWorld(object, attribute.getContext(1)));
});
}

public static ObjectTagProcessor<WorldTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down

0 comments on commit 22b21f0

Please sign in to comment.