From 1fa748215c5cc60b975b300bab9208f04ec3ec91 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Wed, 20 Mar 2024 12:26:42 -0400 Subject: [PATCH] Update itembuilder with custom model data support --- build.gradle.kts | 2 +- buildSrc/build.gradle.kts | 17 +- buildSrc/settings.gradle.kts | 11 +- .../src/main/kotlin/fabric-plugin.gradle.kts | 4 - .../src/main/kotlin/paper-plugin.gradle.kts | 36 +- .../src/main/kotlin/root-plugin.gradle.kts | 66 +- gradle.properties | 4 +- gradle/libs.versions.toml | 57 +- paper/build.gradle.kts | 58 +- paper/run/server.properties | 2 +- .../com/badbones69/crazyauctions/Methods.java | 139 -- .../api/builders/ItemBuilder.java | 1397 +++++++++++++++++ .../crazyauctions/api/enums/ShopType.java | 3 +- .../api/support/PluginSupport.java | 4 +- .../api/support/SkullCreator.java | 189 +++ .../commands/AuctionCommand.java | 8 +- .../controllers/GuiListener.java | 163 +- .../crazyauctions/CrazyAuctionsPaper.java | 28 - .../crazyauctions/platform/PaperServer.java | 17 - paper/src/main/resources/plugin.yml | 8 +- settings.gradle.kts | 49 +- 21 files changed, 1809 insertions(+), 453 deletions(-) create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/api/builders/ItemBuilder.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/api/support/SkullCreator.java delete mode 100644 paper/src/main/java/com/ryderbelserion/crazyauctions/CrazyAuctionsPaper.java delete mode 100644 paper/src/main/java/com/ryderbelserion/crazyauctions/platform/PaperServer.java diff --git a/build.gradle.kts b/build.gradle.kts index 67c43e1..8221632 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ import org.gradle.kotlin.dsl.support.uppercaseFirstChar plugins { - id("root-plugin") + `root-plugin` } tasks { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 63f0610..4a318ac 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -2,14 +2,13 @@ plugins { `kotlin-dsl` } +repositories { + gradlePluginPortal() + mavenCentral() +} + dependencies { - implementation(libs.paperweight) - - implementation(libs.shadowjar) - - implementation(libs.runpaper) - - implementation(libs.modrinth) - - implementation(libs.hangar) + implementation(libs.paperweight.userdev) + implementation(libs.publishing.modrinth) + implementation(libs.publishing.hangar) } \ No newline at end of file diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index 4720f82..b5f44b0 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -1,14 +1,9 @@ dependencyResolutionManagement { - repositories { - maven("https://repo.papermc.io/repository/maven-public/") - - gradlePluginPortal() - mavenCentral() - } - versionCatalogs { create("libs") { from(files("../gradle/libs.versions.toml")) } } -} \ No newline at end of file +} + +rootProject.name = "buildSrc" \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/fabric-plugin.gradle.kts b/buildSrc/src/main/kotlin/fabric-plugin.gradle.kts index 36e9675..ad3acef 100644 --- a/buildSrc/src/main/kotlin/fabric-plugin.gradle.kts +++ b/buildSrc/src/main/kotlin/fabric-plugin.gradle.kts @@ -2,10 +2,6 @@ plugins { id("root-plugin") } -base { - archivesName.set(rootProject.name) -} - val mcVersion = providers.gradleProperty("mcVersion").get() val fabricVersion = providers.gradleProperty("version").get() diff --git a/buildSrc/src/main/kotlin/paper-plugin.gradle.kts b/buildSrc/src/main/kotlin/paper-plugin.gradle.kts index 11ec63f..93979d0 100644 --- a/buildSrc/src/main/kotlin/paper-plugin.gradle.kts +++ b/buildSrc/src/main/kotlin/paper-plugin.gradle.kts @@ -1,15 +1,7 @@ plugins { - id("io.papermc.paperweight.userdev") - - id("xyz.jpenilla.run-paper") - id("root-plugin") } -base { - archivesName.set(rootProject.name) -} - repositories { maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") @@ -19,7 +11,7 @@ repositories { maven("https://repo.triumphteam.dev/snapshots/") - maven("https://repo.oraxen.com/releases/") + maven("https://repo.fancyplugins.de/releases/") flatDir { dirs("libs") } } @@ -28,33 +20,7 @@ val mcVersion = providers.gradleProperty("mcVersion").get() project.version = if (System.getenv("BUILD_NUMBER") != null) "${rootProject.version}-${System.getenv("BUILD_NUMBER")}" else rootProject.version -dependencies { - paperweight.paperDevBundle("$mcVersion-R0.1-SNAPSHOT") -} - tasks { - assemble { - dependsOn(reobfJar) - } - - runServer { - jvmArgs("-Dnet.kyori.ansi.colorLevel=truecolor") - - defaultCharacterEncoding = Charsets.UTF_8.name() - - plugins { - downloadPlugins { - url("https://ci.ender.zone/job/EssentialsX/lastSuccessfulBuild/artifact/jars/EssentialsX-2.21.0-dev+70-c19b20e.jar") - - url("https://ci.lucko.me/job/TinyVault/lastSuccessfulBuild/artifact/build/libs/Vault.jar") - - url("https://download.luckperms.net/1532/bukkit/loader/LuckPerms-Bukkit-5.4.119.jar") - } - } - - minecraftVersion(mcVersion) - } - modrinth { loaders.addAll("paper", "purpur") } diff --git a/buildSrc/src/main/kotlin/root-plugin.gradle.kts b/buildSrc/src/main/kotlin/root-plugin.gradle.kts index 0546e5d..b42ff2d 100644 --- a/buildSrc/src/main/kotlin/root-plugin.gradle.kts +++ b/buildSrc/src/main/kotlin/root-plugin.gradle.kts @@ -1,27 +1,17 @@ -import gradle.kotlin.dsl.accessors._8291d1211fdf2e346e0abe66afb65704.idea import io.papermc.hangarpublishplugin.model.Platforms -import org.gradle.kotlin.dsl.support.uppercaseFirstChar -import java.io.ByteArrayOutputStream plugins { id("io.papermc.hangar-publish-plugin") - id("com.github.johnrengelman.shadow") - id("com.modrinth.minotaur") `java-library` `maven-publish` - - idea } -idea { - module { - isDownloadJavadoc = true - isDownloadSources = true - } +base { + archivesName.set(rootProject.name) } repositories { @@ -34,44 +24,10 @@ repositories { mavenCentral() } -// The commit id for the "main" branch prior to merging a pull request. -/*val start = "e888a19" - -// The commit id BEFORE merging the pull request so before "Merge pull request #30" -val end = "f78f454" - -val commitLog = getGitHistory().joinToString(separator = "") { formatGitLog(it) } - -fun getGitHistory(): List { - val output: String = ByteArrayOutputStream().use { outputStream -> - project.exec { - executable("git") - args("log", "$start..$end", "--format=format:%h %s") - standardOutput = outputStream - } - - outputStream.toString() - } - - return output.split("\n") +java { + toolchain.languageVersion.set(JavaLanguageVersion.of("17")) } -fun formatGitLog(commitLog: String): String { - val hash = commitLog.take(7) - val message = commitLog.substring(8) // Get message after commit hash + space between - return "[$hash](https://github.com/Crazy-Crew/${rootProject.name}/commit/$hash) $message
" -}*/ - -val changes = """ -${rootProject.file("CHANGELOG.md").readText(Charsets.UTF_8)} -## Commits -
-Other - -commitLog -
-""".trimIndent() - tasks { compileJava { options.encoding = Charsets.UTF_8.name() @@ -86,12 +42,6 @@ tasks { filteringCharset = Charsets.UTF_8.name() } - shadowJar { - archiveClassifier.set("") - - exclude("META-INF/**") - } - val directory = File("$rootDir/jars/${project.name.lowercase()}") val mcVersion = providers.gradleProperty("mcVersion").get() @@ -107,7 +57,7 @@ tasks { channel.set(type) - changelog.set(changes) + changelog.set(rootProject.file("CHANGELOG.md").readText(Charsets.UTF_8)) apiKey.set(System.getenv("hangar_key")) @@ -130,7 +80,7 @@ tasks { projectId.set(rootProject.name.lowercase()) - changelog.set(changes) + changelog.set(rootProject.file("CHANGELOG.md").readText(Charsets.UTF_8)) versionName.set("${rootProject.name} ${project.version}") @@ -140,8 +90,4 @@ tasks { gameVersions.add(mcVersion) } -} - -java { - toolchain.languageVersion.set(JavaLanguageVersion.of("17")) } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index f68f3f7..f2103b1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,9 +8,9 @@ website = https://modrinth.com/plugin/crazyauctions sources = https://github.com/Crazy-Crew/CrazyAuctions issues = https://github.com/Crazy-Crew/CrazyAuctions/issues -group = com.ryderbelserion.crazyauctions +group = com.badbones69.crazyauctions description = Auction off items in style. -version = 1.3.3 +version = 1.4 apiVersion = 1.20 mcVersion = 1.20.4 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0de57d8..9d770e6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,28 +1,41 @@ -[versions] -kyori_version = "4.14.0" - -shadow_version = "8.1.1" -paperweight_version = "1.5.9" -runpaper_version = "2.2.3" - -modrinth_version = "2.8.7" -hangar_version = "0.1.2" - [plugins] -hangar = { id = "io.papermc.hangar-publish-plugin", version.ref = "hangar_version" } -modrinth = { id = "com.modrinth.minotaur", version.ref = "modrinth_version" } +run-paper = { id = "xyz.jpenilla.run-paper", version = "2.2.3" } +shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1" } -paperweight = { id = "io.papermc.paperweight.userdev", version.ref = "paperweight_version" } -runpaper = { id = "xyz.jpenilla.run-paper", version.ref = "runpaper_version" } -shadowjar = { id = "com.github.johnrengelman.shadow", version.ref = "shadow_version" } +[versions] +kyori = "4.16.0" +bundle = "1.20.4-R0.1-SNAPSHOT" +cluster = "1.0-SNAPSHOT" [libraries] -adventure = { module = "net.kyori:adventure-api", version.ref = "kyori_version" } -minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "kyori_version" } +simple-yaml = { group = "com.github.Carleslc.Simple-YAML", name = "Simple-Yaml", version = "1.8.4" } -paperweight = { module = "io.papermc.paperweight:paperweight-userdev", version.ref = "paperweight_version" } -shadowjar = { module = "com.github.johnrengelman:shadow", version.ref = "shadow_version" } -runpaper = { module = "xyz.jpenilla:run-task", version.ref = "runpaper_version" } +minimessage-api = { group = "net.kyori", name = "adventure-text-minimessage", version.ref = "kyori" } +adventure-api = { group = "net.kyori", name = "adventure-api", version.ref = "kyori" } -hangar = { module = "io.papermc:hangar-publish-plugin", version.ref = "hangar_version" } -modrinth = { module = "com.modrinth.minotaur:Minotaur", version.ref = "modrinth_version" } \ No newline at end of file +itemsadder-api = { group = "com.github.LoneDev6", name = "api-itemsadder", version = "3.6.1" } +oraxen-api = { group = "io.th0rgal", name = "oraxen", version = "1.171.0" } +placeholder-api = { group = "me.clip", name = "placeholderapi", version = "2.11.5" } +head-database-api = { group = "com.arcaniax", name = "HeadDatabase-API", version = "1.3.1" } + +paperweight-userdev = { group = "io.papermc.paperweight.userdev", name = "io.papermc.paperweight.userdev.gradle.plugin", version = "1.5.11" } +publishing-modrinth = { group = "com.modrinth.minotaur", name = "Minotaur", version = "2.8.7" } +publishing-hangar = { group = "io.papermc", name = "hangar-publish-plugin", version = "0.1.2" } + +cluster-api = { group = "com.ryderbelserion.cluster", name = "api", version.ref = "cluster" } +cluster-paper = { group = "com.ryderbelserion.cluster", name = "paper", version.ref = "cluster" } + +fancy-holograms = { group = "de.oliver", name = "FancyHolograms", version = "2.0.6" } +decent-holograms = { group = "com.github.decentsoftware-eu", name = "decentholograms", version = "2.8.6" } + +triumph-cmds = { group = "dev.triumphteam", name = "triumph-cmd-bukkit", version = "2.0.0-ALPHA-9" } +triumph-gui = { group = "dev.triumphteam", name = "triumph-gui", version = "3.1.7" } + +vault = { group = "com.github.MilkBowl", name = "VaultAPI", version = "1.7.1" } +metrics = { group = "org.bstats", name = "bstats-bukkit", version = "3.0.2" } +config-me = { group = "ch.jalu", name = "configme", version = "1.4.1" } + +[bundles] +adventure = ["minimessage-api", "adventure-api"] +holograms = ["fancy-holograms", "decent-holograms"] +triumph = ["triumph-cmds", "triumph-gui"] \ No newline at end of file diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts index ce19c1c..7eee8f8 100644 --- a/paper/build.gradle.kts +++ b/paper/build.gradle.kts @@ -1,22 +1,56 @@ plugins { - id("paper-plugin") + `paper-plugin` + + id("io.papermc.paperweight.userdev") + + alias(libs.plugins.run.paper) + alias(libs.plugins.shadow) +} + +repositories { + maven("https://repo.oraxen.com/releases/") } dependencies { - implementation(project(":common")) + paperweight.paperDevBundle(libs.versions.bundle) implementation(libs.metrics) - compileOnly(libs.vault) { - exclude("org.bukkit", "bukkit") - } + compileOnly(libs.placeholder.api) + + compileOnly(libs.oraxen.api) + + compileOnly(libs.vault) compileOnly(fileTree("libs").include("*.jar")) } tasks { + assemble { + dependsOn(reobfJar) + } + + runServer { + jvmArgs("-Dnet.kyori.ansi.colorLevel=truecolor") + + defaultCharacterEncoding = Charsets.UTF_8.name() + + downloadPlugins { + url("https://github.com/EssentialsX/Essentials/releases/download/2.20.1/EssentialsX-2.20.1.jar") + + url("https://ci.lucko.me/job/TinyVault/lastSuccessfulBuild/artifact/build/libs/Vault.jar") + + url("https://download.luckperms.net/1532/bukkit/loader/LuckPerms-Bukkit-5.4.119.jar") + } + + minecraftVersion("1.20.4") + } + shadowJar { listOf( + //"com.ryderbelserion.cluster", + //"dev.triumphteam.cmd", + //"dev.triumphteam.gui", "org.bstats" ).forEach { relocate(it, "libs.$it") @@ -25,13 +59,13 @@ tasks { processResources { val properties = hashMapOf( - "name" to rootProject.name, - "version" to project.version, - "group" to rootProject.group, - "description" to rootProject.description, - "apiVersion" to providers.gradleProperty("apiVersion").get(), - "authors" to providers.gradleProperty("authors").get(), - "website" to providers.gradleProperty("website").get() + "name" to rootProject.name, + "version" to project.version, + "group" to rootProject.group, + "description" to rootProject.description, + "apiVersion" to providers.gradleProperty("apiVersion").get(), + "authors" to providers.gradleProperty("authors").get(), + "website" to providers.gradleProperty("website").get() ) inputs.properties(properties) diff --git a/paper/run/server.properties b/paper/run/server.properties index 0168825..37792ff 100644 --- a/paper/run/server.properties +++ b/paper/run/server.properties @@ -1,5 +1,5 @@ #Minecraft server properties -#Tue Mar 05 18:52:30 EST 2024 +#Wed Mar 20 12:17:37 EDT 2024 enable-jmx-monitoring=false rcon.port=25575 level-seed= diff --git a/paper/src/main/java/com/badbones69/crazyauctions/Methods.java b/paper/src/main/java/com/badbones69/crazyauctions/Methods.java index 87af34d..0098b45 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/Methods.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/Methods.java @@ -43,145 +43,6 @@ public class Methods { public static String removeColor(String msg) { return ChatColor.stripColor(msg); } - - public static ItemStack makeItem(String type, int amount) { - int ty = 0; - - if (type.contains(":")) { - String[] b = type.split(":"); - type = b[0]; - ty = Integer.parseInt(b[1]); - } - - Material m = Material.matchMaterial(type); - ItemStack item; - - try { - item = new ItemStack(m, amount, (short) ty); - } catch (Exception e) { - item = new ItemStack(Material.RED_TERRACOTTA); - } - - return item; - } - - public static ItemStack makeItem(String type, int amount, String name) { - int ty = 0; - - if (type.contains(":")) { - String[] b = type.split(":"); - type = b[0]; - ty = Integer.parseInt(b[1]); - } - - Material m = Material.matchMaterial(type); - ItemStack item; - - try { - item = new ItemStack(m, amount, (short) ty); - } catch (Exception e) { - item = new ItemStack(Material.RED_TERRACOTTA); - } - - ItemMeta me = item.getItemMeta(); - - me.setDisplayName(color(name)); - item.setItemMeta(me); - return item; - } - - public static ItemStack makeItem(String type, int amount, String name, List lore) { - ArrayList l = new ArrayList<>(); - int ty = 0; - if (type.contains(":")) { - String[] b = type.split(":"); - type = b[0]; - ty = Integer.parseInt(b[1]); - } - Material m = Material.matchMaterial(type); - ItemStack item; - - try { - item = new ItemStack(m, amount, (short) ty); - } catch (Exception e) { - item = new ItemStack(Material.RED_TERRACOTTA); - } - - ItemMeta me = item.getItemMeta(); - me.setDisplayName(color(name)); - - for (String L : lore) l.add(color(L)); - - me.setLore(l); - item.setItemMeta(me); - - return item; - } - - public static ItemStack makeItem(Material material, int amount, int type, String name) { - ItemStack item = new ItemStack(material, amount, (short) type); - ItemMeta m = item.getItemMeta(); - m.setDisplayName(color(name)); - item.setItemMeta(m); - - return item; - } - - public static ItemStack makeItem(Material material, int amount, int type, String name, List lore) { - ArrayList l = new ArrayList<>(); - ItemStack item = new ItemStack(material, amount, (short) type); - ItemMeta m = item.getItemMeta(); - - m.setDisplayName(color(name)); - for (String L : lore) l.add(color(L)); - m.setLore(l); - item.setItemMeta(m); - - return item; - } - - public static ItemStack makeItem(Material material, int amount, int type, String name, List lore, Map enchants) { - ItemStack item = new ItemStack(material, amount, (short) type); - ItemMeta m = item.getItemMeta(); - - m.setDisplayName(name); - m.setLore(lore); - item.setItemMeta(m); - item.addUnsafeEnchantments(enchants); - - return item; - } - - public static ItemStack addLore(ItemStack item, String i) { - ArrayList lore = new ArrayList<>(); - ItemMeta m = item.getItemMeta(); - - if (item.getItemMeta().hasLore()) { - lore.addAll(item.getItemMeta().getLore()); - } - - lore.add(i); - m.setLore(lore); - item.setItemMeta(m); - return item; - } - - public static ItemStack addLore(ItemStack item, List list) { - if (item != null && item.getType() != Material.AIR) { - ArrayList lore = new ArrayList<>(); - ItemMeta m = item.getItemMeta(); - - if (item.hasItemMeta() && item.getItemMeta().hasLore()) { - lore.addAll(item.getItemMeta().getLore()); - } - - for (String i : list) lore.add(color(i)); - m.setLore(lore); - item.setItemMeta(m); - } - - return item; - } public static ItemStack getItemInHand(Player player) { return player.getInventory().getItemInMainHand(); diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/builders/ItemBuilder.java b/paper/src/main/java/com/badbones69/crazyauctions/api/builders/ItemBuilder.java new file mode 100644 index 0000000..d59b5f4 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/api/builders/ItemBuilder.java @@ -0,0 +1,1397 @@ +package com.badbones69.crazyauctions.api.builders; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.Methods; +import com.badbones69.crazyauctions.api.support.PluginSupport; +import com.badbones69.crazyauctions.api.support.SkullCreator; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.ryderbelserion.cluster.utils.DyeUtils; +import io.th0rgal.oraxen.api.OraxenItems; +import me.clip.placeholderapi.PlaceholderAPI; +import net.minecraft.nbt.TagParser; +import org.bukkit.*; +import org.bukkit.block.Banner; +import org.bukkit.block.banner.Pattern; +import org.bukkit.block.banner.PatternType; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ArmorMeta; +import org.bukkit.inventory.meta.BannerMeta; +import org.bukkit.inventory.meta.BlockStateMeta; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.inventory.meta.MapMeta; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.inventory.meta.trim.ArmorTrim; +import org.bukkit.inventory.meta.trim.TrimMaterial; +import org.bukkit.inventory.meta.trim.TrimPattern; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.potion.PotionData; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.potion.PotionType; +import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; + +public class ItemBuilder { + + @NotNull + private final CrazyAuctions plugin = CrazyAuctions.get(); + + // Items + private Material material = Material.STONE; + private ItemStack itemStack = null; + private int itemAmount = 1; + + // NBT Data + private String itemData = ""; + + // Display + private String displayName = ""; + private List displayLore = new ArrayList<>(); + private int itemDamage = 0; + + // Model Data + private boolean hasCustomModelData = false; + private int customModelData = 0; + private String customMaterial = ""; + + // Potions + private boolean isPotion = false; + private Color potionColor = Color.RED; + private PotionEffectType potionType = null; + private int potionDuration = -1; + private int potionAmplifier = 1; + + // Player Heads + private boolean isHash = false; + private boolean isURL = false; + private boolean isHead = false; + + private String player = ""; + + // Arrows + private boolean isTippedArrow = false; + + // Armor + private boolean isLeatherArmor = false; + private boolean isArmor = false; + + // Trims + private TrimMaterial trimMaterial = null; + private TrimPattern trimPattern = null; + private Color armorColor = Color.RED; + + // Banners + private boolean isBanner = false; + private List patterns = new ArrayList<>(); + + // Shields + private boolean isShield = false; + + // Maps + private boolean isMap = false; + private Color mapColor = Color.RED; + + // Fireworks + private boolean isFirework = false; + private boolean isFireworkStar = false; + private Color fireworkColor = Color.RED; + private List fireworkColors = new ArrayList<>(); + private int fireworkPower = 1; + + // Enchantments or ItemFlags + private boolean isUnbreakable = false; + + private boolean hideItemFlags = false; + private List itemFlags = new ArrayList<>(); + + private boolean isGlowing = false; + + private boolean isSpawner = false; + private EntityType entityType = EntityType.BAT; + + // Crates + private String crateName = ""; + private Player target = null; + + // Placeholders + private Map namePlaceholders = new HashMap<>(); + private Map lorePlaceholders = new HashMap<>(); + + /** + * Deduplicate an item builder. + * + * @param itemBuilder the item builder to deduplicate. + */ + public ItemBuilder(ItemBuilder itemBuilder) { + this.target = itemBuilder.target; + + this.material = itemBuilder.material; + this.itemStack = itemBuilder.itemStack; + + this.customMaterial = itemBuilder.customMaterial; + + this.itemAmount = itemBuilder.itemAmount; + this.itemData = itemBuilder.itemData; + + this.displayName = itemBuilder.displayName; + this.displayLore = itemBuilder.displayLore; + this.itemDamage = itemBuilder.itemDamage; + + this.hasCustomModelData = itemBuilder.hasCustomModelData; + this.customModelData = itemBuilder.customModelData; + + this.isPotion = itemBuilder.isPotion; + this.potionColor = itemBuilder.potionColor; + this.potionType = itemBuilder.potionType; + this.potionDuration = itemBuilder.potionDuration; + this.potionAmplifier = itemBuilder.potionAmplifier; + + this.isHead = itemBuilder.isHead; + this.isHash = itemBuilder.isHash; + this.isURL = itemBuilder.isURL; + this.player = itemBuilder.player; + + this.isTippedArrow = itemBuilder.isTippedArrow; + + this.isLeatherArmor = itemBuilder.isLeatherArmor; + this.isArmor = itemBuilder.isArmor; + + this.trimMaterial = itemBuilder.trimMaterial; + this.trimPattern = itemBuilder.trimPattern; + this.armorColor = itemBuilder.armorColor; + + this.isBanner = itemBuilder.isBanner; + this.patterns = itemBuilder.patterns; + + this.isShield = itemBuilder.isShield; + + this.isMap = itemBuilder.isMap; + this.mapColor = itemBuilder.mapColor; + + this.isFirework = itemBuilder.isFirework; + this.isFireworkStar = itemBuilder.isFireworkStar; + this.fireworkColor = itemBuilder.fireworkColor; + this.fireworkColors = itemBuilder.fireworkColors; + this.fireworkPower = itemBuilder.fireworkPower; + + this.isUnbreakable = itemBuilder.isUnbreakable; + + this.hideItemFlags = itemBuilder.hideItemFlags; + this.itemFlags = itemBuilder.itemFlags; + + this.isGlowing = itemBuilder.isGlowing; + + this.isSpawner = itemBuilder.isSpawner; + this.entityType = itemBuilder.entityType; + + this.namePlaceholders = new HashMap<>(itemBuilder.namePlaceholders); + this.lorePlaceholders = new HashMap<>(itemBuilder.lorePlaceholders); + + this.crateName = itemBuilder.crateName; + } + + public ItemBuilder(ItemStack itemStack) { + this.itemStack = itemStack; + + this.material = itemStack.getType(); + + switch (this.material) { + case LEATHER_HELMET, LEATHER_CHESTPLATE, LEATHER_LEGGINGS, LEATHER_BOOTS, LEATHER_HORSE_ARMOR -> this.isLeatherArmor = true; + case POTION, SPLASH_POTION, LINGERING_POTION -> this.isPotion = true; + case FIREWORK_STAR -> this.isFireworkStar = true; + case TIPPED_ARROW -> this.isTippedArrow = true; + case FIREWORK_ROCKET -> this.isFirework = true; + case FILLED_MAP -> this.isMap = true; + case PLAYER_HEAD -> this.isHead = true; + case SPAWNER -> this.isSpawner = true; + case SHIELD -> this.isShield = true; + } + + this.itemStack.editMeta(itemMeta -> { + if (itemMeta.hasDisplayName()) this.displayName = itemMeta.getDisplayName(); + + if (itemMeta.hasLore()) this.displayLore = itemMeta.getLore(); + }); + + String name = this.material.name(); + + this.isArmor = name.endsWith("_HELMET") || name.endsWith("_CHESTPLATE") || name.endsWith("_LEGGINGS") || name.endsWith("_BOOTS"); + + this.isBanner = name.endsWith("BANNER"); + } + + public ItemBuilder(ItemStack itemStack, Player target) { + this.target = target; + + this.itemStack = itemStack; + + this.material = itemStack.getType(); + + switch (this.material) { + case LEATHER_HELMET, LEATHER_CHESTPLATE, LEATHER_LEGGINGS, LEATHER_BOOTS, LEATHER_HORSE_ARMOR -> this.isLeatherArmor = true; + case POTION, SPLASH_POTION, LINGERING_POTION -> this.isPotion = true; + case FIREWORK_STAR -> this.isFireworkStar = true; + case TIPPED_ARROW -> this.isTippedArrow = true; + case FIREWORK_ROCKET -> this.isFirework = true; + case FILLED_MAP -> this.isMap = true; + case PLAYER_HEAD -> this.isHead = true; + case SPAWNER -> this.isSpawner = true; + case SHIELD -> this.isShield = true; + } + + this.itemStack.editMeta(itemMeta -> { + if (itemMeta.hasDisplayName()) this.displayName = itemMeta.getDisplayName(); + + if (itemMeta.hasLore()) this.displayLore = itemMeta.getLore(); + }); + + String name = this.material.name(); + + this.isArmor = name.endsWith("_HELMET") || name.endsWith("_CHESTPLATE") || name.endsWith("_LEGGINGS") || name.endsWith("_BOOTS"); + + this.isBanner = name.endsWith("BANNER"); + } + + public ItemBuilder() {} + + private String parse(String message) { + if (PluginSupport.PLACEHOLDERAPI.isPluginEnabled() && this.target != null) { + return Methods.color(PlaceholderAPI.setPlaceholders(this.target, message)); + } + + return Methods.color(message); + } + + /** + * Builder the item from all the information that was given to the builder. + * + * @return the result of all the info that was given to the builder as an ItemStack. + */ + public ItemStack build() { + // Check if oraxen is enabled. + if (PluginSupport.ORAXEN.isPluginEnabled()) { + // Get the item. + io.th0rgal.oraxen.items.ItemBuilder oraxenItem = OraxenItems.getItemById(this.customMaterial); + + if (oraxenItem != null) { + // If the item isn't null, we don't need to re-build. + if (this.itemStack != null) { + this.material = this.itemStack.getType(); + + return this.itemStack; + } + + // This is just here in case it is null for whatever reason. + this.itemStack = oraxenItem.build(); + + this.material = this.itemStack.getType(); + + return this.itemStack; + } + } + + if (this.isHead) { // Has to go 1st due to it removing all data when finished. + if (this.isHash) { // Sauce: https://github.com/deanveloper/SkullCreator + if (this.isURL) { + this.itemStack = SkullCreator.itemWithUrl(this.itemStack, this.player); + } else { + this.itemStack = SkullCreator.itemWithBase64(this.itemStack, this.player); + } + } + } + + if (this.itemStack.getType() != Material.AIR) { + // If item data is not empty. We ignore all other options and simply return. + if (!this.itemData.isEmpty()) { + net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(getItemStack()); + + try { + nmsItem.setTag(TagParser.parseTag(this.itemData)); + } catch (CommandSyntaxException exception) { + this.plugin.getLogger().log(Level.WARNING, "Failed to set nms tag.", exception); + } + + return CraftItemStack.asBukkitCopy(nmsItem); + } + + getItemStack().setAmount(this.itemAmount); + + getItemStack().editMeta(itemMeta -> { + // If the item is able to be damaged. + if (itemMeta instanceof Damageable damageable) { + if (this.itemDamage >= 1) { + if (this.itemDamage >= this.material.getMaxDurability()) { + damageable.setDamage(this.material.getMaxDurability()); + } else { + damageable.setDamage(this.itemDamage); + } + } + } + + if (this.isArmor) { + if (this.trimPattern != null && this.trimMaterial != null) { + ArmorMeta armorMeta = (ArmorMeta) itemMeta; + + armorMeta.setTrim(new ArmorTrim(this.trimMaterial, this.trimPattern)); + } + } + + if (this.isMap) { + MapMeta mapMeta = (MapMeta) itemMeta; + + mapMeta.setScaling(true); + + if (this.mapColor != null) mapMeta.setColor(this.mapColor); + } + + // Check if is potion and apply potion related settings. + if (this.isPotion || this.isTippedArrow) { + PotionMeta potionMeta = (PotionMeta) itemMeta; + + // Single potion effect. + if (this.potionType != null) { + PotionEffect effect = new PotionEffect(this.potionType, this.potionDuration, this.potionAmplifier); + + potionMeta.addCustomEffect(effect, true); + + potionMeta.setBasePotionData(new PotionData(PotionType.valueOf(effect.getType().getName()))); + } + + if (this.potionColor != null) { + potionMeta.setColor(this.potionColor); + } + } + + if (this.isLeatherArmor && this.armorColor != null) { + LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemMeta; + + leatherArmorMeta.setColor(this.armorColor); + } + + if (this.isBanner && !this.patterns.isEmpty()) { + BannerMeta bannerMeta = (BannerMeta) itemMeta; + bannerMeta.setPatterns(this.patterns); + } + + if (this.isShield && !this.patterns.isEmpty()) { + BlockStateMeta shieldMeta = (BlockStateMeta) itemMeta; + + Banner banner = (Banner) shieldMeta.getBlockState(); + banner.setPatterns(this.patterns); + banner.update(); + + shieldMeta.setBlockState(banner); + } + + // If the item has model data. + if (this.hasCustomModelData) { + itemMeta.setCustomModelData(this.customModelData); + } + + this.itemFlags.forEach(itemMeta::addItemFlags); + + if (this.hideItemFlags) { + itemMeta.addItemFlags(ItemFlag.values()); + } + + itemMeta.setUnbreakable(this.isUnbreakable); + + if (this.isGlowing) { + if (!itemMeta.hasEnchants()) { + itemMeta.addEnchant(Enchantment.LUCK, 1, false); + itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + } + } + + itemMeta.setDisplayName(getUpdatedName()); + itemMeta.setLore(getUpdatedLore()); + }); + } else { + Logger logger = this.plugin.getLogger(); + + logger.warning("Material cannot be of type AIR or null, If you see this."); + logger.warning("in your console but do not have any invalid items. You can"); + logger.warning("ignore this as we use AIR for some niche cases internally."); + } + + return getItemStack(); + } + + public ItemStack getItemStack() { + return this.itemStack; + } + + public ItemMeta getItemMeta() { + return this.itemStack.getItemMeta(); + } + + public ItemBuilder setItemMeta(ItemMeta itemMeta) { + this.itemStack.setItemMeta(itemMeta); + + return this; + } + + /** + * Set a target player if using PlaceholderAPI + * + * @param target the target to set. + * @return the ItemBuilder with updated data. + */ + public ItemBuilder setTarget(Player target) { + this.target = target; + + return this; + } + + /** + * Get the item's name with all the placeholders added to it. + * + * @return The name with all the placeholders in it. + */ + public String getUpdatedName() { + String newName = this.displayName; + + for (String placeholder : this.namePlaceholders.keySet()) { + newName = newName.replace(placeholder, this.namePlaceholders.get(placeholder)).replace(placeholder.toLowerCase(), this.namePlaceholders.get(placeholder)); + } + + return parse(newName); + } + + /** + * @return the name of the item. + */ + public String getName() { + return this.displayName; + } + + /** + * @return the material of the item. + */ + public Material getMaterial() { + return this.material; + } + + /** + * Sets the material. + * + * @param material the material to use. + * @return the ItemBuilder with updated data. + */ + public ItemBuilder setMaterial(Material material) { + this.material = material; + + if (this.itemStack == null) { + // If item stack is null, we create new item stack based on material. + this.itemStack = new ItemStack(this.material); + } else { + // Get old item meta. + ItemMeta itemMeta = this.itemStack.getItemMeta(); + + // Create new itemstack. + ItemStack newItemStack = new ItemStack(this.material); + // Set old item meta to new itemstack. + newItemStack.setItemMeta(itemMeta); + + // Overwrite old item stack with new item stack. + this.itemStack = newItemStack; + } + + this.isHead = material == Material.PLAYER_HEAD; + + return this; + } + + /** + * Set trim material + * + * @param trimMaterial pattern to set. + */ + public void setTrimMaterial(TrimMaterial trimMaterial) { + this.trimMaterial = trimMaterial; + } + + /** + * Set trim pattern + * + * @param trimPattern pattern to set. + */ + public void setTrimPattern(TrimPattern trimPattern) { + this.trimPattern = trimPattern; + } + + /** + * Set the type of item and its metadata in the builder. + * + * @param type the string must be in this form: %Material% or %Material%:%MetaData% + * @return the ItemBuilder with updated info. + */ + public ItemBuilder setMaterial(String type) { + if (type == null || type.isEmpty()) { + List.of( + "Material cannot be null or empty, Output: " + type + ".", + "Please take a screenshot of this before asking for support." + ).forEach(line -> { + this.plugin.getLogger().warning(line); + }); + + this.itemStack = new ItemStack(Material.STONE); + this.itemStack.editMeta(itemMeta -> itemMeta.setDisplayName(parse("&cAn error has occurred with the item builder."))); + + this.material = this.itemStack.getType(); + + return this; + } + + this.customMaterial = type; + + String metaData; + + if (type.contains(":")) { + String[] section = type.split(":"); + + type = section[0]; + metaData = section[1]; + + if (metaData.contains("#")) { + String modelData = metaData.split("#")[1]; + + if (isInt(modelData)) { + this.hasCustomModelData = true; + this.customModelData = Integer.parseInt(modelData); + } + } + + metaData = metaData.replace("#" + this.customModelData, ""); + + if (isInt(metaData)) { + this.itemDamage = Integer.parseInt(metaData); + } else { + this.potionType = getPotionType(PotionEffectType.getByName(metaData)).getEffectType(); + + this.potionColor = DyeUtils.getColor(metaData); + this.armorColor = DyeUtils.getColor(metaData); + this.mapColor = DyeUtils.getColor(metaData); + this.fireworkColor = DyeUtils.getColor(metaData); + } + } else if (type.contains("#")) { + String[] section = type.split("#"); + type = section[0]; + + String modelData = section[1]; + + if (isInt(modelData)) { + this.hasCustomModelData = true; + this.customModelData = Integer.parseInt(modelData); + } + } + + Material material = Material.matchMaterial(type); + + if (material != null) { + this.itemStack = new ItemStack(material); + + this.material = this.itemStack.getType(); + } else { + if (PluginSupport.ORAXEN.isPluginEnabled()) { + io.th0rgal.oraxen.items.ItemBuilder oraxenItem = OraxenItems.getItemById(this.customMaterial); + + if (oraxenItem != null) { + this.itemStack = oraxenItem.build(); + + this.material = this.itemStack.getType(); + + return this; + } + } + } + + switch (this.material) { + case LEATHER_HELMET, LEATHER_CHESTPLATE, LEATHER_LEGGINGS, LEATHER_BOOTS, LEATHER_HORSE_ARMOR -> this.isLeatherArmor = true; + case POTION, SPLASH_POTION, LINGERING_POTION -> this.isPotion = true; + case FIREWORK_STAR -> this.isFireworkStar = true; + case TIPPED_ARROW -> this.isTippedArrow = true; + case FIREWORK_ROCKET -> this.isFirework = true; + case FILLED_MAP -> this.isMap = true; + case PLAYER_HEAD -> this.isHead = true; + case SPAWNER -> this.isSpawner = true; + case SHIELD -> this.isShield = true; + } + + String name = this.material.name(); + + this.isArmor = name.endsWith("_HELMET") || name.endsWith("_CHESTPLATE") || name.endsWith("_LEGGINGS") || name.endsWith("_BOOTS"); + + this.isBanner = name.endsWith("BANNER"); + + return this; + } + + /** + * Sets the crate name + * + * @param crateName the crate name to set. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder setCrateName(String crateName) { + this.crateName = crateName; + + return this; + } + + /** + * @param damage the damage value of the item. + */ + public void setDamage(int damage) { + this.itemDamage = damage; + } + + /** + * Get the damage to the item. + * + * @return the damage to the item as an int. + */ + public int getDamage() { + return this.itemDamage; + } + + /** + * @param itemName the name of the item. + * @return the ItemBuilder with an updated name. + */ + public ItemBuilder setName(String itemName) { + if (itemName != null) { + this.displayName = itemName; + } + + return this; + } + + /** + * @param placeholders the placeholders that will be used. + * @return the ItemBuilder with updated placeholders. + */ + public ItemBuilder setNamePlaceholders(Map placeholders) { + this.namePlaceholders = placeholders; + + return this; + } + + /** + * Add a placeholder to the name of the item. + * + * @param placeholder the placeholder that will be replaced. + * @param argument the argument you wish to replace the placeholder with. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder addNamePlaceholder(String placeholder, String argument) { + this.namePlaceholders.put(placeholder, argument); + + return this; + } + + /** + * Remove a placeholder from the list. + * + * @param placeholder the placeholder you wish to remove. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder removeNamePlaceholder(String placeholder) { + this.namePlaceholders.remove(placeholder); + + return this; + } + + /** + * Set the lore of the item in the builder. This will auto force color in all the lores that contains color code. (&a, &c, &7, etc...) + * + * @param lore the lore of the item in the builder. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder setLore(List lore) { + if (lore != null) { + this.displayLore.clear(); + + for (String line : lore) { + this.displayLore.add(Methods.color(line)); + } + } + + return this; + } + + /** + * Set the lore of the item with papi support in the builder. This will auto force color in all the lores that contains color code. (&a, &c, &7, etc...) + * + * @param player the player viewing the button. + * @param lore the lore of the item in the builder. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder setLore(Player player, List lore) { + if (lore != null) { + this.displayLore.clear(); + + for (String line : lore) { + this.displayLore.add(PlaceholderAPI.setPlaceholders(player, Methods.color(line))); + } + } + + return this; + } + + /** + * Add a line to the current lore of the item. This will auto force color in the lore that contains color code. (&a, &c, &7, etc...) + * + * @param lore the new line you wish to add. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder addLore(String lore) { + if (lore != null) this.displayLore.add(Methods.color(lore)); + + return this; + } + + /** + * Set the placeholders that are in the lore of the item. + * + * @param placeholders the placeholders that you wish to use. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder setLorePlaceholders(Map placeholders) { + this.lorePlaceholders = placeholders; + + return this; + } + + /** + * Add a placeholder to the lore of the item. + * + * @param placeholder the placeholder you wish to replace. + * @param argument the argument that will replace the placeholder. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder addLorePlaceholder(String placeholder, String argument) { + this.lorePlaceholders.put(placeholder, argument); + + return this; + } + + /** + * Get the lore with all the placeholders added to it. + * + * @return the lore with all placeholders in it. + */ + public List getUpdatedLore() { + List newLore = new ArrayList<>(); + + for (String item : this.displayLore) { + for (String placeholder : this.lorePlaceholders.keySet()) { + item = item.replace(placeholder, this.lorePlaceholders.get(placeholder)).replace(placeholder.toLowerCase(), this.lorePlaceholders.get(placeholder)); + } + + newLore.add(parse(item)); + } + + return newLore; + } + + /** + * Remove a placeholder from the lore. + * + * @param placeholder the placeholder you wish to remove. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder removeLorePlaceholder(String placeholder) { + this.lorePlaceholders.remove(placeholder); + + return this; + } + + /** + * @param entityType the entity type the mob spawn egg will be. + * @return the ItemBuilder with an updated mob spawn egg. + */ + public ItemBuilder setEntityType(EntityType entityType) { + this.entityType = entityType; + + return this; + } + + /** + * @param patterns the list of Patterns to add. + * @return the ItemBuilder with updated patterns. + */ + public ItemBuilder addPatterns(List patterns) { + patterns.forEach(this::addPatterns); + + return this; + } + + /** + * @param pattern a pattern to add. + * @return the ItemBuilder with an updated pattern. + */ + public ItemBuilder addPattern(Pattern pattern) { + this.patterns.add(pattern); + + return this; + } + + /** + * @param patterns set a list of Patterns. + * @return the ItemBuilder with an updated list of patterns. + */ + public ItemBuilder setPattern(List patterns) { + this.patterns = patterns; + + return this; + } + + /** + * @param amount the amount of the item stack. + * @return the ItemBuilder with an updated item count. + */ + public ItemBuilder setAmount(Integer amount) { + this.itemAmount = amount; + + return this; + } + + /** + * Set the player that will be displayed on the head. + * + * @param playerName the player being displayed on the head. + * @return the ItemBuilder with an updated Player Name. + */ + public ItemBuilder setPlayerName(String playerName) { + this.player = playerName; + + if (this.player != null && this.player.length() > 16) { + this.isHash = true; + this.isURL = this.player.startsWith("http"); + } + + return this; + } + + /** + * Adds multiple enchantments to an item. + * + * @param enchantments the map of enchantments, String/Integer + * @param unsafeEnchantments if the enchantments are higher than the vanilla defaults. + * @return the ItemBuilder with updated enchantments. + */ + public ItemBuilder addEnchantments(Map enchantments, boolean unsafeEnchantments) { + enchantments.forEach((enchantment, level) -> addEnchantment(enchantment, level, unsafeEnchantments)); + + return this; + } + + /** + * Adds a single enchantment to an item. + * + * @param enchantment the type of enchantment. + * @param level the level of the enchantment. + * @param unsafeEnchantments if the enchantment is higher than the vanilla defaults. + * @return the ItemBuilder with updated enchantments. + */ + public ItemBuilder addEnchantment(Enchantment enchantment, int level, boolean unsafeEnchantments) { + getItemStack().editMeta(itemMeta -> { + itemMeta.addEnchant(enchantment, level, unsafeEnchantments); + }); + + return this; + } + + /** + * Adds a single enchantment to an item. + * + * @param enchantment the type of enchantment. + * @param level the level of the enchantment. + * @return the ItemBuilder with updated enchantments. + */ + public ItemBuilder addEnchantment(Enchantment enchantment, int level) { + getItemStack().editMeta(itemMeta -> { + itemMeta.addEnchant(enchantment, level, false); + }); + + return this; + } + + /** + * Removes an enchantment. + * + * @param enchantment the enchantment to remove. + * @return the ItemBuilder with updated data. + */ + public ItemBuilder removeEnchantment(Enchantment enchantment) { + getItemStack().editMeta(itemMeta -> { + itemMeta.removeEnchant(enchantment); + }); + + return this; + } + + /** + * Set the flags that will be on the item in the builder. + * + * @param flagStrings the flag names as string you wish to add to the item in the builder. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder setFlagsFromStrings(List flagStrings) { + this.itemFlags.clear(); + + for (String flagString : flagStrings) { + ItemFlag flag = getFlag(flagString); + + if (flag != null) this.itemFlags.add(flag); + } + + return this; + } + + /** + * Adds a list of item flags to an item. + * + * @param flagStrings list of items to add. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder addItemFlags(List flagStrings) { + for (String flagString : flagStrings) { + try { + ItemFlag itemFlag = ItemFlag.valueOf(flagString.toUpperCase()); + + addItemFlag(itemFlag); + } catch (Exception ignored) {} + } + + return this; + } + + /** + * Add a flag to the item in the builder. + * + * @param flagString the name of the flag you wish to add. + * @return the ItemBuilder with updated info. + */ + public ItemBuilder addFlags(String flagString) { + ItemFlag flag = getFlag(flagString); + + if (flag != null) this.itemFlags.add(flag); + + return this; + } + + /** + * Adds an ItemFlag to a map which is added to an item. + * + * @param itemFlag the flag to add. + * @return the ItemBuilder with an updated ItemFlag. + */ + public ItemBuilder addItemFlag(ItemFlag itemFlag) { + if (itemFlag != null) this.itemFlags.add(itemFlag); + + return this; + } + + /** + * Adds multiple ItemFlags in a list to a map which get added to an item. + * + * @param itemFlags the list of flags to add. + * @return the ItemBuilder with a list of ItemFlags. + */ + public ItemBuilder setItemFlags(List itemFlags) { + this.itemFlags = itemFlags; + + return this; + } + + /** + * @param hideItemFlags hide item flags based on a boolean. + * @return the ItemBuilder with an updated Boolean. + */ + public ItemBuilder hideItemFlags(boolean hideItemFlags) { + this.hideItemFlags = hideItemFlags; + + return this; + } + + /** + * @param unbreakable sets the item to be unbreakable. + * @return the ItemBuilder with an updated Boolean. + */ + public ItemBuilder setUnbreakable(boolean unbreakable) { + this.isUnbreakable = unbreakable; + + return this; + } + + /** + * @param glow sets whether to make an item to glow or not. + * @return the ItemBuilder with an updated Boolean. + */ + public ItemBuilder setGlow(boolean glow) { + this.isGlowing = glow; + + return this; + } + + /** + * It will override any enchantments used in ItemBuilder.addEnchantment() below. + * + * @param enchantments a list of enchantments to add to the item. + * @return the ItemBuilder with a list of updated enchantments. + */ + public ItemBuilder setEnchantments(HashMap enchantments) { + if (enchantments != null) getItemStack().editMeta(meta -> { + enchantments.forEach((enchantment, amount) -> meta.addEnchant(enchantment, amount, false)); + }); + + return this; + } + + /** + * Adds an enchantment to the item. + * + * @param enchantment the enchantment you wish to add. + * @param level the level of the enchantment ( Unsafe levels included ) + * @return the ItemBuilder with updated enchantments. + */ + public ItemBuilder addEnchantments(Enchantment enchantment, int level) { + getItemStack().editMeta(meta -> { + meta.addEnchant(enchantment, level, false); + }); + + return this; + } + + /** + * Remove an enchantment from the item. + * + * @param enchantment the enchantment you wish to remove. + * @return the ItemBuilder with updated enchantments. + */ + public ItemBuilder removeEnchantments(Enchantment enchantment) { + getItemStack().editMeta(meta -> { + meta.removeEnchant(enchantment); + }); + + return this; + } + + /** + * Convert an ItemStack to an ItemBuilder to allow easier editing of the ItemStack. + * + * @param item the ItemStack you wish to convert into an ItemBuilder. + * @return the ItemStack as an ItemBuilder with all the info from the item. + */ + public static ItemBuilder convertItemStack(ItemStack item) { + return new ItemBuilder(item).setAmount(item.getAmount()).setEnchantments(new HashMap<>(item.getEnchantments())); + } + + public static ItemBuilder convertItemStack(ItemStack item, Player player) { + return new ItemBuilder(item).setTarget(player).setAmount(item.getAmount()).setEnchantments(new HashMap<>(item.getEnchantments())); + } + + /** + * Converts a String to an ItemBuilder. + * + * @param itemString the string you wish to convert. + * @return the string as an ItemBuilder. + */ + public static ItemBuilder convertString(String itemString) { + return convertString(itemString, null); + } + + /** + * Converts a string to an ItemBuilder with a placeholder for errors. + * + * @param itemString the string you wish to convert. + * @param placeHolder the placeholder to use if there is an error. + * @return the string as an ItemBuilder. + */ + public static ItemBuilder convertString(String itemString, String placeHolder) { + ItemBuilder itemBuilder = new ItemBuilder(); + + try { + for (String optionString : itemString.split(", ")) { + String option = optionString.split(":")[0]; + String value = optionString.replace(option + ":", "").replace(option, ""); + + switch (option.toLowerCase()) { + case "item" -> itemBuilder.setMaterial(value); + case "name" -> itemBuilder.setName(value); + case "amount" -> { + try { + itemBuilder.setAmount(Integer.parseInt(value)); + } catch (NumberFormatException e) { + itemBuilder.setAmount(1); + } + } + case "damage" -> { + try { + itemBuilder.setDamage(Integer.parseInt(value)); + } catch (NumberFormatException e) { + itemBuilder.setDamage(0); + } + } + case "lore" -> itemBuilder.setLore(Arrays.asList(value.split(","))); + case "player" -> itemBuilder.setPlayerName(value); + case "unbreakable-item" -> { + if (value.isEmpty() || value.equalsIgnoreCase("true")) itemBuilder.setUnbreakable(true); + } + case "trim-pattern" -> { + if (!value.isEmpty()) itemBuilder.setTrimPattern(Registry.TRIM_PATTERN.get(NamespacedKey.minecraft(value.toLowerCase()))); + } + case "trim-material" -> { + if (!value.isEmpty()) itemBuilder.setTrimMaterial(Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft(value.toLowerCase()))); + } + default -> { + Enchantment enchantment = getEnchantment(option); + + if (enchantment != null) { + try { + itemBuilder.addEnchantments(enchantment, Integer.parseInt(value)); + } catch (NumberFormatException e) { + itemBuilder.addEnchantments(enchantment, 1); + } + + break; + } + + for (ItemFlag itemFlag : ItemFlag.values()) { + if (itemFlag.name().equalsIgnoreCase(option)) { + itemBuilder.addItemFlag(itemFlag); + break; + } + } + + try { + for (PatternType pattern : PatternType.values()) { + if (option.equalsIgnoreCase(pattern.name()) || value.equalsIgnoreCase(pattern.getIdentifier())) { + DyeColor color = DyeUtils.getDyeColor(value); + if (color != null) itemBuilder.addPattern(new Pattern(color, pattern)); + break; + } + } + } catch (Exception ignored) {} + } + } + } + } catch (Exception exception) { + itemBuilder.setMaterial(Material.RED_TERRACOTTA).setName("&c&lERROR").setLore(Arrays.asList("&cThere is an error", "&cFor : &c" + (placeHolder != null ? placeHolder : ""))); + + JavaPlugin.getPlugin(CrazyAuctions.class).getLogger().log(Level.WARNING, "An error has occurred with the item builder: ", exception); + } + + return itemBuilder; + } + + /** + * Converts a list of Strings to a list of ItemBuilders. + * + * @param itemStrings the list of Strings. + * @return the list of ItemBuilders. + */ + public static List convertStringList(List itemStrings) { + return convertStringList(itemStrings, null); + } + + /** + * Converts a list of Strings to a list of ItemBuilders with a placeholder for errors. + * + * @param itemStrings the list of strings. + * @param placeholder the placeholder for errors. + * @return the list of ItemBuilders. + */ + public static List convertStringList(List itemStrings, String placeholder) { + return itemStrings.stream().map(itemString -> convertString(itemString, placeholder)).collect(Collectors.toList()); + } + + /** + * Get the PotionEffect from a PotionEffectType. + * + * @param type the type of the potion effect. + * @return the potion type. + */ + private PotionType getPotionType(PotionEffectType type) { + if (type != null) { + if (type.equals(PotionEffectType.FIRE_RESISTANCE)) { + return PotionType.FIRE_RESISTANCE; + } else if (type.equals(PotionEffectType.HARM)) { + return PotionType.INSTANT_DAMAGE; + } else if (type.equals(PotionEffectType.HEAL)) { + return PotionType.INSTANT_HEAL; + } else if (type.equals(PotionEffectType.INVISIBILITY)) { + return PotionType.INVISIBILITY; + } else if (type.equals(PotionEffectType.JUMP)) { + return PotionType.JUMP; + } else if (type.equals(PotionEffectType.getByName("LUCK"))) { + return PotionType.valueOf("LUCK"); + } else if (type.equals(PotionEffectType.NIGHT_VISION)) { + return PotionType.NIGHT_VISION; + } else if (type.equals(PotionEffectType.POISON)) { + return PotionType.POISON; + } else if (type.equals(PotionEffectType.REGENERATION)) { + return PotionType.REGEN; + } else if (type.equals(PotionEffectType.SLOW)) { + return PotionType.SLOWNESS; + } else if (type.equals(PotionEffectType.SPEED)) { + return PotionType.SPEED; + } else if (type.equals(PotionEffectType.INCREASE_DAMAGE)) { + return PotionType.STRENGTH; + } else if (type.equals(PotionEffectType.WATER_BREATHING)) { + return PotionType.WATER_BREATHING; + } else if (type.equals(PotionEffectType.WEAKNESS)) { + return PotionType.WEAKNESS; + } + } + + return null; + } + + /** + * Get the enchantment from a string. + * + * @param enchantmentName the string of the enchantment. + * @return the enchantment from the string. + */ + private static Enchantment getEnchantment(String enchantmentName) { + enchantmentName = stripEnchantmentName(enchantmentName); + + for (Enchantment enchantment : Enchantment.values()) { + try { + if (stripEnchantmentName(enchantment.getKey().getKey()).equalsIgnoreCase(enchantmentName)) return enchantment; + + Map enchantments = getEnchantmentList(); + + if (stripEnchantmentName(enchantment.getName()).equalsIgnoreCase(enchantmentName) || (enchantments.get(enchantment.getName()) != null && + stripEnchantmentName(enchantments.get(enchantment.getName())).equalsIgnoreCase(enchantmentName))) return enchantment; + } catch (Exception ignore) {} + } + + return null; + } + + /** + * Strip extra characters from an enchantment name. + * + * @param enchantmentName the enchantment name. + * @return the stripped enchantment name. + */ + private static String stripEnchantmentName(String enchantmentName) { + return enchantmentName != null ? enchantmentName.replace("-", "").replace("_", "").replace(" ", "") : null; + } + + /** + * Get the list of enchantments and their in-Game names. + * + * @return the hashmap of enchantments and their in-game names. + */ + private static Map getEnchantmentList() { + Map enchantments = new HashMap<>(); + + enchantments.put("ARROW_DAMAGE", "Power"); + enchantments.put("ARROW_FIRE", "Flame"); + enchantments.put("ARROW_INFINITE", "Infinity"); + enchantments.put("ARROW_KNOCKBACK", "Punch"); + enchantments.put("DAMAGE_ALL", "Sharpness"); + enchantments.put("DAMAGE_ARTHROPODS", "Bane_Of_Arthropods"); + enchantments.put("DAMAGE_UNDEAD", "Smite"); + enchantments.put("DEPTH_STRIDER", "Depth_Strider"); + enchantments.put("DIG_SPEED", "Efficiency"); + enchantments.put("DURABILITY", "Unbreaking"); + enchantments.put("FIRE_ASPECT", "Fire_Aspect"); + enchantments.put("KNOCKBACK", "KnockBack"); + enchantments.put("LOOT_BONUS_BLOCKS", "Fortune"); + enchantments.put("LOOT_BONUS_MOBS", "Looting"); + enchantments.put("LUCK", "Luck_Of_The_Sea"); + enchantments.put("LURE", "Lure"); + enchantments.put("OXYGEN", "Respiration"); + enchantments.put("PROTECTION_ENVIRONMENTAL", "Protection"); + enchantments.put("PROTECTION_EXPLOSIONS", "Blast_Protection"); + enchantments.put("PROTECTION_FALL", "Feather_Falling"); + enchantments.put("PROTECTION_FIRE", "Fire_Protection"); + enchantments.put("PROTECTION_PROJECTILE", "Projectile_Protection"); + enchantments.put("SILK_TOUCH", "Silk_Touch"); + enchantments.put("THORNS", "Thorns"); + enchantments.put("WATER_WORKER", "Aqua_Affinity"); + enchantments.put("BINDING_CURSE", "Curse_Of_Binding"); + enchantments.put("MENDING", "Mending"); + enchantments.put("FROST_WALKER", "Frost_Walker"); + enchantments.put("VANISHING_CURSE", "Curse_Of_Vanishing"); + enchantments.put("SWEEPING_EDGE", "Sweeping_Edge"); + enchantments.put("RIPTIDE", "Riptide"); + enchantments.put("CHANNELING", "Channeling"); + enchantments.put("IMPALING", "Impaling"); + enchantments.put("LOYALTY", "Loyalty"); + + return enchantments; + } + + /** + * Check if the parameter is an integer. + * + * @param value string to check. + * @return true if integer or false if not. + */ + private boolean isInt(String value) { + try { + Integer.parseInt(value); + } catch (NumberFormatException nfe) { + return false; + } + + return true; + } + + /** + * Get an item flag from string. + * + * @param flagString string to check. + * @return item flag or null. + */ + private ItemFlag getFlag(String flagString) { + for (ItemFlag flag : ItemFlag.values()) { + if (flag.name().equalsIgnoreCase(flagString)) return flag; + } + + return null; + } + + /** + * Add patterns to the item. + * + * @param stringPattern the pattern you wish to add. + */ + private void addPatterns(String stringPattern) { + try { + String[] split = stringPattern.split(":"); + + for (PatternType pattern : PatternType.values()) { + + if (split[0].equalsIgnoreCase(pattern.name()) || split[0].equalsIgnoreCase(pattern.getIdentifier())) { + DyeColor color = DyeUtils.getDyeColor(split[1]); + + if (color != null) addPattern(new Pattern(color, pattern)); + + break; + } + } + } catch (Exception ignored) {} + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/enums/ShopType.java b/paper/src/main/java/com/badbones69/crazyauctions/api/enums/ShopType.java index 6b02397..0b2bb3c 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/enums/ShopType.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/api/enums/ShopType.java @@ -9,7 +9,7 @@ public enum ShopType { /** * @param name name of the Shop Type. */ - private ShopType(String name) { + ShopType(String name) { this.name = name; } @@ -23,6 +23,7 @@ public enum ShopType { return type; } } + return null; } diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/support/PluginSupport.java b/paper/src/main/java/com/badbones69/crazyauctions/api/support/PluginSupport.java index 6e43927..5ab4646 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/support/PluginSupport.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/api/support/PluginSupport.java @@ -1,6 +1,7 @@ package com.badbones69.crazyauctions.api.support; import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; public enum PluginSupport { @@ -15,8 +16,7 @@ public enum PluginSupport { private final String name; - @NotNull - private final CrazyAuctions plugin = CrazyAuctions.get(); + private final @NotNull CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); PluginSupport(String name) { this.name = name; diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/support/SkullCreator.java b/paper/src/main/java/com/badbones69/crazyauctions/api/support/SkullCreator.java new file mode 100644 index 0000000..33a3b9c --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/api/support/SkullCreator.java @@ -0,0 +1,189 @@ +package com.badbones69.crazyauctions.api.support; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Skull; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Base64; +import java.util.UUID; + +/** + * A library for the Bukkit API to create player skulls + * from names, base64 strings, and texture URLs. + * Does not use any NMS code, and should work across all versions. + * + * @author Dean B on 12/28/2016. + */ +public class SkullCreator { + + private static final @NotNull CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + /** + * Creates a player skull with a UUID. 1.13 only. + * + * @param id The Player's UUID + * @return The head of the Player + */ + public static ItemStack itemFromUuid(UUID id) { + ItemStack item = getPlayerSkullItem(); + + return itemWithUuid(item, id); + } + + /** + * Creates a player skull based on a UUID. 1.13 only. + * + * @param item The item to apply the name to + * @param id The Player's UUID + * @return The head of the Player + */ + public static ItemStack itemWithUuid(ItemStack item, UUID id) { + notNull(item, "item"); + notNull(id, "id"); + + SkullMeta meta = (SkullMeta) item.getItemMeta(); + meta.setOwningPlayer(plugin.getServer().getOfflinePlayer(id)); + item.setItemMeta(meta); + + return item; + } + + /** + * Creates a player skull based on a Mojang server URL. + * + * @param url The URL of the Mojang skin + * @return The head associated with the URL + */ + public static ItemStack itemFromUrl(String url) { + ItemStack item = getPlayerSkullItem(); + + return itemWithUrl(item, url); + } + + /** + * Creates a player skull based on a Mojang server URL. + * + * @param item The item to apply the skin to + * @param url The URL of the Mojang skin + * @return The head associated with the URL + */ + public static ItemStack itemWithUrl(ItemStack item, String url) { + notNull(item, "item"); + notNull(url, "url"); + + return itemWithBase64(item, urlToBase64(url)); + } + + /** + * Creates a player skull based on a base64 string containing the link to the skin. + * + * @param base64 The base64 string containing the texture + * @return The head with a custom texture + */ + public static ItemStack itemFromBase64(String base64) { + ItemStack item = getPlayerSkullItem(); + + return itemWithBase64(item, base64); + } + + /** + * Applies the base64 string to the ItemStack. + * + * @param item The ItemStack to put the base64 onto + * @param base64 The base64 string containing the texture + * @return The head with a custom texture + */ + public static ItemStack itemWithBase64(ItemStack item, String base64) { + notNull(item, "item"); + notNull(base64, "base64"); + + UUID hashAsId = new UUID(base64.hashCode(), base64.hashCode()); + return plugin.getServer().getUnsafe().modifyItemStack(item, + "{SkullOwner:{Id:\"" + hashAsId + "\",Properties:{textures:[{Value:\"" + base64 + "\"}]}}}" + ); + } + + /** + * Sets the block to a skull with the given UUID. + * + * @param block The block to set + * @param id The player to set it to + */ + public static void blockWithUuid(Block block, UUID id) { + notNull(block, "block"); + notNull(id, "id"); + + setBlockType(block); + ((Skull) block.getState()).setOwningPlayer(Bukkit.getOfflinePlayer(id)); + } + + /** + * Sets the block to a skull with the given UUID. + * + * @param block The block to set + * @param url The mojang URL to set it to use + */ + public static void blockWithUrl(Block block, String url) { + notNull(block, "block"); + notNull(url, "url"); + + blockWithBase64(block, urlToBase64(url)); + } + + /** + * Sets the block to a skull with the given UUID. + * + * @param block The block to set + * @param base64 The base64 to set it to use + */ + public static void blockWithBase64(Block block, String base64) { + notNull(block, "block"); + notNull(base64, "base64"); + + UUID hashAsId = new UUID(base64.hashCode(), base64.hashCode()); + + String args = String.format( + "%d %d %d %s", + block.getX(), + block.getY(), + block.getZ(), + "{Owner:{Id:\"" + hashAsId + "\",Properties:{textures:[{Value:\"" + base64 + "\"}]}}}" + ); + + plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "data merge block " + args); + } + + private static ItemStack getPlayerSkullItem() { + return new ItemStack(Material.PLAYER_HEAD); + } + + private static void setBlockType(Block block) { + block.setType(Material.PLAYER_HEAD, false); + } + + private static void notNull(Object instance, String name) { + if (instance == null) { + throw new NullPointerException(name + " should not be null!"); + } + } + + private static String urlToBase64(String url) { + URI actualUrl; + + try { + actualUrl = new URI(url); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + + String toEncode = "{\"textures\":{\"SKIN\":{\"url\":\"" + actualUrl + "\"}}}"; + return Base64.getEncoder().encodeToString(toEncode.getBytes()); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/commands/AuctionCommand.java b/paper/src/main/java/com/badbones69/crazyauctions/commands/AuctionCommand.java index 98da5c1..0e92135 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/commands/AuctionCommand.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/commands/AuctionCommand.java @@ -346,11 +346,9 @@ public class AuctionCommand implements CommandExecutor { } } - for (String id : config.getStringList("Settings.BlackList")) { - if (item.getType() == Methods.makeItem(id, 1).getType()) { - player.sendMessage(Messages.ITEM_BLACKLISTED.getMessage()); - return true; - } + if (config.getStringList("Settings.BlackList").contains(item.getType().getKey().getKey())) { + player.sendMessage(Messages.ITEM_BLACKLISTED.getMessage()); + return true; } if (!config.getBoolean("Settings.Allow-Damaged-Items")) { diff --git a/paper/src/main/java/com/badbones69/crazyauctions/controllers/GuiListener.java b/paper/src/main/java/com/badbones69/crazyauctions/controllers/GuiListener.java index 1dce0f4..30cebc8 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/controllers/GuiListener.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/controllers/GuiListener.java @@ -4,6 +4,7 @@ import com.badbones69.crazyauctions.CrazyAuctions; import com.badbones69.crazyauctions.Methods; import com.badbones69.crazyauctions.api.*; import com.badbones69.crazyauctions.api.FileManager.Files; +import com.badbones69.crazyauctions.api.builders.ItemBuilder; import com.badbones69.crazyauctions.api.enums.Category; import com.badbones69.crazyauctions.api.enums.Reaons; import com.badbones69.crazyauctions.api.enums.Messages; @@ -12,6 +13,7 @@ import com.badbones69.crazyauctions.api.events.AuctionBuyEvent; import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent; import com.badbones69.crazyauctions.api.events.AuctionNewBidEvent; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.SoundCategory; import org.bukkit.configuration.file.FileConfiguration; @@ -24,7 +26,6 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -72,15 +73,23 @@ public class GuiListener implements Listener { for (String l : config.getStringList("Settings.GUISettings.Bidding")) { lore.add(l.replace("%TopBid%", Methods.getPrice(i, false)).replace("%topbid%", Methods.getPrice(i, false)).replace("%Seller%", seller).replace("%seller%", seller).replace("%TopBidder%", topbidder).replace("%topbidder%", topbidder).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); } - items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); - ID.add(data.getInt("Items." + i + ".StoreID")); + + ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getItemStack("Items." + i + ".Item")); + + lore.forEach(itemBuilder::addLore); + + ID.add(data.getInt("Items." + i + ".StoreID"));; } } else { if (sell == ShopType.SELL) { for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) { lore.add(l.replace("%Price%", String.format(Locale.ENGLISH, "%,d", Long.parseLong(Methods.getPrice(i, false)))).replace("%price%", String.format(Locale.ENGLISH, "%,d", Long.parseLong(Methods.getPrice(i, false)))).replace("%Seller%", data.getString("Items." + i + ".Seller")).replace("%seller%", data.getString("Items." + i + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); } - items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); + + ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getItemStack("Items." + i + ".Item")); + + lore.forEach(itemBuilder::addLore); + ID.add(data.getInt("Items." + i + ".StoreID")); } } @@ -135,13 +144,16 @@ public class GuiListener implements Listener { int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot"); String cName = Methods.color(config.getString("Settings.GUISettings.Category-Settings." + shopCategory.get(player.getUniqueId()).getName() + ".Name")); + ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1); + if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) { for (String l : config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")) { lore.add(l.replace("%Category%", cName).replace("%category%", cName)); } - inv.setItem(slot - 1, Methods.makeItem(id, 1, name, lore)); + + inv.setItem(slot - 1, itemBuilder.setLore(lore).build()); } else { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); + inv.setItem(slot - 1, itemBuilder.setLore(lore).build()); } } @@ -183,11 +195,14 @@ public class GuiListener implements Listener { String id = config.getString("Settings.GUISettings." + o + ".Item"); String name = config.getString("Settings.GUISettings." + o + ".Name"); int slot = config.getInt("Settings.GUISettings." + o + ".Slot"); + + ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1); + if (config.contains("Settings.GUISettings." + o + ".Lore")) { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings." + o + ".Lore"))); - } else { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); + itemBuilder.setLore(config.getStringList("Settings.GUISettings." + o + ".Lore")); } + + inv.setItem(slot - 1, itemBuilder.build()); } shopType.put(player.getUniqueId(), shop); @@ -217,11 +232,14 @@ public class GuiListener implements Listener { String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item"); String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot"); + + ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1); + if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore"))); - } else { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); + itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")); } + + inv.setItem(slot - 1, itemBuilder.build()); } if (data.contains("Items")) { @@ -231,7 +249,11 @@ public class GuiListener implements Listener { for (String l : config.getStringList("Settings.GUISettings.CurrentLore")) { lore.add(l.replace("%Price%", Methods.getPrice(i, false)).replace("%price%", Methods.getPrice(i, false)).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); } - items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); + + ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getItemStack("Items." + i + ".Item")); + + lore.forEach(itemBuilder::addLore); + ID.add(data.getInt("Items." + i + ".StoreID")); } } @@ -262,7 +284,11 @@ public class GuiListener implements Listener { for (String l : config.getStringList("Settings.GUISettings.Cancelled/ExpiredLore")) { lore.add(l.replace("%Price%", Methods.getPrice(i, true)).replace("%price%", Methods.getPrice(i, true)).replace("%Time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time"))).replace("%time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time")))); } - items.add(Methods.addLore(data.getItemStack("OutOfTime/Cancelled." + i + ".Item").clone(), lore)); + + ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getItemStack("OutOfTime/Cancelled." + i + ".Item")); + + lore.forEach(itemBuilder::addLore); + ID.add(data.getInt("OutOfTime/Cancelled." + i + ".StoreID")); } } @@ -291,11 +317,14 @@ public class GuiListener implements Listener { String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item"); String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot"); + + ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1); + if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore"))); - } else { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); + itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")); } + + inv.setItem(slot - 1, itemBuilder.build()); } for (ItemStack item : Methods.getPage(items, page)) { @@ -331,12 +360,14 @@ public class GuiListener implements Listener { String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); ItemStack item; + ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1); + if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) { - item = Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")); - } else { - item = Methods.makeItem(id, 1, name); + itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")).build(); } + item = itemBuilder.build(); + if (o.equals("Confirm")) { inv.setItem(0, item); inv.setItem(1, item); @@ -358,7 +389,12 @@ public class GuiListener implements Listener { lore.add(l.replace("%Price%", Methods.getPrice(ID, false)).replace("%price%", Methods.getPrice(ID, false)).replace("%Seller%", data.getString("Items." + ID + ".Seller")).replace("%seller%", data.getString("Items." + ID + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + l + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + l + ".Time-Till-Expire")))); } - inv.setItem(4, Methods.addLore(item.clone(), lore)); + ItemBuilder itemBuilder = ItemBuilder.convertItemStack(item); + + lore.forEach(itemBuilder::addLore); + + inv.setItem(4, itemBuilder.build()); + IDs.put(player.getUniqueId(), ID); player.openInventory(inv); } @@ -377,19 +413,21 @@ public class GuiListener implements Listener { Inventory inv = plugin.getServer().createInventory(null, 27, Methods.color(config.getString("Settings.Bidding-On-Item"))); if (!bidding.containsKey(player.getUniqueId())) bidding.put(player.getUniqueId(), 0); - inv.setItem(9, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+1")); - inv.setItem(10, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+10")); - inv.setItem(11, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+100")); - inv.setItem(12, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+1000")); - inv.setItem(14, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-1000")); - inv.setItem(15, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-100")); - inv.setItem(16, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-10")); - inv.setItem(17, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-1")); - + inv.setItem(9, new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName("&a+1").setAmount(1).build()); + inv.setItem(10, new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName("&a+10").setAmount(1).build()); + inv.setItem(11, new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName("&a+100").setAmount(1).build()); + inv.setItem(12, new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName("&a+1000").setAmount(1).build()); + inv.setItem(14, new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName("&c-1000").setAmount(1).build()); + inv.setItem(15, new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName("&c-100").setAmount(1).build()); + inv.setItem(16, new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName("&c-10").setAmount(1).build()); + inv.setItem(17, new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName("&c-1").setAmount(1).build()); inv.setItem(13, getBiddingGlass(player, ID)); - inv.setItem(22, Methods.makeItem(config.getString("Settings.GUISettings.OtherSettings.Bid.Item"), 1, config.getString("Settings.GUISettings.OtherSettings.Bid.Name"), config.getStringList("Settings.GUISettings.OtherSettings.Bid.Lore"))); + + inv.setItem(22, new ItemBuilder().setMaterial(config.getString("Settings.GUISettings.OtherSettings.Bid.Item")).setAmount(1) + .setName("Settings.GUISettings.OtherSettings.Bid.Name").setLore(config.getStringList("Settings.GUISettings.OtherSettings.Bid.Lore")).build()); inv.setItem(4, getBiddingItem(ID)); + player.openInventory(inv); } @@ -421,7 +459,11 @@ public class GuiListener implements Listener { lore.add(l.replace("%Price%", Methods.getPrice(i, false)).replace("%price%", Methods.getPrice(i, false)).replace("%Seller%", data.getString("Items." + i + ".Seller")).replace("%seller%", data.getString("Items." + i + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); } } - items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); + + ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getItemStack("Items." + i + ".Item")); + + lore.forEach(itemBuilder::addLore); + ID.add(data.getInt("Items." + i + ".StoreID")); } } @@ -446,11 +488,13 @@ public class GuiListener implements Listener { String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot"); + ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1); + if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore"))); - } else { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); + itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")); } + + inv.setItem(slot - 1, itemBuilder.build()); } for (ItemStack item : Methods.getPage(items, page)) { @@ -467,7 +511,8 @@ public class GuiListener implements Listener { String id = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item"); String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name"); - ItemStack item; + + ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1); int bid = bidding.get(player.getUniqueId()); @@ -476,12 +521,11 @@ public class GuiListener implements Listener { for (String l : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) { lore.add(l.replace("%Bid%", bid + "").replace("%bid%", bid + "").replace("%TopBid%", Methods.getPrice(ID, false)).replace("%topbid%", Methods.getPrice(ID, false))); } - item = Methods.makeItem(id, 1, name, lore); - } else { - item = Methods.makeItem(id, 1, name); + + itemBuilder.setLore(lore); } - return item; + return itemBuilder.build(); } private static ItemStack getBiddingItem(String ID) { @@ -496,7 +540,11 @@ public class GuiListener implements Listener { lore.add(l.replace("%TopBid%", Methods.getPrice(ID, false)).replace("%topbid%", Methods.getPrice(ID, false)).replace("%Seller%", seller).replace("%seller%", seller).replace("%TopBidder%", topbidder).replace("%topbidder%", topbidder).replace("%Time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire")))); } - return Methods.addLore(item.clone(), lore); + ItemBuilder itemBuilder = ItemBuilder.convertItemStack(item); + + lore.forEach(itemBuilder::addLore); + + return itemBuilder.build(); } private static void playClick(Player player) { @@ -769,17 +817,16 @@ public class GuiListener implements Listener { final Runnable runnable = () -> inv.setItem(slot, item); if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { - String it = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Item"); + String itemName = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Item"); String name = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name"); - ItemStack I; + + ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1); if (config.contains("Settings.GUISettings.OtherSettings.Your-Item.Lore")) { - I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Your-Item.Lore")); - } else { - I = Methods.makeItem(it, 1, name); + itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings.Your-Item.Lore")); } - inv.setItem(slot, I); + inv.setItem(slot, itemBuilder.build()); playClick(player); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); return; @@ -788,17 +835,16 @@ public class GuiListener implements Listener { long cost = data.getLong("Items." + i + ".Price"); if (plugin.getSupport().getMoney(player) < cost) { - String it = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Item"); + String itemName = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Item"); String name = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name"); - ItemStack I; + + ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1); if (config.contains("Settings.GUISettings.OtherSettings.Cant-Afford.Lore")) { - I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Cant-Afford.Lore")); - } else { - I = Methods.makeItem(it, 1, name); + itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings.Cant-Afford.Lore")); } - inv.setItem(slot, I); + inv.setItem(slot, itemBuilder.build()); playClick(player); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); return; @@ -806,17 +852,16 @@ public class GuiListener implements Listener { if (data.getBoolean("Items." + i + ".Biddable")) { if (player.getName().equalsIgnoreCase(data.getString("Items." + i + ".TopBidder"))) { - String it = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Item"); + String itemName = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Item"); String name = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name"); - ItemStack I; + + ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1); if (config.contains("Settings.GUISettings.OtherSettings.Top-Bidder.Lore")) { - I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Top-Bidder.Lore")); - } else { - I = Methods.makeItem(it, 1, name); + itemBuilder.setLore( config.getStringList("Settings.GUISettings.OtherSettings.Top-Bidder.Lore")); } - inv.setItem(slot, I); + inv.setItem(slot, itemBuilder.build()); playClick(player); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); return; diff --git a/paper/src/main/java/com/ryderbelserion/crazyauctions/CrazyAuctionsPaper.java b/paper/src/main/java/com/ryderbelserion/crazyauctions/CrazyAuctionsPaper.java deleted file mode 100644 index 4bb504f..0000000 --- a/paper/src/main/java/com/ryderbelserion/crazyauctions/CrazyAuctionsPaper.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.ryderbelserion.crazyauctions; - -import com.ryderbelserion.cluster.ClusterPackage; -import com.ryderbelserion.crazyauctions.platform.PaperServer; -import org.bukkit.plugin.java.JavaPlugin; - -public class CrazyAuctionsPaper extends JavaPlugin { - - private CrazyAuctions crazyAuctions; - - @Override - public void onEnable() { - this.crazyAuctions = new CrazyAuctions(new PaperServer()); - - new ClusterPackage(this, true); - } - - @Override - public void onDisable() { - if (this.crazyAuctions != null) { - this.crazyAuctions.disable(); - } - } - - public CrazyAuctions getCrazyAuctions() { - return this.crazyAuctions; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/ryderbelserion/crazyauctions/platform/PaperServer.java b/paper/src/main/java/com/ryderbelserion/crazyauctions/platform/PaperServer.java deleted file mode 100644 index 85e6729..0000000 --- a/paper/src/main/java/com/ryderbelserion/crazyauctions/platform/PaperServer.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ryderbelserion.crazyauctions.platform; - -import com.ryderbelserion.crazyauctions.CrazyAuctionsPaper; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import java.io.File; - -public class PaperServer implements Server { - - @NotNull - private final CrazyAuctionsPaper plugin = JavaPlugin.getPlugin(CrazyAuctionsPaper.class); - - @Override - public File getFolder() { - return this.plugin.getDataFolder(); - } -} \ No newline at end of file diff --git a/paper/src/main/resources/plugin.yml b/paper/src/main/resources/plugin.yml index bfd98a7..057516b 100644 --- a/paper/src/main/resources/plugin.yml +++ b/paper/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: '${name}' -main: '${group}.CrazyAuctionsPaper' +main: '${group}.CrazyAuctions' authors: ${authors} @@ -8,4 +8,8 @@ api-version: '${apiVersion}' description: '${description}' website: '${website}' -softdepend: [Vault] \ No newline at end of file +softdepend: [Vault] + +commands: + crazyauctions: + description: The base command for CrazyAuctions. \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index eb409c1..824a9c3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,5 @@ +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") + pluginManagement { repositories { maven("https://repo.papermc.io/repository/maven-public/") @@ -7,51 +9,6 @@ pluginManagement { } } -dependencyResolutionManagement { - repositories { - maven("https://repo.papermc.io/repository/maven-public/") - - gradlePluginPortal() - mavenCentral() - } - - versionCatalogs { - create("libs") { - version("adventure4", "4.16.0") - version("cluster", "6.3") - version("cloud", "1.8.4") - - library("holographicdisplays", "me.filoghost.holographicdisplays", "holographicdisplays-api").version("3.0.0") - library("decentholograms", "com.github.decentsoftware-eu", "decentholograms").version("2.8.6") - - library("triumphcmds", "dev.triumphteam", "triumph-cmd-bukkit").version("2.0.0-SNAPSHOT") - library("triumphgui", "dev.triumphteam", "triumph-gui").version("3.1.7") - - library("cluster_paper", "com.ryderbelserion.cluster", "paper").versionRef("cluster") - library("cluster_api", "com.ryderbelserion.cluster", "paper").versionRef("cluster") - - library("cloud_core", "cloud.commandframework", "cloud-core").versionRef("cloud") - library("cloud_brig", "cloud.commandframework", "cloud-brigadier").versionRef("cloud") - library("cloud_paper", "cloud.commandframework", "cloud-paper").versionRef("cloud") - library("cloud_extras", "cloud.commandframework", "cloud-minecraft-extras").versionRef("cloud") - - library("adventure4", "net.kyori", "adventure-text-minimessage").versionRef("adventure4") - library("minimessage4", "net.kyori", "adventure-api").versionRef("adventure4") - - library("itemsadder", "com.github.LoneDev6", "api-itemsadder").version("3.6.1") - - library("placeholderapi", "me.clip", "placeholderapi").version("2.11.5") - library("vault", "com.github.MilkBowl", "VaultAPI").version("1.7.1") - library("metrics", "org.bstats", "bstats-bukkit").version("3.0.2") - library("oraxen", "io.th0rgal", "oraxen").version("1.164.0") - library("configme", "ch.jalu", "configme").version("1.4.1") - - bundle("adventure", listOf("adventure4", "minimessage4")) - } - } -} - rootProject.name = "CrazyAuctions" -include("paper") -include("common") \ No newline at end of file +include(":paper") \ No newline at end of file