001package com.ericlam.mc.eld.services;
002
003import org.bukkit.Material;
004import org.bukkit.OfflinePlayer;
005import org.bukkit.enchantments.Enchantment;
006import org.bukkit.event.player.PlayerInteractEvent;
007import org.bukkit.event.player.PlayerItemConsumeEvent;
008import org.bukkit.inventory.ItemFlag;
009import org.bukkit.inventory.ItemStack;
010import org.bukkit.inventory.meta.ItemMeta;
011import org.bukkit.persistence.PersistentDataContainer;
012
013import java.util.List;
014import java.util.Map;
015import java.util.function.Consumer;
016
017/**
018 * 物品編輯器
019 */
020public interface ItemStackService {
021
022    /**
023     * 建立物品
024     * @param material 物品類別
025     * @return 物品工廠
026     */
027    ItemFactory build(Material material);
028
029    /**
030     * 編輯物品
031     * @param stack 物品
032     * @return 物品工廠
033     */
034    ItemFactory edit(ItemStack stack);
035
036    /**
037     * 物品工廠
038     */
039    interface ItemFactory {
040
041        /**
042         * 修改類別
043         * @param material 類別
044         * @return this
045         */
046        ItemFactory material(Material material);
047
048        /**
049         * 修改數量
050         * @param amount 數量
051         * @return this
052         */
053        ItemFactory amount(int amount);
054
055        /**
056         * 修改耐久度
057         * @param damage 耐久度
058         * @return this
059         */
060        ItemFactory durability(int damage);
061
062        /**
063         * 顯示名稱
064         * @param display 顯示名稱
065         * @return this
066         */
067        ItemFactory display(String display);
068
069        /**
070         * 新增敘述
071         * @param lore 敘述(行)
072         * @return this
073         */
074        ItemFactory lore(String... lore);
075
076        /**
077         * 設置敘述
078         * @param lore 敘述
079         * @return this
080         */
081        ItemFactory lore(List<String> lore);
082
083        /**
084         * 修改敘述
085         * @param loreEditor 修改敘述
086         * @return this
087         */
088        ItemFactory lore(Consumer<List<String>> loreEditor);
089
090        /**
091         * 新增附魔
092         * @param enchantment 附魔
093         * @param level 等級
094         * @return this
095         */
096        ItemFactory enchant(Enchantment enchantment, int level);
097
098        /**
099         * 設置附魔
100         * @param enchants 附魔表
101         * @return this
102         */
103        ItemFactory enchant(Map<Enchantment, Integer> enchants);
104
105        /**
106         * 修改附魔
107         * @param enchantEditor 附魔編輯
108         * @return this
109         */
110        ItemFactory enchant(Consumer<Map<Enchantment, Integer>> enchantEditor);
111
112        /**
113         * 設置頭顱皮膚, 物品必須為 PLAYER_HEAD
114         * @deprecated 不建議使用,因為每次使用都會請求 URL, 建議使用 {@link #head(String)}
115         * @param player 玩家
116         * @return this
117         */
118        @Deprecated
119        ItemFactory head(OfflinePlayer player);
120
121        /**
122         * 設置頭顱皮膚, 物品必須為 PLAYER_HEAD
123         * @param skullKey 皮膚ID
124         * @return this
125         */
126        ItemFactory head(String skullKey);
127
128        /**
129         * 設置不可破壞
130         * @param unbreakable 不可破壞
131         * @return this
132         */
133        ItemFactory unbreakable(boolean unbreakable);
134
135        /**
136         * 設置 model data
137         * @param modelData model data
138         * @return this
139         */
140        ItemFactory modelData(int modelData);
141
142        /**
143         * 設置 item flags
144         * @param itemFlags item flags
145         * @return this
146         */
147        ItemFactory itemFlags(ItemFlag... itemFlags);
148
149        /**
150         * 編輯物品
151         * @param meta 物品meta
152         * @return this
153         */
154        ItemFactory editItemMeta(Consumer<ItemMeta> meta);
155
156        /**
157         * 設置物品數據儲存器
158         * @param dataEditor 數據儲存編輯
159         * @return this
160         */
161        ItemFactory editPersisData(Consumer<PersistentDataContainer> dataEditor);
162
163        /**
164         * 執行左右鍵事件
165         * @param keyExecute 標識id
166         * @return this
167         */
168        ItemFactory onInteractEvent(String keyExecute);
169
170        /**
171         * 執行臨時的左右鍵事件 (伺服器重啟後消失)
172         * @param handler 事件處理
173         * @return this
174         */
175        ItemFactory onInteractEventTemp(Consumer<PlayerInteractEvent> handler);
176
177        /**
178         * 執行臨時的進食事件 (伺服器重啟後消失)
179         * @param handler 事件處理
180         * @return this
181         */
182        ItemFactory onConsumeEventTemp(Consumer<PlayerItemConsumeEvent> handler);
183
184        /**
185         * 執行進食事件
186         * @param keyExecute 標識id
187         * @return this
188         */
189        ItemFactory onConsumeEvent(String keyExecute);
190
191        /**
192         * 解除左右鍵事件
193         * @return this
194         */
195        ItemFactory destroyInteractEvent();
196
197        /**
198         * 解除進食事件
199         * @return this
200         */
201        ItemFactory destroyClickerEvent();
202
203        /**
204         * 獲取物品
205         * @return 物品
206         */
207        ItemStack getItem();
208
209    }
210}