Skip to content

Commit

Permalink
Add amount field
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 committed Jul 5, 2024
1 parent 9ef683e commit af9922a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/main/java/com/nookure/core/inv/paper/PaperItemConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public ItemStack convert(Item item, I18nAdapter<Player> adapter) {
}
}

itemStack.setAmount(item.amount());

ItemMeta meta = itemStack.getItemMeta();

if (meta == null) {
Expand All @@ -63,34 +65,39 @@ public ItemStack convert(Item item, I18nAdapter<Player> adapter) {
if (item.name() != null) {
meta.displayName(adapter.translateComponent(item.name(), item.tl()));
}
List<Component> lore = new ArrayList<>();

if (item.lore() != null) {
List<Component> lore = new ArrayList<>();

if (item.lore().loreLines() != null) {
item.lore().loreLines().forEach(line -> lore.add(adapter.translateComponent(line, item.tl())));
}
}

if (item.literalLore() != null) {
if (item.literalLore() != null) {
if (item.literalLore().loreLines() != null) {
item.literalLore().loreLines().forEach(line -> lore.add(adapter.translateComponent(line, item.tl())));
}

meta.lore(lore);
}

meta.lore(lore);

} else {
if (item.name() != null) {
meta.setDisplayName(adapter.translate(item.name(), item.tl()));
}

if (item.lore() != null) {
List<String> lore = new ArrayList<>();
if (item.lore() != null) {
if (item.lore().loreLines() != null) {
item.lore().loreLines().forEach(line -> lore.add(adapter.translate(line, item.tl())));
}

if (item.literalLore() != null) {
item.literalLore().loreLines().forEach(line -> lore.add(adapter.translate(line, item.tl())));
}
meta.setLore(lore);
}

if (item.literalLore() != null) {
List<String> lore = new ArrayList<>();
item.literalLore().loreLines().forEach(line -> lore.add(adapter.translate(line, item.tl())));

meta.setLore(lore);
}
Expand Down Expand Up @@ -129,9 +136,12 @@ private ItemStack createHead(String value, HeadType type) {
}

return SkullCreator.itemFromUuid(uuid);
case URL: return SkullCreator.itemFromUrl(value);
case BASE64: return SkullCreator.itemFromBase64(value);
default: return null;
case URL:
return SkullCreator.itemFromUrl(value);
case BASE64:
return SkullCreator.itemFromBase64(value);
default:
return null;
}
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/nookure/core/inv/parser/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.slf4j.LoggerFactory;

import java.util.logging.Logger;


@XmlAccessorType(XmlAccessType.FIELD)
public class Item {
private static final Logger LOGGER = Logger.getLogger(Item.class.getName());
private static final org.slf4j.Logger log = LoggerFactory.getLogger(Item.class);

@XmlAttribute(name = "id")
private String id;

Expand All @@ -25,6 +31,9 @@ public class Item {
@XmlAttribute(name = "headType")
private HeadType headType;

@XmlAttribute
private int amount;

@XmlElement(name = "Name")
@XmlJavaTypeAdapter(MiniMessageAdapter.class)
private String name;
Expand Down Expand Up @@ -142,4 +151,22 @@ public Item setHeadType(HeadType headType) {
this.headType = headType;
return this;
}

public int amount() {
if (amount <= 0) {
return 1;
}

if (amount > 64) {
LOGGER.warning("Amount of item " + id + " is greater than 64, setting to 64");
return 64;
}

return amount;
}

public Item setAmount(int amount) {
this.amount = amount;
return this;
}
}

0 comments on commit af9922a

Please sign in to comment.