-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ed0563
commit 03314e5
Showing
4 changed files
with
70 additions
and
7 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
49 changes: 49 additions & 0 deletions
49
src/main/java/com/github/yufiriamazenta/craftorithm/item/impl/MMOItemsItemProvider.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,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); | ||
} | ||
} |
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