mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-30 06:03:30 +01:00
General cleanup and polish
Added display options. Cleaned up crate end task. Redid option storage. Fixed bugs abroad
This commit is contained in:
parent
08611d1eb3
commit
7c917babda
@ -24,6 +24,8 @@ import java.util.*;
|
||||
*/
|
||||
public class KitEditor {
|
||||
|
||||
public enum Action { NONE, CHANCE, DISPLAY_ITEM, DISPLAY_NAME, DISPLAY_LORE}
|
||||
|
||||
private final Map<UUID, KitEditorPlayerData> editorPlayerData = new HashMap<>();
|
||||
|
||||
private UltimateKits instance;
|
||||
@ -32,9 +34,11 @@ public class KitEditor {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void openOverview(Kit kit, Player player, boolean backb, ItemStack command, int slot) {
|
||||
public void openOverview(Kit kit, Player player, boolean backb, ItemStack toReplace, int slot) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
playerData.setToReplace(null);
|
||||
playerData.setToReplaceSlot(0);
|
||||
|
||||
//assign kit to object.
|
||||
playerData.setKit(kit);
|
||||
@ -77,14 +81,17 @@ public class KitEditor {
|
||||
i.setItem(8, exit);
|
||||
|
||||
int num = 10;
|
||||
List<ItemStack> list = kit.getReadableContents(player, true, true);
|
||||
List<ItemStack> list = kit.getReadableContents(player, false,true, true);
|
||||
for (ItemStack iss : list) {
|
||||
if (num == 17 || num == 36)
|
||||
num++;
|
||||
|
||||
if (num == slot && toReplace != null) {
|
||||
iss = toReplace;
|
||||
}
|
||||
|
||||
KitItem item = new KitItem(iss);
|
||||
|
||||
if (slot != 0 && slot == num) item.setChance(item.getChance() == 100 ? 5 : (item.getChance() + 5));
|
||||
ItemStack is = item.getMoveableItem();
|
||||
|
||||
ItemMeta meta;
|
||||
@ -98,6 +105,11 @@ public class KitEditor {
|
||||
else itemLore = new ArrayList<>();
|
||||
itemLore.add(TextComponent.convertToInvisibleString("----"));
|
||||
itemLore.add(TextComponent.formatText("&7Chance: &6" + item.getChance() + "%"));
|
||||
if (playerData.isInFuction()) {
|
||||
itemLore.add(TextComponent.formatText("&7Display Item: &6" + (item.getDisplayItem() == null ? "null" : item.getDisplayItem().name())));
|
||||
itemLore.add(TextComponent.formatText("&7Display Name: &6" + TextComponent.formatText(item.getDisplayName())));
|
||||
itemLore.add(TextComponent.formatText("&7Display Lore: &6" + TextComponent.formatText(item.getDisplayLore())));
|
||||
}
|
||||
itemLore.add("");
|
||||
if (playerData.isInFuction()) {
|
||||
itemLore.add(TextComponent.formatText("&7Left-Click: &6To set a display item."));
|
||||
@ -105,6 +117,11 @@ public class KitEditor {
|
||||
itemLore.add(TextComponent.formatText("&7Right-Click: &6To set display lore."));
|
||||
itemLore.add(TextComponent.formatText("&7Shift-Click: &6To set chance."));
|
||||
itemLore.add("");
|
||||
itemLore.add(TextComponent.formatText("&7Display options only show up on display."));
|
||||
itemLore.add(TextComponent.formatText("&7This can be useful if you want to explain"));
|
||||
itemLore.add(TextComponent.formatText("&7What an item does without putting it in the"));
|
||||
itemLore.add(TextComponent.formatText("&7permanent lore."));
|
||||
itemLore.add("");
|
||||
itemLore.add(TextComponent.formatText("&6Leave function mode to move items."));
|
||||
}
|
||||
meta.setLore(itemLore);
|
||||
@ -130,8 +147,8 @@ public class KitEditor {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
if (command != null)
|
||||
i.setItem(num, command);
|
||||
if (toReplace != null && slot == 0)
|
||||
i.setItem(num, toReplace);
|
||||
|
||||
i.setItem(3, Methods.getGlass());
|
||||
i.setItem(5, Methods.getGlass());
|
||||
@ -171,6 +188,42 @@ public class KitEditor {
|
||||
}
|
||||
}
|
||||
|
||||
public void replaceItem(Action action, Player player, ItemStack itemStack, int slot) {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
playerData.setToReplace(itemStack);
|
||||
playerData.setToReplaceSlot(slot);
|
||||
|
||||
if (itemStack.getItemMeta().hasLore()) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : meta.getLore()) {
|
||||
if (line.equals(TextComponent.convertToInvisibleString("----"))) break;
|
||||
newLore.add(line);
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
KitItem item = new KitItem(itemStack);
|
||||
|
||||
switch (action) {
|
||||
case CHANCE:
|
||||
item.setChance(item.getChance() == 100 ? 5 : (item.getChance() + 5));
|
||||
playerData.setMuteSave(true);
|
||||
openOverview(getDataFor(player).getKit(), player, false, item.getMoveableItem(), slot);
|
||||
break;
|
||||
case DISPLAY_ITEM:
|
||||
editDisplayItem(player);
|
||||
break;
|
||||
case DISPLAY_NAME:
|
||||
editDisplayName(player);
|
||||
break;
|
||||
case DISPLAY_LORE:
|
||||
editDisplayLore(player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateInvButton(Inventory i, KitEditorPlayerData playerData) {
|
||||
ItemStack alli = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta allmeta = alli.getItemMeta();
|
||||
@ -664,7 +717,7 @@ public class KitEditor {
|
||||
|
||||
Kit kit = playerData.getKit();
|
||||
if (kit.getKitAnimation() == KitAnimation.NONE) {
|
||||
kit.setKitAnimation(KitAnimation.CSGO);
|
||||
kit.setKitAnimation(KitAnimation.ROULETTE);
|
||||
} else {
|
||||
kit.setKitAnimation(KitAnimation.NONE);
|
||||
}
|
||||
@ -846,6 +899,72 @@ public class KitEditor {
|
||||
}
|
||||
}
|
||||
|
||||
public void editDisplayItem(Player player) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (playerData.getEditorType() == KitEditorPlayerData.EditorType.LINK) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.getReferences().getPrefix() + "Editing Timed out."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
}
|
||||
}, 200L);
|
||||
player.closeInventory();
|
||||
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.DISPLAY_ITEM);
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("Please type a material. Example: &aStone"));
|
||||
player.sendMessage("");
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void editDisplayName(Player player) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (playerData.getEditorType() == KitEditorPlayerData.EditorType.LINK) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.getReferences().getPrefix() + "Editing Timed out."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
}
|
||||
}, 200L);
|
||||
player.closeInventory();
|
||||
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.DISPLAY_NAME);
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("Please type a name. Example: &aCool Item"));
|
||||
player.sendMessage("");
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void editDisplayLore(Player player) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (playerData.getEditorType() == KitEditorPlayerData.EditorType.LINK) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.getReferences().getPrefix() + "Editing Timed out."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
}
|
||||
}, 200L);
|
||||
player.closeInventory();
|
||||
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.DISPLAY_LORE);
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("Please type in lore. Example: &aCool Lore"));
|
||||
player.sendMessage("");
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public KitEditorPlayerData getDataFor(Player player) {
|
||||
return editorPlayerData.computeIfAbsent(player.getUniqueId(), uuid -> new KitEditorPlayerData());
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ public class KitEditorPlayerData {
|
||||
private boolean showFuctions = false;
|
||||
private boolean muteSave = false;
|
||||
|
||||
private int toReplaceSlot = 0;
|
||||
private ItemStack toReplace = null;
|
||||
|
||||
public Kit getKit() {
|
||||
return kit;
|
||||
}
|
||||
@ -61,5 +64,21 @@ public class KitEditorPlayerData {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
public enum EditorType {OVERVIEW, GENERAL, SELLING, GUI, COMMAND, MONEY, DELAY, TITLE, PRICE, LINK, NOTIN}
|
||||
public int getToReplaceSlot() {
|
||||
return toReplaceSlot;
|
||||
}
|
||||
|
||||
public void setToReplaceSlot(int toReplaceSlot) {
|
||||
this.toReplaceSlot = toReplaceSlot;
|
||||
}
|
||||
|
||||
public ItemStack getToReplace() {
|
||||
return toReplace;
|
||||
}
|
||||
|
||||
public void setToReplace(ItemStack toReplace) {
|
||||
this.toReplace = toReplace;
|
||||
}
|
||||
|
||||
public enum EditorType {OVERVIEW, GENERAL, SELLING, GUI, COMMAND, MONEY, DELAY, TITLE, PRICE, LINK, NOTIN, DISPLAY_ITEM, DISPLAY_NAME, DISPLAY_LORE}
|
||||
}
|
||||
|
@ -6,7 +6,9 @@ import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.editor.KitEditor;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.editor.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.kit.KitItem;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -44,6 +46,32 @@ public class ChatListeners implements Listener {
|
||||
event.setCancelled(true);
|
||||
|
||||
switch (playerData.getEditorType()) {
|
||||
case DISPLAY_ITEM:
|
||||
ItemStack toReplace = null;
|
||||
try {
|
||||
Material material = Material.valueOf(msg.trim().toUpperCase());
|
||||
|
||||
KitItem item = new KitItem(playerData.getToReplace());
|
||||
item.setDisplayItem(material);
|
||||
|
||||
toReplace = item.getMoveableItem();
|
||||
} catch (Exception e) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("&a" + msg + " &8is not a valid material."));
|
||||
}
|
||||
edit.openOverview(edit.getDataFor(player).getKit(), player, false, toReplace, playerData.getToReplaceSlot());
|
||||
break;
|
||||
case DISPLAY_NAME:
|
||||
KitItem item = new KitItem(playerData.getToReplace());
|
||||
item.setDisplayName(msg);
|
||||
|
||||
edit.openOverview(edit.getDataFor(player).getKit(), player, false, item.getMoveableItem(), playerData.getToReplaceSlot());
|
||||
break;
|
||||
case DISPLAY_LORE:
|
||||
KitItem item2 = new KitItem(playerData.getToReplace());
|
||||
item2.setDisplayLore(msg);
|
||||
|
||||
edit.openOverview(edit.getDataFor(player).getKit(), player, false, item2.getMoveableItem(), playerData.getToReplaceSlot());
|
||||
break;
|
||||
case PRICE:
|
||||
if (plugin.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + Arconix.pl().getApi().format().formatText("&8You must have &aVault &8installed to utilize economy.."));
|
||||
|
@ -179,19 +179,24 @@ public class InventoryListeners implements Listener {
|
||||
KitEditor edit = instance.getKitEditor();
|
||||
if (instance.getKitEditor().getDataFor(player).getEditorType() == KitEditorPlayerData.EditorType.OVERVIEW) {
|
||||
KitEditorPlayerData editorData = edit.getDataFor(player);
|
||||
if (!(event.getRawSlot() > event.getView().getTopInventory().getSize() - 1)) {
|
||||
if ((event.getSlot() > 9 && event.getSlot() < 44) && event.getSlot() != 17 && event.getSlot() != 36) {
|
||||
if (event.getCurrentItem().getType() != Material.AIR) {
|
||||
if (editorData.isInFuction()) {
|
||||
if (event.isShiftClick()) {
|
||||
editorData.setMuteSave(true);
|
||||
edit.openOverview(edit.getDataFor(player).getKit(), player, false, null, event.getSlot());
|
||||
editorData.setMuteSave(true);
|
||||
edit.openOverview(edit.getDataFor(player).getKit(), player, false, null, event.getSlot());
|
||||
edit.replaceItem(KitEditor.Action.CHANCE, player, event.getCurrentItem(), event.getSlot());
|
||||
} else if (event.isLeftClick()) {
|
||||
edit.replaceItem(KitEditor.Action.DISPLAY_ITEM, player, event.getCurrentItem(), event.getSlot());
|
||||
} else if (event.getClick() == ClickType.MIDDLE) {
|
||||
edit.replaceItem(KitEditor.Action.DISPLAY_NAME, player, event.getCurrentItem(), event.getSlot());
|
||||
} else if (event.isRightClick()) {
|
||||
edit.replaceItem(KitEditor.Action.DISPLAY_LORE, player, event.getCurrentItem(), event.getSlot());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((event.getSlot() < 10 || event.getSlot() > 43) || event.getSlot() == 17 || event.getSlot() == 36) {
|
||||
if (event.getInventory() != null && event.getInventory().getType() == InventoryType.CHEST) {
|
||||
event.setCancelled(true);
|
||||
|
@ -45,7 +45,7 @@ public class DisplayItemHandler {
|
||||
|
||||
Kit kit = kitBlockData.getKit();
|
||||
|
||||
List<ItemStack> list = kit.getReadableContents(null, false, false);
|
||||
List<ItemStack> list = kit.getReadableContents(null, false, false, false);
|
||||
for (Entity e : location.getChunk().getEntities()) {
|
||||
if (e.getType() != EntityType.DROPPED_ITEM
|
||||
|| e.getLocation().getX() != location.getX()
|
||||
|
@ -206,7 +206,7 @@ public class Kit {
|
||||
|
||||
guititle = Arconix.pl().getApi().format().formatText(guititle);
|
||||
|
||||
List<ItemStack> list = getReadableContents(p, true, false);
|
||||
List<ItemStack> list = getReadableContents(p, true,true, false);
|
||||
|
||||
int amt = 0;
|
||||
for (ItemStack is : list) {
|
||||
@ -415,12 +415,13 @@ public class Kit {
|
||||
}
|
||||
|
||||
|
||||
public List<ItemStack> getReadableContents(Player player, boolean commands, boolean moveable) {
|
||||
public List<ItemStack> getReadableContents(Player player, boolean preview, boolean commands, boolean moveable) {
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
try {
|
||||
for (KitItem item : getContents()) {
|
||||
if ((!item.getSerialized().startsWith("/") && !item.getSerialized().startsWith(plugin.getConfig().getString("Main.Currency Symbol"))) || commands) { //ToDO: I doubt this is correct.
|
||||
ItemStack stack = moveable ? item.getMoveableItem() : item.getItem();
|
||||
if (preview) stack = item.getItemForDisplay();
|
||||
|
||||
ItemStack fin = stack;
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI") && stack.getItemMeta().getLore() != null) {
|
||||
@ -457,7 +458,7 @@ public class Kit {
|
||||
int amt = innerContents.size();
|
||||
int amtToGive = key == null ? amt : key.getAmt();
|
||||
|
||||
AtomicReference<CrateAnimateTask> task = null;
|
||||
CrateAnimateTask task = null;
|
||||
|
||||
int num = 0;
|
||||
for (KitItem item : innerContents) {
|
||||
@ -485,12 +486,12 @@ public class Kit {
|
||||
ItemStack parseStack = ((KitContentItem)item.getContent()).getItemStack();
|
||||
if (parseStack.getType() == Material.AIR) continue;
|
||||
|
||||
|
||||
amtToGive --;
|
||||
|
||||
if (kitAnimation != KitAnimation.NONE) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin,
|
||||
() -> task.set(new CrateAnimateTask(plugin, player, this, item.getItem())), 210 * num);
|
||||
final CrateAnimateTask cTask = new CrateAnimateTask(plugin, player, this, item.getItem());
|
||||
task = cTask;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, cTask::start, 140 * num);
|
||||
} else {
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(item.getItem());
|
||||
for (ItemStack item2 : overfilled.values()) {
|
||||
@ -500,8 +501,8 @@ public class Kit {
|
||||
num ++;
|
||||
}
|
||||
}
|
||||
if (task.get() != null) {
|
||||
task.get().setLast(true);
|
||||
if (task != null) {
|
||||
task.setLast(true);
|
||||
}
|
||||
|
||||
player.updateInventory();
|
||||
|
@ -1,5 +1,5 @@
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
public enum KitAnimation {
|
||||
NONE, CSGO
|
||||
NONE, ROULETTE
|
||||
}
|
||||
|
@ -8,41 +8,43 @@ import com.songoda.ultimatekits.kit.type.KitContentCommand;
|
||||
import com.songoda.ultimatekits.kit.type.KitContentEconomy;
|
||||
import com.songoda.ultimatekits.kit.type.KitContentItem;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class KitItem {
|
||||
|
||||
private final KitContent content;
|
||||
private String displayName, displayLore = null;
|
||||
private Material displayItem = null;
|
||||
private int chance = 0;
|
||||
|
||||
public KitItem(String item) {
|
||||
String item2 = item.replace(String.valueOf(ChatColor.COLOR_CHAR), "");
|
||||
if (item2.substring(0, Math.min(item2.length(), 5)).contains(":")) {
|
||||
this.chance = Integer.parseInt(item2.split(":", 2)[0]);
|
||||
item = item.split(":", 2)[1].trim();
|
||||
public KitItem(String line) {
|
||||
if (line.contains(";")) {
|
||||
line = translateLine(line);
|
||||
}
|
||||
if (item.startsWith(UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol"))) {
|
||||
this.content = new KitContentEconomy(Double.parseDouble(item.substring(1).trim()));
|
||||
} else if (item.startsWith("/")) {
|
||||
this.content = new KitContentCommand(item.substring(1));
|
||||
if (line.startsWith(UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol"))) {
|
||||
this.content = new KitContentEconomy(Double.parseDouble(line.substring(1).trim()));
|
||||
} else if (line.startsWith("/")) {
|
||||
this.content = new KitContentCommand(line.substring(1));
|
||||
} else {
|
||||
this.content = new KitContentItem(Methods.deserializeItemStack(item));
|
||||
this.content = new KitContentItem(Methods.deserializeItemStack(line));
|
||||
}
|
||||
}
|
||||
|
||||
public KitItem(ItemStack item) {
|
||||
ItemStack itemStack = item.clone();
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta.getDisplayName().contains(":")) {
|
||||
String[] split = meta.getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "").split(":", 2);
|
||||
if (AMath.isInt(split[0])) {
|
||||
this.chance = Integer.parseInt(split[0]);
|
||||
meta.setDisplayName(split[1].contains("aqf") ? null : meta.getDisplayName().split(":", 2)[1]);
|
||||
if (meta.getDisplayName().contains(";")) {
|
||||
translateLine(meta.getDisplayName());
|
||||
String[] split = meta.getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "").split(";", 2);
|
||||
meta.setDisplayName(split[1].contains("faqe") ? null : meta.getDisplayName().split(";", 2)[1]);
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
String name = meta.hasDisplayName() ? meta.getDisplayName() : "";
|
||||
|
||||
if (name.startsWith(UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol"))) {
|
||||
@ -54,13 +56,59 @@ public class KitItem {
|
||||
}
|
||||
}
|
||||
|
||||
private String translateLine(String line) {
|
||||
String[] lineSplit = line.trim().split(";", 2);
|
||||
String[] kitOptions = lineSplit[0].replace(String.valueOf(ChatColor.COLOR_CHAR), "").split(" ");
|
||||
|
||||
for (String s : kitOptions) {
|
||||
if (s.equals("")) continue;
|
||||
String[] sSplit = s.split(":", 2);
|
||||
String option = sSplit[0].toLowerCase();
|
||||
String value = sSplit[1].trim();
|
||||
|
||||
switch(option) {
|
||||
case "chance":
|
||||
chance = Integer.parseInt(value);
|
||||
break;
|
||||
case "display-item":
|
||||
displayItem = Material.valueOf(value);
|
||||
break;
|
||||
case "display-lore":
|
||||
displayLore = value.replace("_", " ");
|
||||
break;
|
||||
case "display-name":
|
||||
displayName = value.replace("_", " ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return lineSplit[1];
|
||||
}
|
||||
|
||||
private String compileOptions() {
|
||||
String line = "";
|
||||
if (chance != 0) {
|
||||
line += "chance:" + chance;
|
||||
}
|
||||
if (displayItem != null) {
|
||||
line += " display-item:" + displayItem;
|
||||
}
|
||||
if (displayName != null) {
|
||||
line += " display-name:" + displayName;
|
||||
}
|
||||
if (displayLore != null) {
|
||||
line += " display-lore:" + displayLore;
|
||||
}
|
||||
line.trim();
|
||||
return line;
|
||||
}
|
||||
|
||||
public KitContent getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public String getSerialized() {
|
||||
if (chance == 0) return this.content.getSerialized();
|
||||
return chance + ":" + this.content.getSerialized();
|
||||
if (chance == 0 && displayItem == null && displayName == null && displayLore == null) return this.content.getSerialized();
|
||||
return compileOptions() + ";" + this.content.getSerialized();
|
||||
}
|
||||
|
||||
public int getChance() {
|
||||
@ -71,6 +119,30 @@ public class KitItem {
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
public Material getDisplayItem() {
|
||||
return displayItem;
|
||||
}
|
||||
|
||||
public void setDisplayItem(Material displayItem) {
|
||||
this.displayItem = displayItem;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getDisplayLore() {
|
||||
return displayLore;
|
||||
}
|
||||
|
||||
public void setDisplayLore(String displayLore) {
|
||||
this.displayLore = displayLore;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return content.getItemForDisplay();
|
||||
}
|
||||
@ -78,17 +150,39 @@ public class KitItem {
|
||||
public ItemStack getMoveableItem() {
|
||||
ItemStack item = content.getItemForDisplay();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (chance != 0) meta.setDisplayName(meta.hasDisplayName() ? TextComponent.convertToInvisibleString(chance + ":") + meta.getDisplayName() : TextComponent.convertToInvisibleString(chance + ":aqf") + item.getType().name().replace("_", " "));
|
||||
if (chance != 0 || displayItem != null || displayName != null || displayLore != null) {
|
||||
meta.setDisplayName(meta.hasDisplayName() ? TextComponent.convertToInvisibleString(compileOptions() + ";") + meta.getDisplayName() : TextComponent.convertToInvisibleString(compileOptions() + ";faqe") + item.getType().name().replace("_", " "));
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public ItemStack getItemForDisplay() {
|
||||
ItemStack item = content.getItemForDisplay();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (displayItem != null) {
|
||||
item.setType(displayItem);
|
||||
}
|
||||
if (displayName != null) {
|
||||
meta.setDisplayName(TextComponent.formatText(displayName));
|
||||
}
|
||||
if (displayLore != null) {
|
||||
meta.setLore(Arrays.asList(TextComponent.formatText(displayLore)));
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KitItem:{"
|
||||
+ "Item:\"" + content.getSerialized() + "\","
|
||||
+ "Chance:" + chance
|
||||
+ "Chance:" + chance + "\","
|
||||
+ "Display Item:" + displayItem + "\","
|
||||
+ "Display Name:" + displayName + "\","
|
||||
+ "Display Lore:" + displayLore
|
||||
+ "}";
|
||||
}
|
||||
|
||||
|
@ -52,14 +52,16 @@ public class CrateAnimateTask extends BukkitRunnable {
|
||||
this.items.addLast(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
instance = this;
|
||||
public void start() {
|
||||
if (instance == null) instance = this;
|
||||
instance.runTaskTimer(plugin, 0, 3);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
||||
slow = true;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> finish = true, 20);
|
||||
}, 130);
|
||||
}, 60);
|
||||
}
|
||||
|
||||
private int num = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user