-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTimefallItem.java
More file actions
74 lines (63 loc) · 2.57 KB
/
Copy pathTimefallItem.java
File metadata and controls
74 lines (63 loc) · 2.57 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
69
70
71
72
73
74
package xyz.holocons.mc.holoitemsrevamp.item;
import com.strangeone101.holoitemsapi.enchantment.EnchantManager;
import com.strangeone101.holoitemsapi.enchantment.Enchantable;
import com.strangeone101.holoitemsapi.item.CustomItem;
import com.strangeone101.holoitemsapi.recipe.RecipeManager;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.jetbrains.annotations.NotNull;
import xyz.holocons.mc.holoitemsrevamp.HoloItemsRevamp;
import java.util.List;
public class TimefallItem extends CustomItem implements Enchantable {
private final static String name = "timefall";
private final static Material material = Material.POWDER_SNOW_BUCKET;
private final static Component displayName = Component.text("Timefall", NamedTextColor.BLUE);
private final static List<Component> lore = List.of(
Component.text("Accelerate oxidation")
);
private final EnchantManager enchantManager;
public TimefallItem(HoloItemsRevamp plugin) {
super(plugin, name, material, displayName, lore);
this.enchantManager = plugin.getEnchantManager();
this.setStackable(false);
this.register();
}
@Override
protected Recipe getRecipe() {
final var recipe = new ShapedRecipe(getKey(), buildStack(null));
recipe.shape(
"ABA",
"BCB",
"ABA"
);
recipe.setIngredient('A', Material.SNOW);
recipe.setIngredient('B', Material.BONE_BLOCK);
recipe.setIngredient('C', Material.BUCKET);
return recipe;
}
@Override
public @NotNull Enchantment getEnchantment() {
return Enchantment.getByKey(getKey());
}
@Override
public ItemStack applyEnchantment(ItemStack itemStack) {
var enchantedStack = itemStack.clone();
var enchantedMeta = enchantedStack.hasItemMeta() ? enchantedStack.getItemMeta() : Bukkit.getItemFactory().getItemMeta(enchantedStack.getType());
if (enchantedMeta.addEnchant(getEnchantment(), 1, false)) {
enchantedStack.setItemMeta(enchantedMeta);
enchantManager.removeCustomEnchantmentLore(enchantedStack);
enchantManager.applyCustomEnchantmentLore(enchantedStack);
return enchantedStack;
} else {
return null;
}
}
}