Skip to content

Commit

Permalink
Remove unneeded nbt checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Mar 3, 2024
1 parent b1b0f99 commit 93ed892
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 35 deletions.
Expand Up @@ -16,7 +16,6 @@
import com.badbones69.crazycrates.tasks.crates.other.AbstractCrateManager;
import org.jetbrains.annotations.NotNull;
import com.badbones69.crazycrates.common.crates.CrateHologram;
import de.tr7zw.changeme.nbtapi.NBTItem;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
Expand Down Expand Up @@ -576,16 +575,12 @@ public void addEditorItem(String prize, ItemStack item, int chance) {
* @param path the path in the config to set the item at.
*/
private void setItem(ItemStack item, int chance, String path) {
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) this.file.set(path + ".DisplayName", item.getItemMeta().getDisplayName());
if (item.getItemMeta().hasLore()) this.file.set(path + ".Lore", item.getItemMeta().getLore());
}
ItemMeta itemMeta = item.getItemMeta();

NBTItem nbtItem = new NBTItem(item);
if (itemMeta.hasDisplayName()) this.file.set(path + ".DisplayName", item.getItemMeta().getDisplayName());
if (itemMeta.hasLore()) this.file.set(path + ".Lore", item.getItemMeta().getLore());

if (nbtItem.hasNBTData()) {
if (nbtItem.hasTag("Unbreakable") && nbtItem.getBoolean("Unbreakable")) this.file.set(path + ".Unbreakable", true);
}
this.file.set(path + ".Unbreakable", itemMeta.isUnbreakable());

List<String> enchantments = new ArrayList<>();

Expand Down
Expand Up @@ -431,11 +431,11 @@ public ItemStack build() {
if (this.isHash) { // Sauce: https://github.com/deanveloper/SkullCreator
if (this.isURL) {
item = SkullCreator.itemWithUrl(item, this.player);
this.itemMeta = item.getItemMeta();
} else {
item = SkullCreator.itemWithBase64(item, this.player);
this.itemMeta = item.getItemMeta();
}

this.itemMeta = item.getItemMeta();
}
}

Expand Down Expand Up @@ -501,6 +501,8 @@ public ItemStack build() {
shieldMeta.setBlockState(banner);
}

this.itemMeta.setUnbreakable(this.unbreakable);

if (this.useCustomModelData) this.itemMeta.setCustomModelData(this.customModelData);

this.itemFlags.forEach(this.itemMeta::addItemFlags);
Expand All @@ -511,12 +513,6 @@ public ItemStack build() {

NBTItem nbt = new NBTItem(item);

if (this.isHead && !this.isHash) nbt.setString("SkullOwner", this.player);

if (this.isMobEgg) {
if (this.entityType != null) nbt.addCompound("EntityTag").setString("id", "minecraft:" + this.entityType.name());
}

if (!this.crateName.isEmpty()) nbt.setString("CrazyCrates-Crate", this.crateName);

return nbt.getItem();
Expand Down Expand Up @@ -1064,36 +1060,25 @@ public ItemBuilder setGlow(boolean glow) {
public static ItemBuilder convertItemStack(ItemStack item) {
ItemBuilder itemBuilder = new ItemBuilder().setReferenceItem(item).setAmount(item.getAmount()).setEnchantments(new HashMap<>(item.getEnchantments()));

if (item.hasItemMeta() && item.getItemMeta() != null) {
ItemMeta itemMeta = item.getItemMeta();

if (itemMeta.hasDisplayName()) itemBuilder.setName(itemMeta.getDisplayName());
if (itemMeta.hasLore()) itemBuilder.setLore(itemMeta.getLore());

NBTItem nbt = new NBTItem(item);

if (nbt.hasTag("Unbreakable")) itemBuilder.setUnbreakable(nbt.getBoolean("Unbreakable"));

if (itemMeta instanceof org.bukkit.inventory.meta.Damageable) itemBuilder.setDamage(((org.bukkit.inventory.meta.Damageable) itemMeta).getDamage());
}

return itemBuilder;
return set(item, itemBuilder);
}

public static ItemBuilder convertItemStack(ItemStack item, Player player) {
ItemBuilder itemBuilder = new ItemBuilder().setTarget(player).setReferenceItem(item).setAmount(item.getAmount()).setEnchantments(new HashMap<>(item.getEnchantments()));

return set(item, itemBuilder);
}

private static ItemBuilder set(ItemStack item, ItemBuilder itemBuilder) {
if (item.hasItemMeta() && item.getItemMeta() != null) {
ItemMeta itemMeta = item.getItemMeta();

if (itemMeta.hasDisplayName()) itemBuilder.setName(itemMeta.getDisplayName());
if (itemMeta.hasLore()) itemBuilder.setLore(itemMeta.getLore());

NBTItem nbt = new NBTItem(item);

if (nbt.hasTag("Unbreakable")) itemBuilder.setUnbreakable(nbt.getBoolean("Unbreakable"));
itemMeta.setUnbreakable(itemMeta.isUnbreakable());

if (itemMeta instanceof org.bukkit.inventory.meta.Damageable) itemBuilder.setDamage(((org.bukkit.inventory.meta.Damageable) itemMeta).getDamage());
if (itemMeta instanceof Damageable) itemBuilder.setDamage(((Damageable) itemMeta).getDamage());
}

return itemBuilder;
Expand Down

0 comments on commit 93ed892

Please sign in to comment.