-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathItemsAdderIngredient.java
More file actions
68 lines (59 loc) · 1.93 KB
/
ItemsAdderIngredient.java
File metadata and controls
68 lines (59 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package fr.traqueur.recipes.impl.hook.hooks;
import dev.lone.itemsadder.api.CustomStack;
import fr.traqueur.recipes.api.domains.Ingredient;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.checkerframework.checker.units.qual.C;
/**
* This class is an implementation of the BaseIngredient class.
* It is used to represent an ingredient that is an item from the ItemsAdder plugin.
*/
public class ItemsAdderIngredient extends Ingredient {
/**
* The CustomStack object that represents the item from ItemsAdder.
*/
private final String data;
/**
* Constructor of the class.
* @param data The id of the item from ItemsAdder.
* @param sign The sign that represents the ingredient in the recipe.
*/
public ItemsAdderIngredient(String data, Character sign) {
super(sign);
this.data = data;
}
/**
* Constructor of the class.
* @param data The id of the item from ItemsAdder.
*/
public ItemsAdderIngredient(String data) {
this(data,null);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isSimilar(ItemStack ingredient) {
CustomStack item = CustomStack.byItemStack(ingredient);
if (item == null) return false;
return item.getNamespacedID().equals(this.getCustomStack().getNamespacedID());
}
/**
* {@inheritDoc}
*/
@Override
public RecipeChoice choice() {
return new RecipeChoice.MaterialChoice(this.getCustomStack().getItemStack().getType());
}
private CustomStack getCustomStack() {
CustomStack customStack = CustomStack.getInstance(data);
if(customStack == null) {
throw new IllegalArgumentException("The item " + data + " is not registered in ItemsAdder.");
}
return customStack;
}
@Override
public String toString() {
return this.getCustomStack().getNamespacedID();
}
}