diff --git a/lib/Denizen-1.2.1-b1744-REL.jar b/lib/Denizen-1.2.1-b1744-REL.jar new file mode 100644 index 00000000..3e194fed Binary files /dev/null and b/lib/Denizen-1.2.1-b1744-REL.jar differ diff --git a/lib/Depenizen-2.0.0-b709.jar b/lib/Depenizen-2.0.0-b709.jar new file mode 100644 index 00000000..4a130bb7 Binary files /dev/null and b/lib/Depenizen-2.0.0-b709.jar differ diff --git a/pom.xml b/pom.xml index 1878668c..082f826d 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,11 @@ + + jitpack.io + https://jitpack.io + + lumine https://mvn.lumine.io/repository/maven/ @@ -73,11 +78,6 @@ https://repo.inventivetalent.org/content/groups/public/ - - jitpack.io - https://jitpack.io - - placeholderapi https://repo.extendedclip.com/content/repositories/placeholderapi/ @@ -373,5 +373,21 @@ ${basedir}/lib/GlowAPI.jar + + com.denizenscript + denizen + 1.2.1-b1744-REL + system + ${basedir}/lib/Denizen-1.2.1-b1744-REL.jar + + + + com.denizenscript + depenizen + 2.0.0-b709 + system + ${basedir}/lib/Depenizen-2.0.0-b709.jar + + diff --git a/src/main/java/net/Indyuce/mmoitems/MMOItems.java b/src/main/java/net/Indyuce/mmoitems/MMOItems.java index b67611e9..8c13427d 100644 --- a/src/main/java/net/Indyuce/mmoitems/MMOItems.java +++ b/src/main/java/net/Indyuce/mmoitems/MMOItems.java @@ -1,5 +1,6 @@ package net.Indyuce.mmoitems; +import com.denizenscript.depenizen.bukkit.Depenizen; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackMessage; @@ -16,6 +17,7 @@ import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.api.util.message.FFPMMOItems; import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; import net.Indyuce.mmoitems.comp.*; +import net.Indyuce.mmoitems.comp.denizen.DenizenBridge; import net.Indyuce.mmoitems.comp.eco.VaultSupport; import net.Indyuce.mmoitems.comp.enchants.AdvancedEnchantmentsHook; import net.Indyuce.mmoitems.comp.enchants.CrazyEnchantsStat; @@ -139,6 +141,12 @@ public class MMOItems extends LuminePlugin { if (Bukkit.getPluginManager().getPlugin("MythicEnchants") != null) enchantPlugins.add(new MythicEnchantsSupport()); + + if (Bukkit.getPluginManager().getPlugin("Depenizen") != null) { + Depenizen depenizen = (Depenizen) Bukkit.getPluginManager().getPlugin("Depenizen"); + depenizen.registerBridge(getName(), () -> new DenizenBridge()); + getLogger().log(Level.INFO, "Hooked onto Denizen"); + } } @Override @@ -251,7 +259,6 @@ public class MMOItems extends LuminePlugin { if (MMOItems.plugin.getConfig().getBoolean("iterate-whole-inventory")) getInventory().register(new OrnamentPlayerInventory()); - if (Bukkit.getPluginManager().getPlugin("CrazyEnchantments") != null) { getStats().register(new CrazyEnchantsStat()); getLogger().log(Level.INFO, "Hooked onto CrazyEnchantments"); diff --git a/src/main/java/net/Indyuce/mmoitems/comp/denizen/DenizenBridge.java b/src/main/java/net/Indyuce/mmoitems/comp/denizen/DenizenBridge.java new file mode 100644 index 00000000..9b5ed404 --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/comp/denizen/DenizenBridge.java @@ -0,0 +1,74 @@ +package net.Indyuce.mmoitems.comp.denizen; + +import com.denizenscript.denizen.objects.ItemTag; +import com.denizenscript.denizencore.objects.ObjectFetcher; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.MapTag; +import com.denizenscript.denizencore.objects.properties.PropertyParser; +import com.denizenscript.denizencore.tags.TagManager; +import com.denizenscript.depenizen.bukkit.Bridge; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.Type; + +/** + * Basic integration with Denizen + */ +public class DenizenBridge extends Bridge { + + @Override + public void init() { + + /* + * This registers sub tags in the custom coded denizen tags + */ + /* ObjectFetcher.registerWithObjectFetcher(MMOItemTag.class, MMOItemTag.tagProcessor);*/ + ObjectFetcher.registerWithObjectFetcher(MMOItemTemplateTag.class, MMOItemTemplateTag.tagProcessor); + + /* + * Implement some properties to the already existing ItemTag + */ + PropertyParser.registerProperty(MMOItemsItemProperty.class, ItemTag.class); + + /* + * This implements a way to retrieve an MMOItem as itemStack. + * + * Usage: + * + */ + TagManager.registerTagHandler("mmoitem_template", attribute -> { + if (!attribute.hasContext(1)) { + attribute.echoError("Please provide an item type and ID."); + return null; + } + + MapTag map = attribute.contextAsType(1, MapTag.class); + if (map == null) { + attribute.echoError("Invalid MapTag input"); + return null; + } + + ObjectTag type = map.getObject("type"); + ObjectTag id = map.getObject("id"); + if (type == null || id == null) { + attribute.echoError("Invalid MapTag input - missing 'type' or 'id'"); + return null; + } + + String typeName = type.toString().replace("-", "_").toUpperCase(); + Type parsedType = MMOItems.plugin.getTypes().get(typeName); + if (parsedType == null) { + attribute.echoError("Invalid type - cannot find type with name '" + typeName + "'"); + return null; + } + + // Format ID and return item + String formattedId = id.toString().replace("-", "_").toUpperCase(); + if (!MMOItems.plugin.getTemplates().hasTemplate(parsedType, formattedId)) { + attribute.echoError("Invalid template ID - cannot find template with name '" + formattedId + "'"); + return null; + } + + return new MMOItemTemplateTag(parsedType, formattedId); + }); + } +} diff --git a/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemTag.java b/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemTag.java new file mode 100644 index 00000000..07e4d2ef --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemTag.java @@ -0,0 +1,57 @@ +package net.Indyuce.mmoitems.comp.denizen; + +import com.denizenscript.denizen.objects.ItemTag; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.tags.Attribute; +import com.denizenscript.denizencore.tags.ObjectTagProcessor; + +@Deprecated +public class MMOItemTag extends SimpleTag { + private final ItemTag item; + + @Deprecated + public MMOItemTag(ItemTag item) { + this.item = item; + } + + @Override + public boolean isUnique() { + return true; + } + + @Override + public String getObjectType() { + return "MMOItem"; + } + + @Override + public String identify() { + return "mmoitem@" + item.identify(); + } + + @Override + public String identifySimple() { + return identify(); + } + + public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); + + @Override + public ObjectTag getObjectAttribute(Attribute attribute) { + return tagProcessor.getObjectAttribute(this, attribute); + } + + public static void registerTags() { + + /* + * Used to get the corresponding itemStack + * + * Usage: + * + * + * Returns: + * ItemTag + */ + tagProcessor.registerTag("item", (attribute, object) -> object.item); + } +} diff --git a/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemTemplateTag.java b/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemTemplateTag.java new file mode 100644 index 00000000..b2c4cb2a --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemTemplateTag.java @@ -0,0 +1,150 @@ +package net.Indyuce.mmoitems.comp.denizen; + +import com.denizenscript.denizen.objects.ItemTag; +import com.denizenscript.denizen.objects.PlayerTag; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.core.MapTag; +import com.denizenscript.denizencore.tags.Attribute; +import com.denizenscript.denizencore.tags.ObjectTagProcessor; +import com.denizenscript.denizencore.tags.TagContext; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.ItemTier; +import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.player.PlayerData; +import org.bukkit.inventory.ItemStack; + +import java.util.Random; + +public class MMOItemTemplateTag extends SimpleTag { + private final Type type; + private final String id; + + private static final Random random = new Random(); + + public MMOItemTemplateTag(Type type, String id) { + this.type = type; + this.id = id; + } + + public MMOItemTemplate getTemplate() { + return MMOItems.plugin.getTemplates().getTemplate(type, id); + } + + @Override + public boolean isUnique() { + return true; + } + + @Override + public String getObjectType() { + return "MMOItemTemplate"; + } + + @Override + public String identify() { + return "mmoitem_template@" + type.getId() + "." + id; + } + + @Override + public String identifySimple() { + return identify(); + } + + public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); + + @Override + public ObjectTag getObjectAttribute(Attribute attribute) { + return tagProcessor.getObjectAttribute(this, attribute); + } + + public static void registerTags() { + + // Display template type name + tagProcessor.registerTag("item_type", ((attribute, object) -> new ElementTag(object.type.getName()))); + + // Display template id + tagProcessor.registerTag("item_id", ((attribute, object) -> new ElementTag(object.id))); + + /* + * Used to generate an item with custom tier and level. + * + * Usage: + * { + if (!attribute.hasContext(1)) + return new ItemTag(object.getTemplate().newBuilder().build().newBuilder().build()); + + MapTag map = attribute.contextAsType(1, MapTag.class); + if (map == null) { + attribute.echoError("Invalid MapTag input"); + return null; + } + + ObjectTag playerTag = map.getObject("player"); + if (playerTag != null && !(playerTag instanceof PlayerTag)) { + attribute.echoError("Bad player input type"); + return null; + } + + // Specified level + ObjectTag levelTag = map.getObject("level"); + int level = -1; + if (levelTag != null) + try { + level = Integer.valueOf(levelTag.toString()); + } catch (IllegalArgumentException exception) { + attribute.echoError("Bad level input: " + levelTag.toString() + " is not a valid integer"); + return null; + } + + // Match level + ObjectTag matchLevelTag = map.getObject("match-level"); + boolean matchLevel = matchLevelTag != null && Boolean.valueOf(matchLevelTag.toString()); + + // Item tier param + ObjectTag tierTag = map.getObject("tier"); + ItemTier tier = null; + if (tierTag != null) + try { + tier = MMOItems.plugin.getTiers().getOrThrow(tierTag.toString().toUpperCase().replace("-", "_")); + } catch (IllegalArgumentException exception) { + attribute.echoError(exception.getMessage()); + } + + // Find item level + int itemLevel = level >= 0 ? level : (matchLevel && playerTag != null ? + MMOItems.plugin.getTemplates().rollLevel(PlayerData.get(((PlayerTag) playerTag).getPlayerEntity()).getRPG().getLevel()) : 1 + random.nextInt(100)); + + // Find item tier + ItemTier itemTier = tier != null ? tier : MMOItems.plugin.getTemplates().rollTier(); + + // Build item + return new ItemTag(object.getTemplate().newBuilder(itemLevel, itemTier).build().newBuilder().build()); + }); + } + + public static MMOItemTemplateTag valueOf(String string, TagContext context) { + if (string == null) + return null; + + try { + String[] split = string.substring("mmoitem_template@".length()).split("\\."); + String typeId = split[0]; + String itemId = split[1]; + + Type type = MMOItems.plugin.getTypes().getOrThrow(typeId); + MMOItems.plugin.getTemplates().getTemplateOrThrow(type, itemId); + + return new MMOItemTemplateTag(type, itemId); + } catch (Exception exception) { + return null; + } + } +} diff --git a/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemsItemProperty.java b/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemsItemProperty.java new file mode 100644 index 00000000..c2e3606a --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemsItemProperty.java @@ -0,0 +1,100 @@ +package net.Indyuce.mmoitems.comp.denizen; + +import com.denizenscript.denizen.objects.ItemTag; +import com.denizenscript.denizencore.objects.Mechanism; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.properties.Property; +import com.denizenscript.denizencore.objects.properties.PropertyParser; +import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmoitems.api.item.util.identify.IdentifiedItem; + +public class MMOItemsItemProperty implements Property { + private final ItemTag item; + + public MMOItemsItemProperty(ItemTag item) { + this.item = item; + } + + @Override + public String getPropertyString() { + return null; + } + + @Override + public String getPropertyId() { + return "MMOItemsItem"; + } + + public boolean isMMOItem() { + return NBTItem.get(item.getItemStack()).hasTag("MMOITEMS_TYPE"); + } + + public MMOItemTag getMMOItem() { + return new MMOItemTag(item); + } + + @Override + public void adjust(Mechanism mechanism) { + // None + } + + public static boolean describes(ObjectTag object) { + return object instanceof ItemTag; + } + + public static MMOItemsItemProperty getFrom(ObjectTag object) { + return object instanceof ItemTag ? new MMOItemsItemProperty((ItemTag) object) : null; + } + + public static final String[] handledMechs = new String[]{}; // None + + public static void registerTags() { + + /* + * Used to check if an ItemTag is an item generated + * using MMOItems or not + * + * Usage: + * + * + * Returns: + * Element tag containing a boolean + */ + PropertyParser.registerTag("is_mmoitem", (attribute, object) -> new ElementTag(object.isMMOItem())); + + /* + * Used to check if an item is an unidentified item from MMOItems + * + * Usage: + * + * + * Returns: + * Element tag containing a boolean + */ + PropertyParser.registerTag("is_unidentified_item", (attribute, object) -> new ElementTag(NBTItem.get(object.item.getItemStack()).hasTag("MMOITEMS_UNIDENTIFIED_ITEM"))); + + /* + * Used to identify an item + * + * Usage: + * + * + * Returns: + * MMOItemTag corresponding to the identified item + */ + PropertyParser.registerTag("identify", (attribute, object) -> new MMOItemTag(new ItemTag(new IdentifiedItem(NBTItem.get(object.item.getItemStack())).identify()))); + + /* + * Used to access utility methods for manipulating + * mmoitems + * + * Usage: + * + * + * Returns: + * MMOItemTag used to manipulate the item + */ + /* PropertyParser.registerTag("mmoitem", (attribute, object) -> object.isMMOItem() ? object.getMMOItem() : null);*/ + } +} diff --git a/src/main/java/net/Indyuce/mmoitems/comp/denizen/SimpleTag.java b/src/main/java/net/Indyuce/mmoitems/comp/denizen/SimpleTag.java new file mode 100644 index 00000000..42dbf0e9 --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/comp/denizen/SimpleTag.java @@ -0,0 +1,20 @@ +package net.Indyuce.mmoitems.comp.denizen; + +import com.denizenscript.denizencore.objects.ObjectTag; + +public abstract class SimpleTag implements ObjectTag { + + // No idea what this is + private String prefix; + + @Override + public String getPrefix() { + return prefix; + } + + @Override + public ObjectTag setPrefix(String prefix) { + this.prefix = prefix; + return this; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 38c6760b..bc356016 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ main: net.Indyuce.mmoitems.MMOItems author: Indyuce description: ${project.description} depend: [MythicLib] -softdepend: [WorldGuard,Holograms,Residence,BossShopPro,SkillAPI,SkillsPro,MMOCore,MythicMobs,MMOInventory,PlaceholderAPI,TrHologram,Vault] +softdepend: [WorldGuard,Residence,BossShopPro,SkillAPI,SkillsPro,MMOCore,MythicMobs,MMOInventory,PlaceholderAPI,Vault,Denizen] api-version: 1.13 commands: mmoitems: