Skip to content

Commit

Permalink
điều chỉnh logic itemflags
Browse files Browse the repository at this point in the history
  • Loading branch information
amadeusmz committed Feb 3, 2025
1 parent 695174f commit bd4fa02
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 3 additions & 3 deletions minevnlib-bukkit/src/main/java/net/minevn/guiapi/GuiIcon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package net.minevn.guiapi

import com.cryptomorin.xseries.XMaterial
import net.minevn.libs.bukkit.color
import net.minevn.libs.bukkit.hideAll
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.enchantments.Enchantment
import org.bukkit.inventory.ItemFlag
import org.bukkit.inventory.ItemStack

class GuiIcon(
Expand All @@ -24,7 +24,7 @@ class GuiIcon(
if (glow) {
addEnchant(Enchantment.DURABILITY, 1, true)
}
addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES)
hideAll()
}
}

Expand All @@ -49,4 +49,4 @@ class GuiIcon(

fun ConfigurationSection.getGuiIcon(path: String) = fromConfig(getConfigurationSection(path)!!)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public GuiItemStack(Material material, byte data, int amount, boolean glow, Stri
if (glow) {
im.addEnchant(Enchantment.DURABILITY, 1, true);
}
im.addItemFlags(ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
hideAll(im);
item.setItemMeta(im);
}

Expand All @@ -85,7 +85,7 @@ public GuiItemStack(Material material, short data, int amount, boolean glow, Str
im.addEnchant(Enchantment.DURABILITY, 1, true);
}
im.setUnbreakable(true);
im.addItemFlags(ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
hideAll(im);
item.setItemMeta(im);
}

Expand All @@ -108,7 +108,7 @@ public GuiItemStack(ItemStack item, String name, String... lores) {
if (lores != null && lores.length > 0)
im.setLore(Arrays.asList(lores));
im.setUnbreakable(true);
im.addItemFlags(ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ATTRIBUTES);
hideAll(im);
item.setItemMeta(im);
}

Expand All @@ -128,4 +128,10 @@ public GuiItemStack onClick(ClickAction action) {
public ItemStack getItem() {
return item;
}

private static void hideAll(ItemMeta itemMeta) {
for (ItemFlag flag : ItemFlag.values()) {
itemMeta.addItemFlags(flag);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Location
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemFlag
import org.bukkit.inventory.meta.ItemMeta

fun List<String>.color() = map { it.color() }

Expand Down Expand Up @@ -74,3 +76,7 @@ fun String.asLocation() = split(",").let {
val pitch = it[5].toFloat()
Location(world, x, y, z, yaw, pitch)
}

fun ItemMeta.hideAll() {
ItemFlag.entries.forEach { addItemFlags(it) }
}

0 comments on commit bd4fa02

Please sign in to comment.