Skip to content

Commit

Permalink
✨Item new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusSlover committed May 1, 2024
1 parent 6989f0b commit 0b9771b
Showing 1 changed file with 109 additions and 4 deletions.
113 changes: 109 additions & 4 deletions src/main/java/com/marcusslover/plus/lib/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,30 @@ public int maxStack() {
return this.itemStack.getType().getMaxStackSize();
}

/**
* @return the material type of this item
*/
public @NotNull Material material() {
return this.type();
}

/**
* @return the material type of this item
*/
public @NotNull Material type() {
return this.itemStack.getType();
}

/**
* Change the material type used in this item.
*
* @param material the material type of this item
* @return this item
*/
public @NotNull Item material(@NotNull Material material) {
return this.type(material);
}

/**
* Change the material type used in this item.
*
Expand All @@ -134,6 +151,17 @@ public int maxStack() {
return this;
}

/**
* Change the material type used in this item.
* IMPORTANT: This method creates a new item with the specified material.
*
* @param material the material type of this item
* @return brand new item
*/
public @NotNull Item withType(@NotNull Material material) {
return Item.of(this.itemStack.withType(material));
}

/**
* @return the amount of items in the stack
*/
Expand All @@ -152,6 +180,74 @@ public int amount() {
return this;
}

/**
* Increment the amount of items in the stack by 1.
* @return the item
*/
public @NotNull Item increment() {
return this.increase();
}

/**
* Increment the amount of items in the stack by the specified amount.
* @param amount the amount to increment by
* @return the item
*/
public @NotNull Item increment(int amount) {
return this.increase(amount);
}

/**
* Increment the amount of items in the stack by 1.
* @return the item
*/
public @NotNull Item increase() {
return this.increase(1);
}

/**
* Increment the amount of items in the stack by the specified amount.
* @param amount the amount to increment by
* @return the item
*/
public @NotNull Item increase(int amount) {
return this.amount(this.amount() + amount);
}

/**
* Decrement the amount of items in the stack by 1.
* @return the item
*/
public @NotNull Item decrement() {
return this.decrease();
}

/**
* Decrement the amount of items in the stack by the specified amount.
* @param amount the amount to decrement by
* @return the item
*/
public @NotNull Item decrement(int amount) {
return this.decrease(amount);
}

/**
* Decrement the amount of items in the stack by 1.
* @return the item
*/
public @NotNull Item decrease() {
return this.decrease(1);
}

/**
* Decrement the amount of items in the stack by the specified amount.
* @param amount the amount to decrement by
* @return the item
*/
public @NotNull Item decrease(int amount) {
return this.amount(this.amount() - amount);
}

/**
* Changes the amount of damage this item has as a percentage.
*
Expand Down Expand Up @@ -246,12 +342,21 @@ public boolean hasEnchant(@NotNull Enchantment enchantment) {
}

public @NotNull Item glow() {
if (this.itemStack.getType().equals(Material.BOW)) {
enchant(Enchantment.DIG_SPEED, 1);
return this.glow(true);
}

public @NotNull Item glow(boolean glow) {
if (glow) {
if (this.itemStack.getType().equals(Material.BOW)) {
enchant(Enchantment.DIG_SPEED, 1);
} else {
enchant(Enchantment.ARROW_INFINITE, 1);
}
return addItemFlag(ItemFlag.HIDE_ENCHANTS);
} else {
enchant(Enchantment.ARROW_INFINITE, 1);
clearEnchants();
return removeItemFlag(ItemFlag.HIDE_ENCHANTS);
}
return addItemFlag(ItemFlag.HIDE_ENCHANTS);
}

/**
Expand Down

0 comments on commit 0b9771b

Please sign in to comment.