diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 06bd316..e0e9593 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,14 +2,15 @@ # https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format [versions] -com-comphenix-protocol-protocollib = "5.0.0" -com-github-cryptomorin-xseries = "9.4.0" +com-comphenix-protocol-protocollib = "5.1.0" +com-github-cryptomorin-xseries = "11.3.0" com-zaxxer-hikaricp = "4.0.3" me-clip-placeholderapi = "2.11.6" org-jetbrains-annotations = "23.0.0" org-spigotmc-spigot-api = "1.21-R0.1-SNAPSHOT" org-xerial-sqlite-jdbc = "3.41.2.2" org-mariadb-jdbc-mariadb-java-client = "3.1.2" +canvas = "1.7.0-SNAPSHOT" [libraries] @@ -20,4 +21,5 @@ me-clip-placeholderapi = { module = "me.clip:placeholderapi", version.ref = "me- org-jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "org-jetbrains-annotations" } org-spigotmc-spigot-api = { module = "org.spigotmc:spigot-api", version.ref = "org-spigotmc-spigot-api" } org-xerial-sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version.ref = "org-xerial-sqlite-jdbc" } -org-mariadb-jdbc-mariadb-java-client = { module = "org.mariadb.jdbc:mariadb-java-client", version.ref = "org-mariadb-jdbc-mariadb-java-client" } \ No newline at end of file +org-mariadb-jdbc-mariadb-java-client = { module = "org.mariadb.jdbc:mariadb-java-client", version.ref = "org-mariadb-jdbc-mariadb-java-client" } +org-ipvp-canvas = { module = "org.ipvp:canvas", version.ref = "canvas"} \ No newline at end of file diff --git a/src/main/java/dev/tylerm/khs/configuration/Items.java b/src/main/java/dev/tylerm/khs/configuration/Items.java index 0894ab2..e5b36f8 100644 --- a/src/main/java/dev/tylerm/khs/configuration/Items.java +++ b/src/main/java/dev/tylerm/khs/configuration/Items.java @@ -1,11 +1,8 @@ package dev.tylerm.khs.configuration; -import com.cryptomorin.xseries.XItemStack; -import dev.tylerm.khs.Main; +import dev.tylerm.khs.util.ItemUtil; import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -42,13 +39,13 @@ public static void loadItems() { SEEKER_ITEMS.add(null); continue; } - ItemStack item = createItem(section); + ItemStack item = ItemUtil.createItem(section); SEEKER_ITEMS.add(item); } ConfigurationSection SeekerHelmet = SeekerItems.getConfigurationSection("helmet"); if (SeekerHelmet != null) { - ItemStack item = createItem(SeekerHelmet); + ItemStack item = ItemUtil.createItem(SeekerHelmet); if (item != null) { SEEKER_HELM = item; } @@ -56,7 +53,7 @@ public static void loadItems() { ConfigurationSection SeekerChestplate = SeekerItems.getConfigurationSection("chestplate"); if (SeekerChestplate != null) { - ItemStack item = createItem(SeekerChestplate); + ItemStack item = ItemUtil.createItem(SeekerChestplate); if (item != null) { SEEKER_CHEST = item; } @@ -64,7 +61,7 @@ public static void loadItems() { ConfigurationSection SeekerLeggings = SeekerItems.getConfigurationSection("leggings"); if (SeekerLeggings != null) { - ItemStack item = createItem(SeekerLeggings); + ItemStack item = ItemUtil.createItem(SeekerLeggings); if (item != null) { SEEKER_LEGS = item; } @@ -72,7 +69,7 @@ public static void loadItems() { ConfigurationSection SeekerBoots = SeekerItems.getConfigurationSection("boots"); if (SeekerBoots != null) { - ItemStack item = createItem(SeekerBoots); + ItemStack item = ItemUtil.createItem(SeekerBoots); if (item != null) { SEEKER_BOOTS = item; } @@ -92,13 +89,13 @@ public static void loadItems() { HIDER_ITEMS.add(null); continue; } - ItemStack item = createItem(section); + ItemStack item = ItemUtil.createItem(section); HIDER_ITEMS.add(item); } ConfigurationSection HiderHelmet = HiderItems.getConfigurationSection("helmet"); if (HiderHelmet != null) { - ItemStack item = createItem(HiderHelmet); + ItemStack item = ItemUtil.createItem(HiderHelmet); if (item != null) { HIDER_HELM = item; } @@ -106,7 +103,7 @@ public static void loadItems() { ConfigurationSection HiderChestplate = HiderItems.getConfigurationSection("chestplate"); if (HiderChestplate != null) { - ItemStack item = createItem(HiderChestplate); + ItemStack item = ItemUtil.createItem(HiderChestplate); if (item != null) { HIDER_CHEST = item; } @@ -114,7 +111,7 @@ public static void loadItems() { ConfigurationSection HiderLeggings = HiderItems.getConfigurationSection("leggings"); if (HiderLeggings != null) { - ItemStack item = createItem(HiderLeggings); + ItemStack item = ItemUtil.createItem(HiderLeggings); if (item != null) { HIDER_LEGS = item; } @@ -122,7 +119,7 @@ public static void loadItems() { ConfigurationSection HiderBoots = HiderItems.getConfigurationSection("boots"); if (HiderBoots != null) { - ItemStack item = createItem(HiderBoots); + ItemStack item = ItemUtil.createItem(HiderBoots); if (item != null) { HIDER_BOOTS = item; } @@ -152,36 +149,6 @@ public static void loadItems() { } } - private static ItemStack createItem(ConfigurationSection item) { - ConfigurationSection config = new YamlConfiguration().createSection("temp"); - String material = item.getString("material").toUpperCase(); - boolean splash = false; - if (material.contains("POTION")) { - config.set("level", 1); - } - if (material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION")) { - material = "POTION"; - splash = true; - } - config.set("name", item.getString("name")); - config.set("material", material); - config.set("enchants", item.getConfigurationSection("enchantments")); - config.set("unbreakable", item.getBoolean("unbreakable")); - if (item.contains("model-data")) { - config.set("model-data", item.getInt("model-data")); - } - if (item.isSet("lore")) - config.set("lore", item.getStringList("lore")); - if (material.equalsIgnoreCase("POTION") || material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION")) - config.set("base-effect", String.format("%s,%s,%s", item.getString("type"), false, splash)); - ItemStack stack = XItemStack.deserialize(config); - int amt = item.getInt("amount"); - if (amt < 1) amt = 1; - stack.setAmount(amt); - if (stack.getData().getItemType() == Material.AIR) return null; - return stack; - } - private static PotionEffect getPotionEffect(ConfigurationSection item) { String type = item.getString("type"); if (type == null) return null; diff --git a/src/main/java/dev/tylerm/khs/util/ItemUtil.java b/src/main/java/dev/tylerm/khs/util/ItemUtil.java new file mode 100644 index 0000000..1307ebe --- /dev/null +++ b/src/main/java/dev/tylerm/khs/util/ItemUtil.java @@ -0,0 +1,43 @@ +package dev.tylerm.khs.util; + +import com.cryptomorin.xseries.XItemStack; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.inventory.ItemStack; + +public class ItemUtil{ + public static ItemStack createItem(ConfigurationSection item) { + ConfigurationSection config = new YamlConfiguration().createSection("temp"); + String material = item.getString("material").toUpperCase(); + boolean splash = false; + if (material.contains("POTION")) { + if(!item.contains("potionLevel")){ + config.set("level", 1); + }else{ + config.set("level", item.getInt("potionLevel")); + } + } + if (material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION")) { + material = "POTION"; + splash = true; + } + config.set("name", item.getString("name")); + config.set("material", material); + config.set("enchants", item.getConfigurationSection("enchantments")); + config.set("unbreakable", item.getBoolean("unbreakable")); + if (item.contains("model-data")) { + config.set("model-data", item.getInt("model-data")); + } + if (item.isSet("lore")) + config.set("lore", item.getStringList("lore")); + if (material.equalsIgnoreCase("POTION") || material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION")) + config.set("base-effect", String.format("%s,%s,%s", item.getString("type"), false, splash)); + ItemStack stack = XItemStack.deserialize(config); + int amt = item.getInt("amount"); + if (amt < 1) amt = 1; + stack.setAmount(amt); + if (stack.getData().getItemType() == Material.AIR) return null; + return stack; + } +} diff --git a/src/main/java/dev/tylerm/khs/util/item/ItemStackBuilder.java b/src/main/java/dev/tylerm/khs/util/item/ItemStackBuilder.java new file mode 100644 index 0000000..b213727 --- /dev/null +++ b/src/main/java/dev/tylerm/khs/util/item/ItemStackBuilder.java @@ -0,0 +1,112 @@ +/* + * + * AstralFlow - The plugin enriches bukkit servers + * Copyright (C) 2022 The Inlined Lambdas and Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package dev.tylerm.khs.util.item; + +import dev.tylerm.khs.item.CustomItems; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.persistence.PersistentDataType; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static java.util.Objects.requireNonNull; + +public final class ItemStackBuilder { + private Material material = Material.AIR; + private List lore = new ArrayList<>(); + private int customModelId; + private String displayName; + private List itemFlags = new ArrayList<>(); + private int customItemId=-1; + + private boolean unbreakable; + + public ItemStackBuilder unbreakable() { + this.unbreakable = true; + return this; + } + + public ItemStackBuilder material(Material material) { + requireNonNull(material, "Material cannot be null"); + if(material.isAir()){ + throw new IllegalArgumentException("Material cannot be AIR"); + } + this.material = material; + return this; + } + + public ItemStackBuilder lore(String... strings) { + requireNonNull(strings, "Lore cannot be null"); + for (String string : strings) { + lore.add(string.replaceAll("&", ChatColor.COLOR_CHAR + "")); + } + return this; + } + + public ItemStackBuilder customItemKey(int key){ + customItemId = key;; + return this; + } + + public ItemStackBuilder customModelId(int customModelId) { + if(customModelId < 0){ + throw new IllegalArgumentException("Custom model id cannot be negative"); + } + this.customModelId = customModelId; + return this; + } + + public ItemStackBuilder displayName(String displayName) { + requireNonNull(displayName, "Display name cannot be null"); + this.displayName = displayName.replaceAll("&", ChatColor.COLOR_CHAR + ""); + return this; + } + + public ItemStackBuilder itemFlags(ItemFlag... flags) { + requireNonNull(flags, "Flags cannot be null"); + itemFlags.addAll(Arrays.asList(flags)); + return this; + } + + + public ItemStack build() { + if (material == Material.AIR) { + throw new IllegalArgumentException("Material cannot be AIR"); + } + var item = new ItemStack(material); + var meta = item.getItemMeta(); + if (customModelId != 0 || displayName != null || !lore.isEmpty() || unbreakable || !itemFlags.isEmpty() || customItemId != 0) { + meta.setCustomModelData(customModelId); + meta.setLore(lore); + meta.setDisplayName(displayName); + meta.setUnbreakable(unbreakable); + meta.addItemFlags(itemFlags.toArray(new ItemFlag[0])); + } + meta.getPersistentDataContainer().set(CustomItems.CUSTOM_ITEM, PersistentDataType.INTEGER, customItemId); + item.setItemMeta(meta); + return item; + } +} \ No newline at end of file diff --git a/src/main/java/dev/tylerm/khs/util/item/ItemStacks.java b/src/main/java/dev/tylerm/khs/util/item/ItemStacks.java new file mode 100644 index 0000000..783a0db --- /dev/null +++ b/src/main/java/dev/tylerm/khs/util/item/ItemStacks.java @@ -0,0 +1,73 @@ +/* + * + * AstralFlow - The plugin enriches bukkit servers + * Copyright (C) 2022 The Inlined Lambdas and Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package dev.tylerm.khs.util.item; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import static java.util.Objects.requireNonNull; + +/** + * Util for working with ItemStacks. + */ +@ApiStatus.AvailableSince("0.1.0") +public final class ItemStacks { + /** + * Create an itemstack by a builder pattern. + * + * @param material The material of the itemstack. + * @return The itemstack. + */ + public static ItemStackBuilder builder(Material material) { + return new ItemStackBuilder().material(material); + } + + /** + * A quicker way to create sample itemstacks. + * + * @param material material of the item + * @param name display name of the item + * @param lores lore of the item + * @return itemstack + */ + @NotNull + public static ItemStack of(Material material, String name, String... lores) { + requireNonNull(material); + if (material.isAir()) throw new IllegalArgumentException("Material cannot be air"); + requireNonNull(name); + return builder(material).displayName(name).lore(lores == null ? new String[0] : lores).build(); + } + + public static ItemStack consumeOrNull(ItemStack itemStack, int amount) { + if (itemStack.getAmount() < amount) { + return null; + } + if (itemStack.getAmount() == amount) { + return new ItemStack(Material.AIR); + } + var item = itemStack.clone(); + item.setAmount(item.getAmount() - amount); + return item; + } +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index bf5d2a9..50c4af9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ main: dev.tylerm.khs.Main version: 1.7.6 author: KenshinEto load: STARTUP -api-version: 1.21 +api-version: "1.13" depend: [ProtocolLib] softdepend: [PlaceholderAPI] commands: