Moved to NBT from Invisible Strings.
This commit is contained in:
parent
8c9f756e6b
commit
d931173733
|
@ -338,7 +338,8 @@ public class KitEditorGui extends DoubleGui {
|
|||
ItemMeta meta = itemStack.getItemMeta();
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : meta.getLore()) {
|
||||
if (TextUtils.convertFromInvisibleString(line).equals("----")) break;
|
||||
if (line.contains("Moveable")) continue;
|
||||
if (line.equals(TextUtils.formatText("&8----"))) break;
|
||||
newLore.add(line);
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
|
@ -421,7 +422,7 @@ public class KitEditorGui extends DoubleGui {
|
|||
|
||||
if (meta.hasLore()) itemLore = meta.getLore();
|
||||
else itemLore = new ArrayList<>();
|
||||
itemLore.add(TextUtils.convertToInvisibleLoreString("----"));
|
||||
itemLore.add(TextUtils.formatText("&8----"));
|
||||
itemLore.add(ChatColor.GRAY.toString() + plugin.getLocale().getMessage("general.type.chance").getMessage().replaceFirst("^" + ChatColor.RESET.toString(), "")
|
||||
+ ": " + ChatColor.GOLD.toString() + item.getChance() + "%"); //TODO use a placeholder message in locales
|
||||
if (isInFunction) {
|
||||
|
|
|
@ -144,8 +144,7 @@ public class KitSelectorGui extends Gui {
|
|||
.processPlaceholder("kit", TextUtils.formatText(kitItem, true)).getMessage();
|
||||
|
||||
setButton(row, col, GuiUtils.createButtonItem(
|
||||
kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.ENCHANTED_BOOK,
|
||||
TextUtils.convertToInvisibleString(kitItem + ":") + kitTitle,
|
||||
kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.ENCHANTED_BOOK,kitTitle,
|
||||
getKitLore(kit)),
|
||||
event -> {
|
||||
if (event.clickType == ClickType.MIDDLE && player.hasPermission("ultimatekits.admin")) {
|
||||
|
|
|
@ -118,7 +118,7 @@ public class PreviewKitGui extends Gui {
|
|||
|| (Settings.DONT_PREVIEW_COMMANDS.getBoolean()
|
||||
&& item.getType() == Material.PAPER
|
||||
&& item.getItemMeta().hasDisplayName()
|
||||
&& item.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("general.type.command")))) {
|
||||
&& item.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("general.type.command").getMessage()))) {
|
||||
setItem(row, col, AIR);
|
||||
} else if (item.getAmount() <= 64) {
|
||||
// display item
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.songoda.ultimatekits.handlers;
|
||||
|
||||
import com.songoda.core.nms.NmsManager;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
|
@ -15,6 +17,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -62,19 +65,24 @@ public class DisplayItemHandler {
|
|||
|
||||
if (!kitBlockData.isDisplayingItems()) e.remove();
|
||||
|
||||
int inum = Integer.parseInt(i.getItemStack().getItemMeta().getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "")) + 1;
|
||||
|
||||
NBTItem nbtItem = NmsManager.getNbt().of(i.getItemStack());
|
||||
int inum = nbtItem.has("num") ? nbtItem.getNBTObject("num").asInt() + 1 : 0;
|
||||
|
||||
if (inum > list.size()) inum = 1;
|
||||
|
||||
ItemStack is = list.get(inum - 1);
|
||||
ItemStack is = list.get(inum);
|
||||
if (kitBlockData.isItemOverride()) {
|
||||
if (kit.getDisplayItem() != null)
|
||||
is = kit.getDisplayItem().getItem();
|
||||
}
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
is.setAmount(1);
|
||||
meta.setDisplayName(TextUtils.convertToInvisibleString(Integer.toString(inum)));
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
meta.setDisplayName(null);
|
||||
is.setItemMeta(meta);
|
||||
i.setItemStack(is);
|
||||
nbtItem = NmsManager.getNbt().of(is);
|
||||
nbtItem.set("num", inum);
|
||||
i.setItemStack(nbtItem.finish());
|
||||
i.setPickupDelay(9999);
|
||||
return;
|
||||
}
|
||||
|
@ -83,13 +91,18 @@ public class DisplayItemHandler {
|
|||
ItemStack is = list.get(0);
|
||||
is.setAmount(1);
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
meta.setDisplayName(TextUtils.convertFromInvisibleString("0"));
|
||||
meta.setLore(Collections.singletonList("Display Item"));
|
||||
is.setItemMeta(meta);
|
||||
|
||||
NBTItem nbtItem = NmsManager.getNbt().of(is);
|
||||
nbtItem.set("num", 0);
|
||||
|
||||
Bukkit.getScheduler().runTask(instance, () -> {
|
||||
Item item = location.getWorld().dropItem(location.add(0, 1, 0), list.get(0));
|
||||
Item item = location.getWorld().dropItem(location.add(0, 1, 0), nbtItem.finish());
|
||||
Vector vec = new Vector(0, 0, 0);
|
||||
item.setVelocity(vec);
|
||||
item.setPickupDelay(9999);
|
||||
item.setCustomName(null);
|
||||
item.setMetadata("US_EXEMPT", new FixedMetadataValue(UltimateKits.getInstance(), true));
|
||||
item.setMetadata("displayItem", new FixedMetadataValue(UltimateKits.getInstance(), true));
|
||||
item.setMetadata("betterdrops_ignore", new FixedMetadataValue(UltimateKits.getInstance(), true));
|
||||
|
|
|
@ -217,7 +217,8 @@ public class Kit {
|
|||
ItemMeta meta = is.getItemMeta();
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : meta.getLore()) {
|
||||
if (TextUtils.convertFromInvisibleString(line).equals("----")) break;
|
||||
if (line.contains("Moveable")) continue;
|
||||
if (line.equals(TextUtils.formatText("&8----"))) break;
|
||||
newLore.add(line);
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
import com.songoda.core.nms.NmsManager;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.type.KitContent;
|
||||
|
@ -13,9 +15,7 @@ import org.bukkit.Material;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.*;
|
||||
|
||||
public class KitItem {
|
||||
|
||||
|
@ -32,26 +32,13 @@ public class KitItem {
|
|||
}
|
||||
|
||||
public KitItem(ItemStack item, String line) {
|
||||
ItemStack itemStack = item.clone();
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (itemStack.hasItemMeta() && meta.hasDisplayName() && meta.getDisplayName().contains(";")) {
|
||||
translateLine(meta.getDisplayName());
|
||||
}
|
||||
translateTags(item);
|
||||
processContent(line, null);
|
||||
}
|
||||
|
||||
public KitItem(ItemStack item) {
|
||||
ItemStack itemStack = item.clone();
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (itemStack.hasItemMeta() && meta.hasDisplayName() && meta.getDisplayName().contains(";")) {
|
||||
String translated = translateLine(meta.getDisplayName()).replace(TextUtils.convertToInvisibleString("faqe"), "");
|
||||
if (translated.equalsIgnoreCase(WordUtils.capitalize(item.getType().toString().toLowerCase().replace("_", " "))))
|
||||
meta.setDisplayName(null);
|
||||
else
|
||||
meta.setDisplayName(translated);
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
processContent(null, itemStack);
|
||||
translateTags(item);
|
||||
processContent(null, item.clone());
|
||||
}
|
||||
|
||||
private void processContent(String line, ItemStack item) {
|
||||
|
@ -65,6 +52,18 @@ public class KitItem {
|
|||
}
|
||||
}
|
||||
|
||||
private void translateTags(ItemStack item) {
|
||||
NBTItem nbtItem = NmsManager.getNbt().of(item);
|
||||
if (nbtItem.has("chance"))
|
||||
chance = nbtItem.getNBTObject("chance").asDouble();
|
||||
if (nbtItem.has("display-item"))
|
||||
displayItem = Material.valueOf(nbtItem.getNBTObject("display-item").asString());
|
||||
if (nbtItem.has("display-name"))
|
||||
displayName = nbtItem.getNBTObject("display-name").asString();
|
||||
if (nbtItem.has("display-lore"))
|
||||
displayLore = nbtItem.getNBTObject("display-lore").asString();
|
||||
}
|
||||
|
||||
private String translateLine(String line) {
|
||||
String[] lineSplit = line.trim().split(";", 2);
|
||||
String[] kitOptions = lineSplit[0].replace(String.valueOf(ChatColor.COLOR_CHAR), "").split("~");
|
||||
|
@ -94,7 +93,19 @@ public class KitItem {
|
|||
return lineSplit[1];
|
||||
}
|
||||
|
||||
private String compileOptions() {
|
||||
private ItemStack compileOptions(ItemStack item) {
|
||||
NBTItem nbtItem = NmsManager.getNbt().of(item);
|
||||
if (chance != 0)
|
||||
nbtItem.set("chance", chance);
|
||||
if (displayItem != null)
|
||||
nbtItem.set("display-item", displayItem.name());
|
||||
if (displayName != null)
|
||||
nbtItem.set("display-name", displayName);
|
||||
if (displayLore != null)
|
||||
nbtItem.set("display-lore", displayLore);
|
||||
return nbtItem.finish();
|
||||
}
|
||||
private String compileOptionsText() {
|
||||
String line = "";
|
||||
if (chance != 0)
|
||||
line += "chance:" + chance;
|
||||
|
@ -114,7 +125,7 @@ public class KitItem {
|
|||
public String getSerialized() {
|
||||
if (chance == 0 && displayItem == null && displayName == null && displayLore == null)
|
||||
return this.content.getSerialized();
|
||||
return compileOptions() + ";" + this.content.getSerialized();
|
||||
return compileOptionsText() + ";" + this.content.getSerialized();
|
||||
}
|
||||
|
||||
public double getChance() {
|
||||
|
@ -155,17 +166,15 @@ public class KitItem {
|
|||
|
||||
public ItemStack getMoveableItem() {
|
||||
if (content == null) return null;
|
||||
ItemStack item = content.getItemForDisplay();
|
||||
ItemStack item = content.getItemForDisplay().clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (chance != 0 || displayItem != null || displayName != null || displayLore != null) {
|
||||
String capitalizedName = meta.hasDisplayName() ? meta.getDisplayName() :
|
||||
WordUtils.capitalize(item.getType().toString().toLowerCase().replace("_", " "));
|
||||
if (capitalizedName.contains(TextUtils.convertToInvisibleString(";faqe")))
|
||||
capitalizedName = meta.getDisplayName().split(TextUtils.convertToInvisibleString(";faqe"))[1];
|
||||
meta.setDisplayName(TextUtils.convertToInvisibleString(compileOptions() + ";faqe") + capitalizedName);
|
||||
}
|
||||
List<String> lore = meta.hasLore() && meta.getLore().get(0).equals(TextUtils.formatText("&8&oMoveable"))
|
||||
? new ArrayList<>() : new ArrayList<>(Collections.singletonList(TextUtils.formatText("&8&oMoveable")));
|
||||
if (meta.hasLore())
|
||||
lore.addAll(meta.getLore());
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
return compileOptions(item);
|
||||
}
|
||||
|
||||
public ItemStack getItemForDisplay() {
|
||||
|
@ -181,19 +190,18 @@ public class KitItem {
|
|||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName));
|
||||
}
|
||||
if (displayLore != null) {
|
||||
meta.setLore(Arrays.asList(ChatColor.translateAlternateColorCodes('&', displayLore)));
|
||||
meta.setLore(Collections.singletonList(ChatColor.translateAlternateColorCodes('&', displayLore)));
|
||||
}
|
||||
|
||||
if (UltimateKits.getInstance().getConfig().getBoolean("Main.Display Chance In Preview")) {
|
||||
ArrayDeque<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
if (meta.hasLore())
|
||||
lore = new ArrayDeque<>(meta.getLore());
|
||||
} else {
|
||||
else
|
||||
lore = new ArrayDeque<>();
|
||||
}
|
||||
|
||||
if (!lore.isEmpty()) lore.addFirst("");
|
||||
lore.addFirst(ChatColor.GRAY.toString() + UltimateKits.getInstance().getLocale().getMessage("general.type.chance") + ": " + ChatColor.GOLD + (chance == 0 ? 100 : chance) + "%");
|
||||
lore.addFirst(ChatColor.GRAY.toString() + UltimateKits.getInstance().getLocale().getMessage("general.type.chance").getMessage() + ": " + ChatColor.GOLD + (chance == 0 ? 100 : chance) + "%");
|
||||
meta.setLore(new ArrayList<>(lore));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue