Skip to content

Commit

Permalink
[1.6.2-dev1]新增从mmoitems获取物品
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Dec 13, 2023
1 parent 4ed0563 commit 03314e5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.text.SimpleDateFormat
version = "1.6.1"
version = "1.6.2-dev1"

plugins {
`java-library`
Expand Down Expand Up @@ -38,6 +38,8 @@ dependencies {
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.5.0b")
compileOnly("com.github.oraxen:oraxen:1.160.0")
compileOnly("io.lumine:Mythic-Dist:5.3.5")
compileOnly("io.lumine:MythicLib-dist:1.6.2-SNAPSHOT")
compileOnly("net.Indyuce:MMOItems-API:6.9.5-SNAPSHOT")
implementation("com.crypticlib:CrypticLib:0.7.1")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.github.yufiriamazenta.craftorithm.item.impl;

import com.github.yufiriamazenta.craftorithm.item.ItemProvider;
import crypticlib.util.ItemUtil;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.MMOItems;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public enum MMOItemsItemProvider implements ItemProvider {

INSTANCE;

@Override
public @NotNull String namespace() {
return "mmoitems";
}

@Override
public @Nullable String getItemName(ItemStack itemStack, boolean ignoreAmount) {
NBTItem nbtItem = NBTItem.get(itemStack);
if (!nbtItem.hasType())
return null;
String type = nbtItem.getType();
String id = nbtItem.getString("MMOITEMS_ITEM_ID");
String itemKey = type + ":" + id;
if (ignoreAmount) {
return itemKey;
} else {
ItemStack item = getItem(type + ":" + id);
if (ItemUtil.isAir(item)) {
return null;
}
return type + id + " " + (itemStack.getAmount() / item.getAmount());
}

}

@Override
public @Nullable ItemStack getItem(String itemName) {
if (!itemName.contains(":"))
return null;
int index = itemName.indexOf(":");
String type = itemName.substring(0, index);
String id = itemName.substring(index + 1);
return MMOItems.plugin.getItem(type, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.github.yufiriamazenta.craftorithm.config.Languages;
import com.github.yufiriamazenta.craftorithm.item.ItemManager;
import com.github.yufiriamazenta.craftorithm.item.impl.ItemsAdderItemProvider;
import com.github.yufiriamazenta.craftorithm.item.impl.MythicMobsItemProvider;
import com.github.yufiriamazenta.craftorithm.item.impl.NeigeItemsItemProvider;
import com.github.yufiriamazenta.craftorithm.item.impl.OraxenItemProvider;
import com.github.yufiriamazenta.craftorithm.item.impl.*;
import net.milkbowl.vault.economy.Economy;
import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.Bukkit;
Expand All @@ -15,14 +12,15 @@ public class PluginHookUtil {

private static Economy economy;
private static PlayerPoints playerPoints;
private static boolean economyLoaded, pointsLoaded, itemsAdderLoaded, oraxenLoaded, mythicLoaded, neigeItemsLoaded;
private static boolean economyLoaded, pointsLoaded, itemsAdderLoaded, oraxenLoaded, mythicLoaded, neigeItemsLoaded, mmoitemsLoaded;

public static void hookPlugins() {
hookVault();
hookPlayerPoints();
hookNeigeItems();
hookItemsAdder();
hookOraxen();
hookMMOItems();
hookMythicMobs();
}

Expand Down Expand Up @@ -105,6 +103,16 @@ private static void hookNeigeItems() {
LangUtil.info(Languages.LOAD_HOOK_PLUGIN_NOT_EXIST.value(), CollectionsUtil.newStringHashMap("<plugin>", "NeigeItems"));
}

private static void hookMMOItems() {
mmoitemsLoaded = Bukkit.getPluginManager().isPluginEnabled("MMOItems");
if (mmoitemsLoaded) {
ItemManager.INSTANCE.regItemProvider(MMOItemsItemProvider.INSTANCE);
LangUtil.info(Languages.LOAD_HOOK_PLUGIN_SUCCESS.value(), CollectionsUtil.newStringHashMap("<plugin>", "MMOItems"));
}
else
LangUtil.info(Languages.LOAD_HOOK_PLUGIN_NOT_EXIST.value(), CollectionsUtil.newStringHashMap("<plugin>", "MMOItems"));
}

public static boolean isItemsAdderLoaded() {
return itemsAdderLoaded;
}
Expand All @@ -121,4 +129,8 @@ public static boolean isNeigeItemsLoaded() {
return neigeItemsLoaded;
}

public static boolean isMmoitemsLoaded() {
return mmoitemsLoaded;
}

}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Craft recipes management system
main: com.github.yufiriamazenta.craftorithm.Craftorithm
api-version: 1.13
load: POSTWORLD
softdepend: [ Vault, LuckPerms, PlayerPoints, PlaceholderAPI, ItemsAdder, Oraxen, MythicMobs, NeigeItems ]
softdepend: [ Vault, LuckPerms, PlayerPoints, PlaceholderAPI, ItemsAdder, Oraxen, MythicMobs, NeigeItems, MMOItems ]
authors: [ YufiriaMazenta ]
folia-supported: true
website: https://github.com/YufiriaMazenta/Craftorithm
Expand Down

0 comments on commit 03314e5

Please sign in to comment.