Skip to content

Commit

Permalink
Điều chỉnh XMaterial (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
amadeusmz authored May 22, 2024
1 parent bbed6e0 commit 48ba4ba
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 2,472 deletions.
5 changes: 3 additions & 2 deletions minevnlib-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ repositories {

dependencies {
compileOnly(project(":minevnlib-master"))
compileOnly("com.destroystokyo.paper:paper-api:1.12.2-R0.1-SNAPSHOT")
}
compileOnly("com.destroystokyo.paper:paper-api:1.13.2-R0.1-SNAPSHOT")
implementation("com.github.cryptomorin:XSeries:10.0.0") { isTransitive = false }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class ConfiguredUI(
private val plugin: JavaPlugin,
) : GuiInventory(
getConfig(configPath, plugin).getInt("rows") * 9,
getConfig(configPath, plugin).getString("name").color()
getConfig(configPath, plugin).getString("name")?.color()
) {
companion object {
private val configList = mutableMapOf<Plugin, MutableMap<String, YamlConfiguration>>()
Expand Down
33 changes: 18 additions & 15 deletions minevnlib-bukkit/src/main/java/net/minevn/guiapi/GuiIcon.kt
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
package net.minevn.guiapi

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

class GuiIcon(
var iconType: Material,
var iconItem: ItemStack,
var iconData: Short,
var name: String,
var lore: List<String>,
var glow: Boolean,
) {
fun toItemStack() = ItemStack(iconType, 1, iconData).apply {
val meta = itemMeta
meta.displayName = name
meta.lore = this@GuiIcon.lore
if (glow) {
meta.addEnchant(Enchantment.DURABILITY, 1, true)
fun toItemStack() = iconItem.clone().apply {
if (iconData > 0) {
durability = iconData
}
itemMeta = itemMeta.apply {
setDisplayName(name)
lore = this@GuiIcon.lore
if (glow) {
addEnchant(Enchantment.DURABILITY, 1, true)
}
addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES)
}
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES)
itemMeta = meta
}

fun toGuiItemStack(action: ClickAction?) = GuiItemStack(toItemStack()).apply { onClick(action) }

fun toGuiItemStack() = toGuiItemStack(null)

fun clone() = GuiIcon(iconType, iconData, name, lore, glow)
fun clone() = GuiIcon(iconItem, iconData, name, lore, glow)

companion object {
@JvmStatic
fun fromConfig(configSection: ConfigurationSection): GuiIcon {
val iconType = XMaterial.matchXMaterial(configSection.getString("icon.type", "STONE"))
val iconItem = XMaterial.matchXMaterial(configSection.getString("icon.type", "STONE")!!)
.orElse(XMaterial.STONE)
.parseMaterial()!!
.parseItem()!!
val iconData = configSection.getInt("icon.data", 0).toShort()
val name = configSection.getString("name", "&f").color()
val name = configSection.getString("name", "&f")!!.color()
val lore = configSection.getStringList("lore").color()
val glow = configSection.getBoolean("glow")
return GuiIcon(iconType, iconData, name, lore, glow)
return GuiIcon(iconItem, iconData, name, lore, glow)
}

fun ConfigurationSection.getGuiIcon(path: String) = fromConfig(getConfigurationSection(path)!!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.minevn.guiapi;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -60,7 +61,7 @@ public GuiItemStack(Material material, byte data, int amount, boolean glow, Stri
item = new ItemStack(material, amount, data);
ItemMeta im = item.getItemMeta();
im.setDisplayName(name);
if (lores != null && lores.size() > 0)
if (lores != null && !lores.isEmpty())
im.setLore(lores);
if (glow) {
im.addEnchant(Enchantment.DURABILITY, 1, true);
Expand All @@ -77,7 +78,7 @@ public GuiItemStack(Material material, short data, int amount, boolean glow, Str
item = new ItemStack(material, amount, data);
ItemMeta im = item.getItemMeta();
im.setDisplayName(name);
if (lores != null && lores.size() > 0) {
if (lores != null && !lores.isEmpty()) {
im.setLore(lores);
}
if (glow) {
Expand Down

This file was deleted.

Loading

0 comments on commit 48ba4ba

Please sign in to comment.