From a1bc9a041cabb29651563147f6965cf22ca39f40 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Mon, 21 Aug 2023 03:03:49 -0400 Subject: [PATCH 1/7] [ci-skip] delete .github --- .fleet/settings.json | 3 --- .github/FUNDING.yml | 2 -- .github/ISSUE_TEMPLATE/bug_report.md | 26 -------------------------- .github/auto-assign.yml | 26 -------------------------- .github/workflows/auto-assign.yml | 14 -------------- 5 files changed, 71 deletions(-) delete mode 100644 .fleet/settings.json delete mode 100644 .github/FUNDING.yml delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md delete mode 100644 .github/auto-assign.yml delete mode 100644 .github/workflows/auto-assign.yml diff --git a/.fleet/settings.json b/.fleet/settings.json deleted file mode 100644 index 06b604c..0000000 --- a/.fleet/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "java.home": "C:/Program Files/Eclipse Adoptium/jdk-17.0.4.101-hotspot/bin" -} \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 4a72181..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,2 +0,0 @@ -github: Crazy-Crew -open_collective: CrazyCrew \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 2214b42..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: "[Bug Report] " -labels: '' -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**Versions (please complete the following information):** - - Minecraft Server Version: [e.g. 1.19] - - Plugin Version: [e.g. 1.2.18-SNAPSHOT] - -*Do **NOT** say Latest use `/version crazyauctions` in the console. - -**Pastebin any errors in console** -Link: https://mclo.gs/ - -**Issue** -Describe the issue you are having with the plugin. - -**Screenshots** -If applicable, add screenshots to help explain your problem. diff --git a/.github/auto-assign.yml b/.github/auto-assign.yml deleted file mode 100644 index b56891e..0000000 --- a/.github/auto-assign.yml +++ /dev/null @@ -1,26 +0,0 @@ -# Set to true to add reviewers to PRs -addReviewers: true - -# Set to 'author' to add PR's author as an assignee -addAssignees: author - -# A list of reviewers to be added to PRs (GitHub username) -reviewers: - - RyderBelserion - -# A number of reviewers added to the PR -# Set 0 to add all the reviewers (default: 0) -numberOfReviewers: 1 - -# A list of assignees, overrides reviewers if set -assignees: - - RyderBelserion - -# A number of assignees to add to the PRs -# Set to 0 to add all the assignees. -# Uses numberOfReviewers if unset. -numberOfAssignees: 0 - -# A list of keywords to be skipped the process if PR's title include it -skipKeywords: - - wip \ No newline at end of file diff --git a/.github/workflows/auto-assign.yml b/.github/workflows/auto-assign.yml deleted file mode 100644 index 0453a83..0000000 --- a/.github/workflows/auto-assign.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Auto Assign -on: - issues: - types: [opened] - pull_request: - types: [opened] -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: wow-actions/auto-assign@v1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CONFIG_FILE: .github/auto-assign.yml \ No newline at end of file From f6182d3b3e97a04a2bab20b175529f842b358dc6 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Mon, 21 Aug 2023 14:06:07 -0400 Subject: [PATCH 2/7] add actual v1 code --- .gitignore | 17 +- README.md | 120 +- build.gradle.kts | 80 -- gradle/libs.versions.toml | 30 - gradle/wrapper/gradle-wrapper.properties | 5 - pom.xml | 116 ++ settings.gradle.kts | 3 - .../crazyauctions/CrazyAuctions.java | 72 - .../com/badbones69/crazyauctions/Main.java | 479 +++++++ .../com/badbones69/crazyauctions/Methods.java | 436 +++++- .../com/badbones69/crazyauctions/Starter.java | 50 - .../AuctionCategories.java => Category.java} | 208 ++- .../{CrazyManager.java => CrazyAuctions.java} | 36 +- .../crazyauctions/api/FileManager.java | 307 ++-- .../api/{enums => }/Messages.java | 79 +- .../crazyauctions/api/ShopType.java | 36 + .../badbones69/crazyauctions/api/Version.java | 128 ++ .../crazyauctions/api/economy/Currency.java | 48 - .../api/economy/CurrencyAPI.java | 158 --- .../api/economy/vault/VaultSupport.java | 25 - .../api/enums/CancelledReason.java | 1 + .../api/enums/ShopCategories.java | 92 -- .../api/events/AuctionBuyEvent.java | 18 +- .../api/events/AuctionCancelledEvent.java | 17 +- .../api/events/AuctionExpireEvent.java | 15 +- .../api/events/AuctionListEvent.java | 24 +- .../api/events/AuctionNewBidEvent.java | 15 +- .../api/events/AuctionWinBidEvent.java | 16 +- .../crazyauctions/controllers/DupePatch.java | 22 + .../crazyauctions/controllers/GUI.java | 950 +++++++++++++ .../currency/CurrencyManager.java | 119 ++ .../crazyauctions/currency/Vault.java | 57 + .../crazyauctions/utils/ItemBuilder.java | 1261 ----------------- .../crazyauctions/utils/SkullCreator.java | 275 ---- .../utils/func/PluginSupport.java | 27 - .../utils/func/ServerProtocol.java | 120 -- src/main/resources/config1.12.2-Down.yml | 306 ++++ .../{config.yml => config1.13-Up.yml} | 2 + src/main/resources/plugin.yml | 26 +- 39 files changed, 3039 insertions(+), 2757 deletions(-) delete mode 100644 build.gradle.kts delete mode 100644 gradle/libs.versions.toml delete mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 pom.xml delete mode 100644 settings.gradle.kts delete mode 100644 src/main/java/com/badbones69/crazyauctions/CrazyAuctions.java create mode 100644 src/main/java/com/badbones69/crazyauctions/Main.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/Starter.java rename src/main/java/com/badbones69/crazyauctions/api/{enums/AuctionCategories.java => Category.java} (51%) rename src/main/java/com/badbones69/crazyauctions/api/{CrazyManager.java => CrazyAuctions.java} (69%) rename src/main/java/com/badbones69/crazyauctions/api/{enums => }/Messages.java (77%) create mode 100644 src/main/java/com/badbones69/crazyauctions/api/ShopType.java create mode 100644 src/main/java/com/badbones69/crazyauctions/api/Version.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/api/economy/Currency.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/api/economy/CurrencyAPI.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/api/economy/vault/VaultSupport.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/api/enums/ShopCategories.java create mode 100644 src/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java create mode 100644 src/main/java/com/badbones69/crazyauctions/controllers/GUI.java create mode 100644 src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java create mode 100644 src/main/java/com/badbones69/crazyauctions/currency/Vault.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/utils/ItemBuilder.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/utils/SkullCreator.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/utils/func/PluginSupport.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/utils/func/ServerProtocol.java create mode 100644 src/main/resources/config1.12.2-Down.yml rename src/main/resources/{config.yml => config1.13-Up.yml} (99%) diff --git a/.gitignore b/.gitignore index ce181e5..72db3d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,14 @@ -.idea -.gradle -build \ No newline at end of file + +\.idea/ + +*.iml + +*.class + +target/classes/ + +target/ + +\.DS_Store + +dependency-reduced-pom.xml diff --git a/README.md b/README.md index dd15306..07ed220 100644 --- a/README.md +++ b/README.md @@ -1,111 +1,41 @@ -
+## Crazy Auctions -[![CrazyAuctions](https://raw.githubusercontent.com/RyderBelserion/Assets/main/crazycrew/banners/CrazyAuctions.png)](https://www.spigotmc.org/resources/crazy-crates.17599/) +[![Join us on Discord](https://img.shields.io/discord/182615261403283459.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.badbones69.com) -
+[![CrazyAuctions's Stargazers](https://img.shields.io/github/stars/Crazy-Crew/Crazy-Auctions?label=stars&logo=github)](https://github.com/Crazy-Crew/Crazy-Auctions/stargazers) +[![CrazyAuctions's Forks](https://img.shields.io/github/forks/Crazy-Crew/Crazy-Auctions?label=forks&logo=github)](https://github.com/Crazy-Crew/Crazy-Auctions/network/members) +[![CrazyAuctions's Watchers](https://img.shields.io/github/watchers/Crazy-Crew/Crazy-Auctions?label=watchers&logo=github)](https://github.com/Crazy-Crew/Crazy-Auctions/watchers) -[![Contributors][contributors-shield]][contributors-url] -[![Forks][forks-shield]][forks-url] -[![Stargazers][stars-shield]][stars-url] -[![Issues][issues-shield]][issues-url] -[![GPU License][license-shield]][license-url] -[![Contact][discord-shield]][discord-url] -![CodeFactor][codefactor-shield] +CrazyAuctions is a simple auctions plugin where you can sell your items and bid on other items! - - - +## Contact +[![Join us on Discord](https://img.shields.io/discord/182615261403283459.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.badbones69.com) -

- A simple auctions plugin where you can sell your items and bid on other items! -
- Explore the docs » -
-
- Report Bug - · - Request Feature - · - Get Support -

-
- - -
- Table of Contents -
    -
  1. - Getting Started - -
  2. -
  3. Roadmap
  4. -
  5. Contributing
  6. -
  7. License
  8. -
  9. Contact
  10. -
-
+Join us on [Discord](https://discord.badbones69.com) ## Downloads -#### Stable Builds -https://modrinth.com/plugin/crazyauctions ( Soon ) +[![Build Status](https://jenkins.badbones69.com/view/Stable/job/Crazy-Auctions/badge/icon)](https://jenkins.badbones69.com/view/Stable/job/Crazy-Auctions/) -#### Beta Builds -https://ci.badbones69.com/view/Beta/job/CrazyAuctions-Beta/ +Downloads can be obtained from the [spigot page](https://www.spigotmc.org/resources/crazy-auctions.25219/) or the [Jenkins](https://jenkins.badbones69.com/view/Stable/job/Crazy-Auctions/). -## Getting Started +## Plugin Data +[![bStats Graph Data](https://bstats.org/signatures/bukkit/CrazyAuctions.svg)](https://bstats.org/plugin/bukkit/CrazyAuctions/4624) -How to get started with contributing / maintaining your own version of CrazyAuctions! +## API +In Progress. -### Prerequisites +### Dependency Information -A list of things necessary to make sure you can build CrazyAuctions properly. -* Intellij IDEA - * https://www.jetbrains.com/idea/download/ -* Gradle +#### Maven +In Progress. -### Installation +#### Gradle +In Progress. -1. Clone the repo - ```sh - git clone https://github.com/Crazy-Crew/CrazyAuctions.git - ``` -2. Open the repository using Intellij IDEA & wait until it finishes downloading/indexing. -3. Run the shadowJar task. - ```gradle - ./gradlew shadowJar or gradle shadowJar - ``` +## Working with CrazyAuctions. -## Roadmap +#### Contributing +Fork the project & open a pull request. -Check our public [trello board](https://trello.com/b/bzQ5TwXo) for our current plans, any bugs and general tracking of the project progress. - -## Contributing - -1. Fork the Project -2. Create your Feature Branch (`git checkout -b feature/yourfeature`) -3. Commit your Changes (`git commit -m 'your amazing feature.'`) -4. Push to the Branch (`git push`) -5. Open a Pull Request - -## License - -Distributed under the MIT License. See [`LICENSE`](/LICENSE) for more information. - -[discord-shield]: https://img.shields.io/discord/182615261403283459.svg?style=for-the-badge -[discord-url]: https://discord.gg/crazycrew - -[contributors-shield]: https://img.shields.io/github/contributors/Crazy-Crew/CrazyAuctions.svg?style=for-the-badge -[contributors-url]: https://github.com/Crazy-Crew/CrazyAuctions/graphs/contributors -[forks-shield]: https://img.shields.io/github/forks/Crazy-Crew/CrazyAuctions.svg?style=for-the-badge -[forks-url]: https://github.com/Crazy-Crew/CrazyAuctions/network/members -[stars-shield]: https://img.shields.io/github/stars/Crazy-Crew/CrazyAuctions.svg?style=for-the-badge -[stars-url]: https://github.com/Crazy-Crew/CrazyAuctions/stargazers -[issues-shield]: https://img.shields.io/github/issues/Crazy-Crew/CrazyAuctions.svg?style=for-the-badge -[issues-url]: https://github.com/Crazy-Crew/CrazyAuctions/issues -[license-shield]: https://img.shields.io/github/license/Crazy-Crew/CrazyAuctions.svg?style=for-the-badge -[license-url]: https://github.com/Crazy-Crew/CrazyAuctions/blob/master/LICENSE.MD - -[codefactor-shield]: https://img.shields.io/codefactor/grade/github/crazy-crew/CrazyAuctions/main?style=for-the-badge \ No newline at end of file +#### Compiling +Clone the project & run the install task. diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index 454b621..0000000 --- a/build.gradle.kts +++ /dev/null @@ -1,80 +0,0 @@ -plugins { - java - - id("com.github.johnrengelman.shadow") version "7.1.2" -} - -val buildNumber: String? = System.getenv("BUILD_NUMBER") - -val jenkinsVersion = "1.2.18-b$buildNumber" - -group = "com.badbones69.crazyauctions" -version = "1.2.18" -description = "A simple auctions plugin where you can sell your items and bid on other items! " - -repositories { - /** - * Paper Team - */ - maven("https://repo.papermc.io/repository/maven-public/") - - /** - * NBT Team - */ - maven("https://repo.codemc.org/repository/maven-public/") - - /** - * Everything else we need. - */ - maven("https://jitpack.io/") - - mavenCentral() -} - -dependencies { - implementation(libs.bukkit.bstats) - - implementation(libs.nbt.api) - - compileOnly(libs.reserve.api) - - compileOnly(libs.vault.api) - - compileOnly(libs.paper) -} - -java { - toolchain.languageVersion.set(JavaLanguageVersion.of(17)) -} - -tasks { - shadowJar { - if (buildNumber != null) { - archiveFileName.set("${rootProject.name}-[v${jenkinsVersion}].jar") - } else { - archiveFileName.set("${rootProject.name}-[v${rootProject.version}].jar") - } - - listOf( - "de.tr7zw", - "org.bstats" - ).forEach { - relocate(it, "${rootProject.group}.plugin.lib.$it") - } - } - - compileJava { - options.release.set(17) - } - - processResources { - filesMatching("plugin.yml") { - expand( - "name" to rootProject.name, - "group" to rootProject.group, - "version" to rootProject.version, - "description" to rootProject.description - ) - } - } -} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml deleted file mode 100644 index 4f9523f..0000000 --- a/gradle/libs.versions.toml +++ /dev/null @@ -1,30 +0,0 @@ -[versions] - -# Paper Team -paper = "1.19.2-R0.1-SNAPSHOT" - -# Bukkit -bukkit-bstats = "3.0.0" - -# Placeholders -placeholder-api = "2.11.2" - -# Misc Libraries -nbt-api = "2.10.0" -vault-api = "1.7" -reserve-api = "0.1.5.0" - -[libraries] - -# Paper Team -paper = { module = "io.papermc.paper:paper-api", version.ref = "paper" } - -# Bukkit -bukkit-bstats = { module = "org.bstats:bstats-bukkit", version.ref = "bukkit-bstats" } - -# Misc Libraries -vault-api = { module = "com.github.MilkBowl:VaultAPI", version.ref = "vault-api" } - -nbt-api = { module = "de.tr7zw:nbt-data-api", version.ref = "nbt-api" } - -reserve-api = { module = "net.tnemc:Reserve", version.ref = "reserve-api" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index ae04661..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d3a603e --- /dev/null +++ b/pom.xml @@ -0,0 +1,116 @@ + + + 4.0.0 + + com.badbones69 + crazyauctions + 1.2.19 + Crazy-Auctions + + + UTF-8 + + + + + + + crazycrew-repo-releases + CrazyCrew Team + https://repo.badbones69.com/releases + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + vault-repo + http://nexus.hc.to/content/repositories/pub_releases + + + codemc-repo + https://repo.codemc.io/repository/maven-public/ + + + + + + org.spigotmc + spigot-api + 1.19.3-R0.1-SNAPSHOT + provided + + + net.milkbowl.vault + VaultAPI + 1.7 + provided + + + bukkit + org.bukkit + + + + + net.tnemc + Reserve + 0.1.5.0 + provided + + + org.bstats + bstats-bukkit + 3.0.0 + provided + + + + + ${project.name}-[v${project.version}] + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + + org.bstats + + com.badbones69.crazyauctions.libraries + + + + + + package + + shade + + + + + + + \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts deleted file mode 100644 index 8b522d1..0000000 --- a/settings.gradle.kts +++ /dev/null @@ -1,3 +0,0 @@ -rootProject.name = "CrazyAuctions" - -enableFeaturePreview("VERSION_CATALOGS") \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/CrazyAuctions.java b/src/main/java/com/badbones69/crazyauctions/CrazyAuctions.java deleted file mode 100644 index 1980b26..0000000 --- a/src/main/java/com/badbones69/crazyauctions/CrazyAuctions.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.badbones69.crazyauctions; - -import com.badbones69.crazyauctions.api.CrazyManager; -import com.badbones69.crazyauctions.api.FileManager; -import com.badbones69.crazyauctions.api.FileManager.Files; -import org.bukkit.event.Listener; -import org.bukkit.plugin.java.JavaPlugin; - -public class CrazyAuctions extends JavaPlugin implements Listener { - - private static CrazyAuctions plugin; - - private Starter starter; - - private final FileManager fileManager = getStarter().getFileManager(); - - private final CrazyManager crazyManager = getStarter().getCrazyManager(); - - private final Methods methods = getStarter().getMethods(); - - private boolean isEnabled = false; - - @Override - public void onEnable() { - try { - plugin = this; - - starter = new Starter(); - - starter.run(); - - fileManager.setup(); - - crazyManager.load(); - - // methods.updateAuction(); - } catch (Exception e) { - e.printStackTrace(); - - isEnabled = false; - - return; - } - - isEnabled = true; - - enable(); - } - - @Override - public void onDisable() { - if (!isEnabled) return; - - disable(); - } - - private void enable() { - - } - - private void disable() { - Files.DATA.saveFile(); - } - - public static CrazyAuctions getPlugin() { - return plugin; - } - - public Starter getStarter() { - return starter; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/Main.java b/src/main/java/com/badbones69/crazyauctions/Main.java new file mode 100644 index 0000000..eb29de7 --- /dev/null +++ b/src/main/java/com/badbones69/crazyauctions/Main.java @@ -0,0 +1,479 @@ +package com.badbones69.crazyauctions; + +import com.badbones69.crazyauctions.api.*; +import com.badbones69.crazyauctions.api.FileManager.Files; +import com.badbones69.crazyauctions.api.events.AuctionListEvent; +import com.badbones69.crazyauctions.controllers.DupePatch; +import com.badbones69.crazyauctions.controllers.GUI; +import com.badbones69.crazyauctions.currency.Vault; +import org.bstats.bukkit.Metrics; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; +import org.bukkit.permissions.PermissionAttachmentInfo; +import org.bukkit.plugin.java.JavaPlugin; +import org.yaml.snakeyaml.error.YAMLException; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Random; + +public class Main extends JavaPlugin implements Listener { + + public static FileManager fileManager = FileManager.getInstance(); + public static CrazyAuctions crazyAuctions = CrazyAuctions.getInstance(); + + @Override + public void onEnable() { + fileManager.logInfo(true).setup(this); + crazyAuctions.loadCrazyAuctions(); + Bukkit.getServer().getPluginManager().registerEvents(this, this); + Bukkit.getServer().getPluginManager().registerEvents(new GUI(), this); + Bukkit.getServer().getPluginManager().registerEvents(new DupePatch(), this); + Methods.updateAuction(); + startCheck(); + + if (!Vault.setupEconomy()) { saveDefaultConfig(); } + + Messages.addMissingMessages(); + new Metrics(this, 4624); //Starts up bStats + } + + @Override + public void onDisable() { + int file = 0; + Bukkit.getScheduler().cancelTask(file); + Files.DATA.saveFile(true); + } + + public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args) { + if (commandLable.equalsIgnoreCase("CrazyAuctions") || commandLable.equalsIgnoreCase("CrazyAuction") || commandLable.equalsIgnoreCase("CA") || commandLable.equalsIgnoreCase("AH") || commandLable.equalsIgnoreCase("HDV")) { + if (args.length == 0) { + if (!Methods.hasPermission(sender, "Access")) return true; + if (!(sender instanceof Player)) { + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); + return true; + } + Player player = (Player) sender; + if (Files.CONFIG.getFile().contains("Settings.Category-Page-Opens-First")) { + if (Files.CONFIG.getFile().getBoolean("Settings.Category-Page-Opens-First")) { + GUI.openCategories(player, ShopType.SELL); + return true; + } + } + if (crazyAuctions.isSellingEnabled()) { + GUI.openShop(player, ShopType.SELL, Category.NONE, 1); + } else if (crazyAuctions.isBiddingEnabled()) { + GUI.openShop(player, ShopType.BID, Category.NONE, 1); + } else { + player.sendMessage(Methods.getPrefix() + Methods.color("&cThe bidding and selling options are both disabled. Please contact the admin about this.")); + } + return true; + } + if (args.length >= 1) { + if (args[0].equalsIgnoreCase("Help")) {// CA Help + if (!Methods.hasPermission(sender, "Access")) return true; + sender.sendMessage(Messages.HELP.getMessage()); + return true; + } + if (args[0].equalsIgnoreCase("test")) {// CA test [times] + if (!Methods.hasPermission(sender, "test")) return true; + int times = 1; + if (args.length >= 2) { + if (!Methods.isInt(args[1])) { + HashMap placeholders = new HashMap<>(); + placeholders.put("%Arg%", args[1]); + placeholders.put("%arg%", args[1]); + sender.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); + return true; + } + times = Integer.parseInt(args[1]); + } + int price = 10; + int amount = 1; + ItemStack item = Methods.getItemInHand((Player) sender); + if (item != null && item.getType() != Material.AIR) { + // For testing as another player + String seller = "Test-Account"; + for (int it = 1; it <= times; it++) { + int num = 1; + Random r = new Random(); + for (; Files.DATA.getFile().contains("Items." + num); num++) ; + Files.DATA.getFile().set("Items." + num + ".Price", price); + Files.DATA.getFile().set("Items." + num + ".Seller", seller); + if (args[0].equalsIgnoreCase("Bid")) { + Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Bid-Time"))); + } else { + Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Sell-Time"))); + } + Files.DATA.getFile().set("Items." + num + ".Full-Time", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Full-Expire-Time"))); + int id = r.nextInt(Integer.MAX_VALUE); + for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) + if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); + Files.DATA.getFile().set("Items." + num + ".StoreID", id); + ShopType type = ShopType.SELL; + Files.DATA.getFile().set("Items." + num + ".Biddable", args[0].equalsIgnoreCase("Bid")); + Files.DATA.getFile().set("Items." + num + ".TopBidder", "None"); + ItemStack I = item.clone(); + I.setAmount(amount); + Files.DATA.getFile().set("Items." + num + ".Item", I); + } + Files.DATA.saveFile(); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Price%", price + ""); + placeholders.put("%price%", price + ""); + sender.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(placeholders)); + if (item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) { + Methods.setItemInHand((Player) sender, new ItemStack(Material.AIR)); + } else { + item.setAmount(item.getAmount() - amount); + } + } else { + sender.sendMessage(Messages.DOSENT_HAVE_ITEM_IN_HAND.getMessage()); + } + return true; + } + if (args[0].equalsIgnoreCase("Reload")) {// CA Reload + if (!Methods.hasPermission(sender, "Admin")) return true; + fileManager.logInfo(true).setup(this); + crazyAuctions.loadCrazyAuctions(); + sender.sendMessage(Messages.RELOAD.getMessage()); + return true; + } + if (args[0].equalsIgnoreCase("View")) {// CA View + if (!Methods.hasPermission(sender, "View")) return true; + if (!(sender instanceof Player)) { + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); + return true; + } + if (args.length >= 2) { + Player player = (Player) sender; + GUI.openViewer(player, args[1], 1); + return true; + } + sender.sendMessage(Messages.CRAZYAUCTIONS_VIEW.getMessage()); + return true; + } + if (args[0].equalsIgnoreCase("Expired") || args[0].equalsIgnoreCase("Collect")) {// CA Expired + if (!Methods.hasPermission(sender, "Access")) return true; + if (!(sender instanceof Player)) { + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); + return true; + } + Player player = (Player) sender; + GUI.openPlayersExpiredList(player, 1); + return true; + } + if (args[0].equalsIgnoreCase("Listed")) {// CA Listed + if (!Methods.hasPermission(sender, "Access")) return true; + if (!(sender instanceof Player)) { + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); + return true; + } + Player player = (Player) sender; + GUI.openPlayersCurrentList(player, 1); + return true; + } + if (args[0].equalsIgnoreCase("Sell") || args[0].equalsIgnoreCase("Bid")) {// /CA Sell/Bid [Amount of Items] + if (!(sender instanceof Player)) { + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); + return true; + } + if (args.length >= 2) { + Player player = (Player) sender; + if (args[0].equalsIgnoreCase("Sell")) { + if (!crazyAuctions.isSellingEnabled()) { + player.sendMessage(Messages.SELLING_DISABLED.getMessage()); + return true; + } + if (!Methods.hasPermission(player, "Sell")) return true; + } + if (args[0].equalsIgnoreCase("Bid")) { + if (!crazyAuctions.isBiddingEnabled()) { + player.sendMessage(Messages.BIDDING_DISABLED.getMessage()); + return true; + } + if (!Methods.hasPermission(player, "Bid")) return true; + } + ItemStack item = Methods.getItemInHand(player); + int amount = item.getAmount(); + if (args.length >= 3) { + if (!Methods.isInt(args[2])) { + HashMap placeholders = new HashMap<>(); + placeholders.put("%Arg%", args[2]); + placeholders.put("%arg%", args[2]); + player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); + return true; + } + amount = Integer.parseInt(args[2]); + if (amount <= 0) amount = 1; + if (amount > item.getAmount()) amount = item.getAmount(); + } + if (!Methods.isLong(args[1])) { + HashMap placeholders = new HashMap<>(); + placeholders.put("%Arg%", args[1]); + placeholders.put("%arg%", args[1]); + player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); + return true; + } + if (Methods.getItemInHand(player).getType() == Material.AIR) { + player.sendMessage(Messages.DOSENT_HAVE_ITEM_IN_HAND.getMessage()); + return false; + } + long price = Long.parseLong(args[1]); + if (args[0].equalsIgnoreCase("Bid")) { + if (price < Files.CONFIG.getFile().getLong("Settings.Minimum-Bid-Price")) { + player.sendMessage(Messages.BID_PRICE_TO_LOW.getMessage()); + return true; + } + if (price > Files.CONFIG.getFile().getLong("Settings.Max-Beginning-Bid-Price")) { + player.sendMessage(Messages.BID_PRICE_TO_HIGH.getMessage()); + return true; + } + } else { + if (price < Files.CONFIG.getFile().getLong("Settings.Minimum-Sell-Price")) { + player.sendMessage(Messages.SELL_PRICE_TO_LOW.getMessage()); + return true; + } + if (price > Files.CONFIG.getFile().getLong("Settings.Max-Beginning-Sell-Price")) { + player.sendMessage(Messages.SELL_PRICE_TO_HIGH.getMessage()); + return true; + } + } + if (!player.hasPermission("crazyauctions.bypass")) { + int SellLimit = 0; + int BidLimit = 0; + for (PermissionAttachmentInfo permission : player.getEffectivePermissions()) { + String perm = permission.getPermission(); + if (perm.startsWith("crazyauctions.sell.")) { + perm = perm.replace("crazyauctions.sell.", ""); + if (Methods.isInt(perm)) { + if (Integer.parseInt(perm) > SellLimit) { + SellLimit = Integer.parseInt(perm); + } + } + } + if (perm.startsWith("crazyauctions.bid.")) { + perm = perm.replace("crazyauctions.bid.", ""); + if (Methods.isInt(perm)) { + if (Integer.parseInt(perm) > BidLimit) { + BidLimit = Integer.parseInt(perm); + } + } + } + } + for (int i = 1; i < 100; i++) { + if (SellLimit < i) { + if (player.hasPermission("crazyauctions.sell." + i)) { + SellLimit = i; + } + } + if (BidLimit < i) { + if (player.hasPermission("crazyauctions.bid." + i)) { + BidLimit = i; + } + } + } + if (args[0].equalsIgnoreCase("Sell")) { + if (crazyAuctions.getItems(player, ShopType.SELL).size() >= SellLimit) { + player.sendMessage(Messages.MAX_ITEMS.getMessage()); + return true; + } + } + if (args[0].equalsIgnoreCase("Bid")) { + if (crazyAuctions.getItems(player, ShopType.BID).size() >= BidLimit) { + player.sendMessage(Messages.MAX_ITEMS.getMessage()); + return true; + } + } + } + for (String id : Files.CONFIG.getFile().getStringList("Settings.BlackList")) { + if (item.getType() == Methods.makeItem(id, 1).getType()) { + player.sendMessage(Messages.ITEM_BLACKLISTED.getMessage()); + return true; + } + } + if (!Files.CONFIG.getFile().getBoolean("Settings.Allow-Damaged-Items")) { + for (Material i : getDamageableItems()) { + if (item.getType() == i) { + if (item.getDurability() > 0) { + player.sendMessage(Messages.ITEM_DAMAGED.getMessage()); + return true; + } + } + } + } + if (!allowBook(item)) { + player.sendMessage(Messages.BOOK_NOT_ALLOWED.getMessage()); + return true; + } + String seller = player.getName(); + // For testing as another player + //String seller = "Test-Account"; + int num = 1; + Random r = new Random(); + for (; Files.DATA.getFile().contains("Items." + num); num++) ; + Files.DATA.getFile().set("Items." + num + ".Price", price); + Files.DATA.getFile().set("Items." + num + ".Seller", seller); + if (args[0].equalsIgnoreCase("Bid")) { + Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Bid-Time"))); + } else { + Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Sell-Time"))); + } + Files.DATA.getFile().set("Items." + num + ".Full-Time", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Full-Expire-Time"))); + int id = r.nextInt(999999); + // Runs 3x to check for same ID. + for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) + if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); + for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) + if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); + for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) + if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); + Files.DATA.getFile().set("Items." + num + ".StoreID", id); + ShopType type = ShopType.SELL; + if (args[0].equalsIgnoreCase("Bid")) { + Files.DATA.getFile().set("Items." + num + ".Biddable", true); + type = ShopType.BID; + } else { + Files.DATA.getFile().set("Items." + num + ".Biddable", false); + } + Files.DATA.getFile().set("Items." + num + ".TopBidder", "None"); + ItemStack I = item.clone(); + I.setAmount(amount); + Files.DATA.getFile().set("Items." + num + ".Item", I); + Files.DATA.saveFile(); + Bukkit.getPluginManager().callEvent(new AuctionListEvent(player, type, I, price)); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Price%", price + ""); + placeholders.put("%price%", price + ""); + player.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(placeholders)); + if (item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) { + Methods.setItemInHand(player, new ItemStack(Material.AIR)); + } else { + item.setAmount(item.getAmount() - amount); + } + return false; + } + sender.sendMessage(Messages.CRAZYAUCTIONS_SELL_BID.getMessage()); + return true; + } + } + } + sender.sendMessage(Messages.CRAZYAUCTIONS_HELP.getMessage()); + return false; + } + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + final Player player = e.getPlayer(); + if (player.getName().equalsIgnoreCase("BadBones69")) { + Bukkit.getScheduler().runTaskLater(this, () -> player.sendMessage(Methods.getPrefix() + Methods.color("&7This server is running your Crazy Auctions Plugin. " + "&7It is running version &av" + Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions").getDescription().getVersion() + "&7.")), 40); + } + } + + private void startCheck() { + Bukkit.getScheduler().runTaskTimer(this, Methods :: updateAuction, 20, 5 * 20); + } + + private ArrayList getDamageableItems() { + ArrayList ma = new ArrayList<>(); + if (Version.isNewer(Version.v1_12_R1)) { + ma.add(Material.matchMaterial("GOLDEN_HELMET")); + ma.add(Material.matchMaterial("GOLDEN_CHESTPLATE")); + ma.add(Material.matchMaterial("GOLDEN_LEGGINGS")); + ma.add(Material.matchMaterial("GOLDEN_BOOTS")); + ma.add(Material.matchMaterial("WOODEN_SWORD")); + ma.add(Material.matchMaterial("WOODEN_AXE")); + ma.add(Material.matchMaterial("WOODEN_PICKAXE")); + ma.add(Material.matchMaterial("WOODEN_AXE")); + ma.add(Material.matchMaterial("WOODEN_SHOVEL")); + ma.add(Material.matchMaterial("STONE_SHOVEL")); + ma.add(Material.matchMaterial("IRON_SHOVEL")); + ma.add(Material.matchMaterial("DIAMOND_SHOVEL")); + ma.add(Material.matchMaterial("WOODEN_HOE")); + ma.add(Material.matchMaterial("GOLDEN_HOE")); + ma.add(Material.matchMaterial("CROSSBOW")); + ma.add(Material.matchMaterial("TRIDENT")); + ma.add(Material.matchMaterial("TURTLE_HELMET")); + } else { + ma.add(Material.matchMaterial("GOLD_HELMET")); + ma.add(Material.matchMaterial("GOLD_CHESTPLATE")); + ma.add(Material.matchMaterial("GOLD_LEGGINGS")); + ma.add(Material.matchMaterial("GOLD_BOOTS")); + ma.add(Material.matchMaterial("WOOD_SWORD")); + ma.add(Material.matchMaterial("WOOD_AXE")); + ma.add(Material.matchMaterial("WOOD_PICKAXE")); + ma.add(Material.matchMaterial("WOOD_AXE")); + ma.add(Material.matchMaterial("WOOD_SPADE")); + ma.add(Material.matchMaterial("STONE_SPADE")); + ma.add(Material.matchMaterial("IRON_SPADE")); + ma.add(Material.matchMaterial("DIAMOND_SPADE")); + ma.add(Material.matchMaterial("WOOD_HOE")); + ma.add(Material.matchMaterial("GOLD_HOE")); + } + ma.add(Material.DIAMOND_HELMET); + ma.add(Material.DIAMOND_CHESTPLATE); + ma.add(Material.DIAMOND_LEGGINGS); + ma.add(Material.DIAMOND_BOOTS); + ma.add(Material.CHAINMAIL_HELMET); + ma.add(Material.CHAINMAIL_CHESTPLATE); + ma.add(Material.CHAINMAIL_LEGGINGS); + ma.add(Material.CHAINMAIL_BOOTS); + ma.add(Material.IRON_HELMET); + ma.add(Material.IRON_CHESTPLATE); + ma.add(Material.IRON_LEGGINGS); + ma.add(Material.IRON_BOOTS); + ma.add(Material.LEATHER_HELMET); + ma.add(Material.LEATHER_CHESTPLATE); + ma.add(Material.LEATHER_LEGGINGS); + ma.add(Material.LEATHER_BOOTS); + ma.add(Material.BOW); + ma.add(Material.STONE_SWORD); + ma.add(Material.IRON_SWORD); + ma.add(Material.DIAMOND_SWORD); + ma.add(Material.STONE_AXE); + ma.add(Material.IRON_AXE); + ma.add(Material.DIAMOND_AXE); + ma.add(Material.STONE_PICKAXE); + ma.add(Material.IRON_PICKAXE); + ma.add(Material.DIAMOND_PICKAXE); + ma.add(Material.STONE_AXE); + ma.add(Material.IRON_AXE); + ma.add(Material.DIAMOND_AXE); + ma.add(Material.STONE_HOE); + ma.add(Material.IRON_HOE); + ma.add(Material.DIAMOND_HOE); + ma.add(Material.FLINT_AND_STEEL); + ma.add(Material.ANVIL); + ma.add(Material.FISHING_ROD); + return ma; + } + + private boolean allowBook(ItemStack item) { + if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof BookMeta) { + Bukkit.getLogger().info("Checking " + item.getType() + " for illegal unicode."); + try { + Files.TEST_FILE.getFile().set("Test", item); + Files.TEST_FILE.saveFile(); + Bukkit.getLogger().info("" + item.getType() + " has passed unicode checks."); + } catch (YAMLException e) { + Bukkit.getLogger().info("" + item.getType() + " has failed unicode checks and has been denied."); + return false; + } + return ((BookMeta) item.getItemMeta()).getPages().stream().mapToInt(String :: length).sum() < 2000; + } + return true; + } + + public Material getMaterial(String newMaterial, String oldMaterial) { + return Material.matchMaterial(Version.isNewer(Version.v1_12_R1) ? newMaterial : oldMaterial); + } + +} diff --git a/src/main/java/com/badbones69/crazyauctions/Methods.java b/src/main/java/com/badbones69/crazyauctions/Methods.java index e298339..c2c098c 100644 --- a/src/main/java/com/badbones69/crazyauctions/Methods.java +++ b/src/main/java/com/badbones69/crazyauctions/Methods.java @@ -1,117 +1,277 @@ package com.badbones69.crazyauctions; import com.badbones69.crazyauctions.api.FileManager.Files; -import com.badbones69.crazyauctions.api.enums.Messages; -import com.badbones69.crazyauctions.utils.ItemBuilder; -import com.badbones69.crazyauctions.utils.func.ServerProtocol; -import net.md_5.bungee.api.chat.TextComponent; +import com.badbones69.crazyauctions.api.Messages; +import com.badbones69.crazyauctions.api.Version; +import com.badbones69.crazyauctions.api.events.AuctionExpireEvent; +import com.badbones69.crazyauctions.api.events.AuctionWinBidEvent; +import com.badbones69.crazyauctions.currency.CurrencyManager; import org.bukkit.*; import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; -@SuppressWarnings("deprecation") public class Methods { - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); + public final static Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F0-9]{6}"); - public final Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F0-9]{6}"); - - public String color(String message) { - if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) { + public static String color(String message) { + if (Version.isNewer(Version.v1_15_R1)) { Matcher matcher = HEX_PATTERN.matcher(message); - StringBuilder buffer = new StringBuilder(); - + StringBuffer buffer = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(buffer, net.md_5.bungee.api.ChatColor.of(matcher.group()).toString()); } - return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString()); } - return ChatColor.translateAlternateColorCodes('&', message); } - public String getPrefix() { + public static String getPrefix() { return color(Files.CONFIG.getFile().getString("Settings.Prefix", "")); } - public String getPrefix(String msg) { + public static String getPrefix(String msg) { return color(Files.CONFIG.getFile().getString("Settings.Prefix", "") + msg); } - - public String sanitizeColor(String msg) { - return sanitizeFormat(color(msg)); - } - public String removeColor(String msg) { + public static String removeColor(String msg) { return ChatColor.stripColor(msg); } - - public static String sanitizeFormat(String string) { - return TextComponent.toLegacyText(TextComponent.fromLegacyText(string)); - } - public ItemStack makeItem(Material material, int amount, String name, List lore, HashMap enchants) { - ItemBuilder newItem = new ItemBuilder().setMaterial(material).setAmount(amount).setName(name).setLore(lore).setEnchantments(enchants); - return newItem.build(); - } - - public ItemStack getItemInHand(Player player) { - return player.getInventory().getItemInMainHand(); - } - - public void setItemInHand(Player player, ItemStack item) { - player.getInventory().setItemInMainHand(item); - } - - public Player getPlayer(String name) { + 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 { - return plugin.getServer().getPlayer(name); + item = new ItemStack(m, amount, (short) ty); + } catch (Exception e) { + if (Version.isNewer(Version.v1_12_R1)) { + item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1); + + } else { + item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14); + } + } + 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) { + if (Version.isNewer(Version.v1_12_R1)) { + item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1); + + } else { + item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14); + } + } + 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) { + if (Version.isNewer(Version.v1_12_R1)) { + item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1); + + } else { + item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14); + } + } + 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 Integer getVersion() { + String ver = Bukkit.getServer().getClass().getPackage().getName(); + ver = ver.substring(ver.lastIndexOf('.') + 1); + ver = ver.replace("_", "").replace("R", "").replace("v", ""); + return Integer.parseInt(ver); + } + + @SuppressWarnings("deprecation") + public static ItemStack getItemInHand(Player player) { + if (getVersion() >= 191) { + return player.getInventory().getItemInMainHand(); + } else { + return player.getItemInHand(); + } + } + + @SuppressWarnings("deprecation") + public static void setItemInHand(Player player, ItemStack item) { + if (getVersion() >= 191) { + player.getInventory().setItemInMainHand(item); + } else { + player.setItemInHand(item); + } + } + + public static boolean isInt(String s) { + try { + Integer.parseInt(s); + } catch (NumberFormatException nfe) { + return false; + } + return true; + } + + public static boolean isLong(String s) { + try { + Long.parseLong(s); + } catch (NumberFormatException nfe) { + return false; + } + return true; + } + + public static Player getPlayer(String name) { + try { + return Bukkit.getServer().getPlayer(name); } catch (Exception e) { return null; } } @SuppressWarnings("deprecation") - public OfflinePlayer getOfflinePlayer(String name) { - return plugin.getServer().getOfflinePlayer(name); + public static OfflinePlayer getOfflinePlayer(String name) { + return Bukkit.getServer().getOfflinePlayer(name); } - public boolean isOnline(String name) { - for (Player player : plugin.getServer().getOnlinePlayers()) { - if (player.getName().equalsIgnoreCase(name)) return true; + public static Location getLoc(Player player) { + return player.getLocation(); + } + + public static void runCMD(Player player, String CMD) { + player.performCommand(CMD); + } + + public static boolean isOnline(String name) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { + if (player.getName().equalsIgnoreCase(name)) { + return true; + } } - return false; } - public boolean isOnline(String name, CommandSender commandSender) { - for (Player player : plugin.getServer().getOnlinePlayers()) { - if (player.getName().equalsIgnoreCase(name)) return true; + public static boolean isOnline(String name, CommandSender p) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { + if (player.getName().equalsIgnoreCase(name)) { + return true; + } } - - commandSender.sendMessage(Messages.NOT_ONLINE.getMessage()); + p.sendMessage(Messages.NOT_ONLINE.getMessage()); return false; } - public boolean hasPermission(Player player, String perm) { + public static boolean hasPermission(Player player, String perm) { if (!player.hasPermission("crazyauctions." + perm)) { player.sendMessage(Messages.NO_PERMISSION.getMessage()); return false; } - return true; } - public boolean hasPermission(CommandSender sender, String perm) { + public static boolean hasPermission(CommandSender sender, String perm) { if (sender instanceof Player) { Player player = (Player) sender; - if (!player.hasPermission("crazyauctions." + perm)) { player.sendMessage(Messages.NO_PERMISSION.getMessage()); return false; @@ -123,7 +283,171 @@ public class Methods { } } - public boolean isInvFull(Player player) { + public static List getPage(List list, Integer page) { + List items = new ArrayList<>(); + if (page <= 0) page = 1; + int max = 45; + int index = page * max - max; + int endIndex = index >= list.size() ? list.size() - 1 : index + max; + for (; index < endIndex; index++) { + if (index < list.size()) items.add(list.get(index)); + } + for (; items.size() == 0; page--) { + if (page <= 0) break; + index = page * max - max; + endIndex = index >= list.size() ? list.size() - 1 : index + max; + for (; index < endIndex; index++) { + if (index < list.size()) items.add(list.get(index)); + } + } + return items; + } + + public static List getPageInts(List list, Integer page) { + List items = new ArrayList<>(); + if (page <= 0) page = 1; + int max = 45; + int index = page * max - max; + int endIndex = index >= list.size() ? list.size() - 1 : index + max; + for (; index < endIndex; index++) { + if (index < list.size()) items.add(list.get(index)); + } + for (; items.size() == 0; page--) { + if (page <= 0) break; + index = page * max - max; + endIndex = index >= list.size() ? list.size() - 1 : index + max; + for (; index < endIndex; index++) { + if (index < list.size()) items.add(list.get(index)); + } + } + return items; + } + + public static int getMaxPage(List list) { + int maxPage = 1; + int amount = list.size(); + for (; amount > 45; amount -= 45, maxPage++) ; + return maxPage; + } + + public static String convertToTime(long time) { + Calendar C = Calendar.getInstance(); + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(time); + int total = ((int) (cal.getTimeInMillis() / 1000) - (int) (C.getTimeInMillis() / 1000)); + int D = 0; + int H = 0; + int M = 0; + int S = 0; + for (; total > 86400; total -= 86400, D++) ; + for (; total > 3600; total -= 3600, H++) ; + for (; total > 60; total -= 60, M++) ; + S += total; + return D + "d " + H + "h " + M + "m " + S + "s "; + } + + public static long convertToMill(String time) { + Calendar cal = Calendar.getInstance(); + for (String i : time.split(" ")) { + if (i.contains("D") || i.contains("d")) { + cal.add(Calendar.DATE, Integer.parseInt(i.replace("D", "").replace("d", ""))); + } + if (i.contains("H") || i.contains("h")) { + cal.add(Calendar.HOUR, Integer.parseInt(i.replace("H", "").replace("h", ""))); + } + if (i.contains("M") || i.contains("m")) { + cal.add(Calendar.MINUTE, Integer.parseInt(i.replace("M", "").replace("m", ""))); + } + if (i.contains("S") || i.contains("s")) { + cal.add(Calendar.SECOND, Integer.parseInt(i.replace("S", "").replace("s", ""))); + } + } + return cal.getTimeInMillis(); + } + + public static boolean isInvFull(Player player) { return player.getInventory().firstEmpty() == -1; } + + public static void updateAuction() { + FileConfiguration data = Files.DATA.getFile(); + Calendar cal = Calendar.getInstance(); + Calendar expireTime = Calendar.getInstance(); + Calendar fullExpireTime = Calendar.getInstance(); + boolean shouldSave = false; + if (data.contains("OutOfTime/Cancelled")) { + for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { + fullExpireTime.setTimeInMillis(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time")); + if (cal.after(fullExpireTime)) { + data.set("OutOfTime/Cancelled." + i, null); + shouldSave = true; + } + } + } + if (data.contains("Items")) { + for (String i : data.getConfigurationSection("Items").getKeys(false)) { + expireTime.setTimeInMillis(data.getLong("Items." + i + ".Time-Till-Expire")); + fullExpireTime.setTimeInMillis(data.getLong("Items." + i + ".Full-Time")); + if (cal.after(expireTime)) { + int num = 1; + for (; data.contains("OutOfTime/Cancelled." + num); num++) ; + if (data.getBoolean("Items." + i + ".Biddable") && !data.getString("Items." + i + ".TopBidder").equalsIgnoreCase("None") && CurrencyManager.getMoney(getPlayer(data.getString("Items." + i + ".TopBidder"))) >= data.getInt("Items." + i + ".Price")) { + String winner = data.getString("Items." + i + ".TopBidder"); + String seller = data.getString("Items." + i + ".Seller"); + Long price = data.getLong("Items." + i + ".Price"); + CurrencyManager.addMoney(getOfflinePlayer(seller), price); + CurrencyManager.removeMoney(getOfflinePlayer(winner), price); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Price%", getPrice(i, false)); + placeholders.put("%price%", getPrice(i, false)); + placeholders.put("%Player%", winner); + placeholders.put("%player%", winner); + if (isOnline(winner) && getPlayer(winner) != null) { + Player player = getPlayer(winner); + Bukkit.getPluginManager().callEvent(new AuctionWinBidEvent(player, data.getItemStack("Items." + i + ".Item"), price)); + player.sendMessage(Messages.WIN_BIDDING.getMessage(placeholders)); + } + if (isOnline(seller) && getPlayer(seller) != null) { + Player player = getPlayer(seller); + player.sendMessage(Messages.SOMEONE_WON_PLAYERS_BID.getMessage(placeholders)); + } + data.set("OutOfTime/Cancelled." + num + ".Seller", winner); + data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis()); + data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); + data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item")); + } else { + String seller = data.getString("Items." + i + ".Seller"); + Player player = getPlayer(seller); + if (isOnline(seller) && getPlayer(seller) != null) { + player.sendMessage(Messages.ITEM_HAS_EXPIRED.getMessage()); + } + AuctionExpireEvent event = new AuctionExpireEvent(player, data.getItemStack("Items." + i + ".Item")); + Bukkit.getPluginManager().callEvent(event); + data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); + data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis()); + data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); + data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item")); + } + data.set("Items." + i, null); + shouldSave = true; + } + } + } + if (shouldSave) Files.DATA.saveFile(); + } + + public static String getPrice(String ID, Boolean Expired) { + long price = 0L; + if (Expired) { + if (Files.DATA.getFile().contains("OutOfTime/Cancelled." + ID + ".Price")) { + price = Files.DATA.getFile().getLong("OutOfTime/Cancelled." + ID + ".Price"); + } + } else { + if (Files.DATA.getFile().contains("Items." + ID + ".Price")) { + price = Files.DATA.getFile().getLong("Items." + ID + ".Price"); + } + } + return String.valueOf(price); + } + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/Starter.java b/src/main/java/com/badbones69/crazyauctions/Starter.java deleted file mode 100644 index 24d59db..0000000 --- a/src/main/java/com/badbones69/crazyauctions/Starter.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.badbones69.crazyauctions; - -import com.badbones69.crazyauctions.api.CrazyManager; -import com.badbones69.crazyauctions.api.FileManager; -import com.badbones69.crazyauctions.api.economy.vault.VaultSupport; -import com.badbones69.crazyauctions.utils.SkullCreator; - -public class Starter { - - private FileManager fileManager; - - private CrazyManager crazyManager; - - private VaultSupport vaultSupport; - - private Methods methods; - - private SkullCreator skullCreator; - - public void run() { - fileManager = new FileManager(); - crazyManager = new CrazyManager(); - - vaultSupport = new VaultSupport(); - - methods = new Methods(); - - skullCreator = new SkullCreator(); - } - - public FileManager getFileManager() { - return fileManager; - } - - public CrazyManager getCrazyManager() { - return crazyManager; - } - - public VaultSupport getVaultSupport() { - return vaultSupport; - } - - public Methods getMethods() { - return methods; - } - - public SkullCreator getSkullCreator() { - return skullCreator; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/enums/AuctionCategories.java b/src/main/java/com/badbones69/crazyauctions/api/Category.java similarity index 51% rename from src/main/java/com/badbones69/crazyauctions/api/enums/AuctionCategories.java rename to src/main/java/com/badbones69/crazyauctions/api/Category.java index 0de5742..11e46ee 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/enums/AuctionCategories.java +++ b/src/main/java/com/badbones69/crazyauctions/api/Category.java @@ -1,11 +1,11 @@ -package com.badbones69.crazyauctions.api.enums; +package com.badbones69.crazyauctions.api; -import com.badbones69.crazyauctions.utils.func.ServerProtocol; import org.bukkit.Material; + import java.util.ArrayList; -public enum AuctionCategories { - +public enum Category { + NONE("None", new ArrayList<>()), OTHER("Other", getOthers()), ARMOR("Armor", getArmor()), @@ -14,194 +14,192 @@ public enum AuctionCategories { FOOD("Food", getFood()), POTIONS("Potions", getPotions()), BLOCKS("Blocks", getBlocks()); - + private final String name; private final ArrayList items; - + /** * @param name Name of the Shop Type. */ - AuctionCategories(String name, ArrayList items) { + private Category(String name, ArrayList items) { this.name = name; this.items = items; } - + /** * @param name Name of the Type you want. * @return Returns the Type as an Enum. */ - public static AuctionCategories getFromName(String name) { - for (AuctionCategories type : AuctionCategories.values()) { - if (type.getName().equalsIgnoreCase(name)) return type; + public static Category getFromName(String name) { + for (Category type : Category.values()) { + if (type.getName().equalsIgnoreCase(name)) { + return type; + } } - return null; } - + private static ArrayList getArmor() { ArrayList ma = new ArrayList<>(); - - ma.add(Material.LEATHER_HELMET); - ma.add(Material.LEATHER_CHESTPLATE); - ma.add(Material.LEATHER_LEGGINGS); - ma.add(Material.LEATHER_BOOTS); - - ma.add(Material.GOLDEN_HELMET); - ma.add(Material.GOLDEN_CHESTPLATE); - ma.add(Material.GOLDEN_LEGGINGS); - ma.add(Material.GOLDEN_BOOTS); - - ma.add(Material.CHAINMAIL_HELMET); - ma.add(Material.CHAINMAIL_CHESTPLATE); - ma.add(Material.CHAINMAIL_LEGGINGS); - ma.add(Material.CHAINMAIL_BOOTS); - - ma.add(Material.IRON_HELMET); - ma.add(Material.IRON_CHESTPLATE); - ma.add(Material.IRON_LEGGINGS); - ma.add(Material.IRON_BOOTS); - + if (Version.isNewer(Version.v1_12_R1)) { + ma.add(Material.matchMaterial("GOLDEN_HELMET")); + ma.add(Material.matchMaterial("GOLDEN_CHESTPLATE")); + ma.add(Material.matchMaterial("GOLDEN_LEGGINGS")); + ma.add(Material.matchMaterial("GOLDEN_BOOTS")); + } else { + ma.add(Material.matchMaterial("GOLD_HELMET")); + ma.add(Material.matchMaterial("GOLD_CHESTPLATE")); + ma.add(Material.matchMaterial("GOLD_LEGGINGS")); + ma.add(Material.matchMaterial("GOLD_BOOTS")); + } ma.add(Material.DIAMOND_HELMET); ma.add(Material.DIAMOND_CHESTPLATE); ma.add(Material.DIAMOND_LEGGINGS); ma.add(Material.DIAMOND_BOOTS); - - ma.add(Material.TURTLE_HELMET); - - if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) { + ma.add(Material.CHAINMAIL_HELMET); + ma.add(Material.CHAINMAIL_CHESTPLATE); + ma.add(Material.CHAINMAIL_LEGGINGS); + ma.add(Material.CHAINMAIL_BOOTS); + ma.add(Material.IRON_HELMET); + ma.add(Material.IRON_CHESTPLATE); + ma.add(Material.IRON_LEGGINGS); + ma.add(Material.IRON_BOOTS); + ma.add(Material.DIAMOND_HELMET); + ma.add(Material.DIAMOND_CHESTPLATE); + ma.add(Material.DIAMOND_LEGGINGS); + ma.add(Material.DIAMOND_BOOTS); + if (Version.isNewer(Version.v1_15_R1)) { ma.add(Material.NETHERITE_HELMET); ma.add(Material.NETHERITE_CHESTPLATE); ma.add(Material.NETHERITE_LEGGINGS); ma.add(Material.NETHERITE_BOOTS); } - return ma; } - + private static ArrayList getTools() { ArrayList ma = new ArrayList<>(); - - ma.add(Material.WOODEN_PICKAXE); - ma.add(Material.WOODEN_AXE); - ma.add(Material.WOODEN_SHOVEL); - ma.add(Material.WOODEN_HOE); - + if (Version.isNewer(Version.v1_12_R1)) { + ma.add(Material.matchMaterial("WOODEN_PICKAXE")); + ma.add(Material.matchMaterial("WOODEN_AXE")); + ma.add(Material.matchMaterial("WOODEN_SHOVEL")); + ma.add(Material.matchMaterial("WOODEN_HOE")); + ma.add(Material.matchMaterial("GOLDEN_PICKAXE")); + ma.add(Material.matchMaterial("GOLDEN_AXE")); + ma.add(Material.matchMaterial("GOLDEN_SHOVEL")); + ma.add(Material.matchMaterial("GOLDEN_HOE")); + ma.add(Material.matchMaterial("STONE_SHOVEL")); + ma.add(Material.matchMaterial("IRON_SHOVEL")); + ma.add(Material.matchMaterial("DIAMOND_SHOVEL")); + } else { + ma.add(Material.matchMaterial("WOOD_PICKAXE")); + ma.add(Material.matchMaterial("WOOD_AXE")); + ma.add(Material.matchMaterial("WOOD_SPADE")); + ma.add(Material.matchMaterial("WOOD_HOE")); + ma.add(Material.matchMaterial("GOLD_PICKAXE")); + ma.add(Material.matchMaterial("GOLD_AXE")); + ma.add(Material.matchMaterial("GOLD_SPADE")); + ma.add(Material.matchMaterial("GOLD_HOE")); + ma.add(Material.matchMaterial("STONE_SPADE")); + ma.add(Material.matchMaterial("IRON_SPADE")); + ma.add(Material.matchMaterial("DIAMOND_SPADE")); + } ma.add(Material.STONE_PICKAXE); - ma.add(Material.STONE_AXE); - ma.add(Material.STONE_SHOVEL); - ma.add(Material.STONE_HOE); - - ma.add(Material.GOLDEN_PICKAXE); - ma.add(Material.GOLDEN_AXE); - ma.add(Material.GOLDEN_SHOVEL); - ma.add(Material.GOLDEN_HOE); - ma.add(Material.IRON_PICKAXE); - ma.add(Material.IRON_AXE); - ma.add(Material.IRON_SHOVEL); - ma.add(Material.IRON_HOE); - ma.add(Material.DIAMOND_PICKAXE); + ma.add(Material.STONE_AXE); + ma.add(Material.IRON_AXE); ma.add(Material.DIAMOND_AXE); - ma.add(Material.DIAMOND_SHOVEL); + ma.add(Material.STONE_HOE); + ma.add(Material.IRON_HOE); ma.add(Material.DIAMOND_HOE); - - ma.add(Material.SHEARS); - ma.add(Material.FISHING_ROD); - ma.add(Material.FLINT_AND_STEEL); - ma.add(Material.SPYGLASS); - - if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) { + if (Version.isNewer(Version.v1_15_R1)) { ma.add(Material.NETHERITE_PICKAXE); ma.add(Material.NETHERITE_AXE); ma.add(Material.NETHERITE_HOE); ma.add(Material.NETHERITE_SHOVEL); } - return ma; } - + private static ArrayList getWeapons() { ArrayList ma = new ArrayList<>(); - - ma.add(Material.WOODEN_SWORD); - ma.add(Material.WOODEN_AXE); - + if (Version.isNewer(Version.v1_12_R1)) { + ma.add(Material.matchMaterial("WOODEN_SWORD")); + ma.add(Material.matchMaterial("WOODEN_AXE")); + ma.add(Material.matchMaterial("GOLDEN_SWORD")); + ma.add(Material.matchMaterial("GOLDEN_AXE")); + } else { + ma.add(Material.matchMaterial("WOOD_SWORD")); + ma.add(Material.matchMaterial("WOOD_AXE")); + ma.add(Material.matchMaterial("GOLD_SWORD")); + ma.add(Material.matchMaterial("GOLD_AXE")); + } ma.add(Material.STONE_SWORD); - ma.add(Material.STONE_AXE); - - ma.add(Material.GOLDEN_SWORD); - ma.add(Material.GOLDEN_AXE); - ma.add(Material.IRON_SWORD); - ma.add(Material.IRON_AXE); - ma.add(Material.DIAMOND_SWORD); + ma.add(Material.STONE_AXE); + ma.add(Material.IRON_AXE); ma.add(Material.DIAMOND_AXE); - ma.add(Material.BOW); - ma.add(Material.CROSSBOW); - ma.add(Material.TRIDENT); - - if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) { + if (Version.isNewer(Version.v1_15_R1)) { ma.add(Material.NETHERITE_SWORD); ma.add(Material.NETHERITE_AXE); } - return ma; } - + private static ArrayList getFood() { ArrayList ma = new ArrayList<>(); - for (Material m : Material.values()) { if (m.isEdible()) { if (m != Material.POTION) ma.add(m); } } - return ma; } - + private static ArrayList getPotions() { ArrayList ma = new ArrayList<>(); ma.add(Material.POTION); - - if (Material.matchMaterial("SPLASH_POTION") != null) ma.add(Material.matchMaterial("SPLASH_POTION")); - - if (Material.matchMaterial("LINGERING_POTION") != null) ma.add(Material.matchMaterial("LINGERING_POTION")); - + if (Material.matchMaterial("SPLASH_POTION") != null) { + ma.add(Material.matchMaterial("SPLASH_POTION")); + } + if (Material.matchMaterial("LINGERING_POTION") != null) { + ma.add(Material.matchMaterial("LINGERING_POTION")); + } return ma; } - + private static ArrayList getBlocks() { ArrayList ma = new ArrayList<>(); - for (Material m : Material.values()) { - if (m.isBlock()) ma.add(m); + if (m.isBlock()) { + ma.add(m); + } } - return ma; } - + private static ArrayList getOthers() { ArrayList ma = new ArrayList<>(); - for (Material m : Material.values()) { - if (!(getArmor().contains(m) || getTools().contains(m) || getWeapons().contains(m) || getFood().contains(m) || getPotions().contains(m) || getBlocks().contains(m))) ma.add(m); + if (!(getArmor().contains(m) || getTools().contains(m) || getWeapons().contains(m) || getFood().contains(m) || getPotions().contains(m) || getBlocks().contains(m))) { + ma.add(m); + } } - return ma; } - + /** * @return Returns the type name as a string. */ public String getName() { return name; } - + public ArrayList getItems() { return items; } + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/CrazyManager.java b/src/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java similarity index 69% rename from src/main/java/com/badbones69/crazyauctions/api/CrazyManager.java rename to src/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java index 230f201..4045c0e 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/CrazyManager.java +++ b/src/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java @@ -1,24 +1,29 @@ package com.badbones69.crazyauctions.api; import com.badbones69.crazyauctions.api.FileManager.Files; -import com.badbones69.crazyauctions.api.enums.ShopCategories; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; + import java.util.ArrayList; -public class CrazyManager { - +public class CrazyAuctions { + + private static CrazyAuctions instance = new CrazyAuctions(); + private FileManager fileManager = FileManager.getInstance(); private Boolean sellingEnabled; private Boolean biddingEnabled; - - public void load() { + + public static CrazyAuctions getInstance() { + return instance; + } + + public void loadCrazyAuctions() { if (Files.CONFIG.getFile().contains("Settings.Feature-Toggle.Selling")) { this.sellingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Selling"); } else { this.sellingEnabled = true; } - if (Files.CONFIG.getFile().contains("Settings.Feature-Toggle.Bidding")) { this.biddingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Bidding"); } else { @@ -37,32 +42,35 @@ public class CrazyManager { public ArrayList getItems(Player player) { FileConfiguration data = Files.DATA.getFile(); ArrayList items = new ArrayList<>(); - if (data.contains("Items")) { for (String i : data.getConfigurationSection("Items").getKeys(false)) { - if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) items.add(data.getItemStack("Items." + i + ".Item").clone()); + if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { + items.add(data.getItemStack("Items." + i + ".Item").clone()); + } } } - return items; } - public ArrayList getItems(Player player, ShopCategories type) { + public ArrayList getItems(Player player, ShopType type) { FileConfiguration data = Files.DATA.getFile(); ArrayList items = new ArrayList<>(); - if (data.contains("Items")) { for (String i : data.getConfigurationSection("Items").getKeys(false)) { if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { if (data.getBoolean("Items." + i + ".Biddable")) { - if (type == ShopCategories.BID) items.add(data.getItemStack("Items." + i + ".Item").clone()); + if (type == ShopType.BID) { + items.add(data.getItemStack("Items." + i + ".Item").clone()); + } } else { - if (type == ShopCategories.SELL) items.add(data.getItemStack("Items." + i + ".Item").clone()); + if (type == ShopType.SELL) { + items.add(data.getItemStack("Items." + i + ".Item").clone()); + } } } } } - return items; } + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/FileManager.java b/src/main/java/com/badbones69/crazyauctions/api/FileManager.java index 8e1691d..329f39a 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/FileManager.java +++ b/src/main/java/com/badbones69/crazyauctions/api/FileManager.java @@ -1,8 +1,11 @@ package com.badbones69.crazyauctions.api; -import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -11,107 +14,110 @@ import java.util.ArrayList; import java.util.HashMap; /** + * * @author BadBones69 * @version v1.0 + * */ public class FileManager { - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); + private static FileManager instance = new FileManager(); + private Plugin plugin; + private String prefix = ""; + private Boolean log = false; + private HashMap files = new HashMap<>(); + private ArrayList homeFolders = new ArrayList<>(); + private ArrayList customFiles = new ArrayList<>(); + private HashMap autoGenerateFiles = new HashMap<>(); + private HashMap configurations = new HashMap<>(); - private boolean log = false; - - private final HashMap files = new HashMap<>(); - private final ArrayList homeFolders = new ArrayList<>(); - private final ArrayList customFiles = new ArrayList<>(); - private final HashMap jarHomeFolders = new HashMap<>(); - private final HashMap autoGenerateFiles = new HashMap<>(); - private final HashMap configurations = new HashMap<>(); + public static FileManager getInstance() { + return instance; + } /** - * Loads all necessary files. + * Sets up the plugin and loads all necessary files. + * @param plugin The plugin this is getting loading for. */ - public FileManager setup() { - if (!plugin.getDataFolder().exists()) plugin.getDataFolder().mkdirs(); - + public FileManager setup(Plugin plugin) { + prefix = "[" + plugin.getName() + "] "; + this.plugin = plugin; + if (!plugin.getDataFolder().exists()) { + plugin.getDataFolder().mkdirs(); + } files.clear(); customFiles.clear(); - - // Loads all the normal static files. + //Loads all the normal static files. for (Files file : Files.values()) { File newFile = new File(plugin.getDataFolder(), file.getFileLocation()); - - if (isLogging()) plugin.getLogger().info("Loading the " + file.getFileName()); - + if (log) Bukkit.getLogger().info("Loading the " + file.getFileName()); if (!newFile.exists()) { try { + String fileLocation = file.getFileLocation(); + //Switch between 1.12.2- and 1.13+ config version. + if (file == Files.CONFIG) { + if (Version.isOlder(Version.v1_13_R2)) { + fileLocation = "config1.12.2-Down.yml"; + } else { + fileLocation = "config1.13-Up.yml"; + } + } File serverFile = new File(plugin.getDataFolder(), "/" + file.getFileLocation()); - InputStream jarFile = getClass().getResourceAsStream("/" + file.getFileJar()); + InputStream jarFile = getClass().getResourceAsStream("/" + fileLocation); copyFile(jarFile, serverFile); } catch (Exception e) { - if (isLogging()) plugin.getLogger().info("Failed to load " + file.getFileName()); - + if (log) Bukkit.getLogger().info("Failed to load " + file.getFileName()); e.printStackTrace(); continue; } } - files.put(file, newFile); configurations.put(file, YamlConfiguration.loadConfiguration(newFile)); - - if (isLogging()) plugin.getLogger().info("Successfully loaded " + file.getFileName()); + if (log) Bukkit.getLogger().info("Successfully loaded " + file.getFileName()); } - - // Starts to load all the custom files. + //Starts to load all the custom files. if (homeFolders.size() > 0) { - if (isLogging()) plugin.getLogger().info("Loading custom files."); - + if (log) Bukkit.getLogger().info("Loading custom files."); for (String homeFolder : homeFolders) { File homeFile = new File(plugin.getDataFolder(), "/" + homeFolder); - if (homeFile.exists()) { String[] list = homeFile.list(); - if (list != null) { for (String name : list) { if (name.endsWith(".yml")) { - CustomFile file = new CustomFile(name, homeFolder); - + CustomFile file = new CustomFile(name, homeFolder, plugin); if (file.exists()) { customFiles.add(file); - - if (isLogging()) plugin.getLogger().info("Loaded new custom file: " + homeFolder + "/" + name + "."); + if (log) Bukkit.getLogger().info("Loaded new custom file: " + homeFolder + "/" + name + "."); } } } } + } else { homeFile.mkdir(); - if (isLogging()) plugin.getLogger().info("The folder " + homeFolder + "/ was not found so it was created."); - + if (log) Bukkit.getLogger().info("The folder " + homeFolder + "/ was not found so it was created."); for (String fileName : autoGenerateFiles.keySet()) { if (autoGenerateFiles.get(fileName).equalsIgnoreCase(homeFolder)) { homeFolder = autoGenerateFiles.get(fileName); - try { File serverFile = new File(plugin.getDataFolder(), homeFolder + "/" + fileName); InputStream jarFile = getClass().getResourceAsStream(homeFolder + "/" + fileName); copyFile(jarFile, serverFile); - - if (fileName.toLowerCase().endsWith(".yml")) customFiles.add(new CustomFile(fileName, homeFolder)); - - if (isLogging()) plugin.getLogger().info("Created new default file: " + homeFolder + "/" + fileName + "."); + if (fileName.toLowerCase().endsWith(".yml")) { + customFiles.add(new CustomFile(fileName, homeFolder, plugin)); + } + if (log) Bukkit.getLogger().info("Created new default file: " + homeFolder + "/" + fileName + "."); } catch (Exception e) { - if (isLogging()) plugin.getLogger().info("Failed to create new default file: " + homeFolder + "/" + fileName + "!"); + if (log) Bukkit.getLogger().info("Failed to create new default file: " + homeFolder + "/" + fileName + "!"); e.printStackTrace(); } } } } } - - if (isLogging()) plugin.getLogger().info("Finished loading custom files."); + if (log) Bukkit.getLogger().info("Finished loading custom files."); } - return this; } @@ -119,7 +125,7 @@ public class FileManager { * Turn on the logger system for the FileManager. * @param log True to turn it on and false for it to be off. */ - public FileManager setLog(boolean log) { + public FileManager logInfo(Boolean log) { this.log = log; return this; } @@ -128,7 +134,7 @@ public class FileManager { * Check if the logger is logging in console. * @return True if it is and false if it isn't. */ - public boolean isLogging() { + public Boolean isLogging() { return log; } @@ -185,21 +191,42 @@ public class FileManager { */ public CustomFile getFile(String name) { for (CustomFile file : customFiles) { - if (file.getName().equalsIgnoreCase(name)) return file; + if (file.getName().equalsIgnoreCase(name)) { + return file; + } } - return null; } /** * Saves the file from the loaded state to the file system. */ - public void saveFile(Files file) { + public void saveFile(Files file, boolean sync) { try { - configurations.get(file).save(files.get(file)); - } catch (IOException e) { - plugin.getLogger().warning("Could not save " + file.getFileName() + "!"); - + File targetFile = files.get(file); + FileConfiguration configuration = configurations.get(file); + + YamlConfiguration copy = new YamlConfiguration(); + configuration.getValues(false).forEach(copy :: set); + + BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + try { + copy.save(targetFile); + } catch (IOException e) { + Bukkit.getLogger().info("Could not save " + file.getFileName() + "!"); + e.printStackTrace(); + } + } + }; + if (sync) { + runnable.run(); + } else { + runnable.runTaskAsynchronously(plugin); + } + } catch (NullPointerException e) { + Bukkit.getLogger().info("File is null " + file.getFileName() + "!"); e.printStackTrace(); } } @@ -210,18 +237,16 @@ public class FileManager { */ public void saveFile(String name) { CustomFile file = getFile(name); - if (file != null) { try { file.getFile().save(new File(plugin.getDataFolder(), file.getHomeFolder() + "/" + file.getFileName())); - - if (isLogging()) plugin.getLogger().info("Successfully saved the " + file.getFileName() + "."); + if (log) Bukkit.getLogger().info("Successfuly saved the " + file.getFileName() + "."); } catch (Exception e) { - plugin.getLogger().warning("Could not save " + file.getFileName() + "!"); + Bukkit.getLogger().info("Could not save " + file.getFileName() + "!"); e.printStackTrace(); } } else { - if (isLogging()) plugin.getLogger().warning("The file " + name + ".yml could not be found!"); + if (log) Bukkit.getLogger().info("The file " + name + ".yml could not be found!"); } } @@ -230,7 +255,7 @@ public class FileManager { * @param file The custom file you are saving. * @return True if the file saved correct and false if there was an error. */ - public boolean saveFile(CustomFile file) { + public Boolean saveFile(CustomFile file) { return file.saveFile(); } @@ -246,18 +271,16 @@ public class FileManager { */ public void reloadFile(String name) { CustomFile file = getFile(name); - if (file != null) { try { file.file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + file.getHomeFolder() + "/" + file.getFileName())); - - if (isLogging()) plugin.getLogger().info("Successfully reloaded the " + file.getFileName() + "."); + if (log) Bukkit.getLogger().info("Successfuly reload the " + file.getFileName() + "."); } catch (Exception e) { - plugin.getLogger().warning("Could not reload the " + file.getFileName() + "!"); + Bukkit.getLogger().info("Could not reload the " + file.getFileName() + "!"); e.printStackTrace(); } } else { - if (isLogging()) plugin.getLogger().warning("The file " + name + ".yml could not be found!"); + if (log) Bukkit.getLogger().info("The file " + name + ".yml could not be found!"); } } @@ -265,70 +288,47 @@ public class FileManager { * Overrides the loaded state file and loads the filesystems file. * @return True if it reloaded correct and false if the file wasn't found. */ - public boolean reloadFile(CustomFile file) { + public Boolean reloadFile(CustomFile file) { return file.reloadFile(); } - + /** - * Was found here: ... + * Was found here: https://bukkit.org/threads/extracting-file-from-jar.16962 */ private void copyFile(InputStream in, File out) throws Exception { - try (InputStream fis = in; FileOutputStream fos = new FileOutputStream(out)) { + try (FileOutputStream fos = new FileOutputStream(out)) { byte[] buf = new byte[1024]; int i; - - while ((i = fis.read(buf)) != -1) { + while ((i = in.read(buf)) != -1) { fos.write(buf, 0, i); } - } - } - - public void reloadAllFiles() { - for (Files file : Files.values()) { - file.reloadFile(); - } - - for (CustomFile file : customFiles) { - file.reloadFile(); + } finally { + if (in != null) { + in.close(); + } + } } public enum Files { - - // ENUM_NAME("fileName.yml", "fileLocation.yml"), - // ENUM_NAME("fileName.yml", "newFileLocation.yml", "oldFileLocation.yml"), + + //ENUM_NAME("FileName.yml", "FilePath.yml"), CONFIG("config.yml", "config.yml"), - DATA("data.yml", "data.yml"), - MESSAGES("messages.yml", "messages.yml"), - TEST_FILE("test-file.yml", "test-file.yml"); - + DATA("Data.yml", "Data.yml"), + MESSAGES("Messages.yml", "Messages.yml"), + TEST_FILE("Test-File.yml", "Test-File.yml"); + private final String fileName; - private final String fileJar; private final String fileLocation; - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - private final FileManager fileManager = plugin.getStarter().getFileManager(); - + /** * The files that the server will try and load. * @param fileName The file name that will be in the plugin's folder. - * @param fileLocation The location the file in the plugin's folder. + * @param fileLocation The location the file is in while in the Jar. */ - Files(String fileName, String fileLocation) { - this(fileName, fileLocation, fileLocation); - } - - /** - * The files that the server will try and load. - * @param fileName The file name that will be in the plugin's folder. - * @param fileLocation The location of the file will be in the plugin's folder. - * @param fileJar The location of the file in the jar. - */ - Files(String fileName, String fileLocation, String fileJar) { + private Files(String fileName, String fileLocation) { this.fileName = fileName; this.fileLocation = fileLocation; - this.fileJar = fileJar; } /** @@ -346,57 +346,54 @@ public class FileManager { public String getFileLocation() { return fileLocation; } - - /** - * Get the location of the file in the jar. - * @return The location of the file in the jar. - */ - public String getFileJar() { - return fileJar; - } - + /** * Gets the file from the system. * @return The file from the system. */ public FileConfiguration getFile() { - return fileManager.getFile(this); + return getInstance().getFile(this); } /** * Saves the file from the loaded state to the file system. */ + public void saveFile(boolean sync) { + getInstance().saveFile(this, sync); + } + public void saveFile() { - fileManager.saveFile(this); + getInstance().saveFile(this, false); } /** * Overrides the loaded state file and loads the file systems file. */ - public void reloadFile() { - fileManager.reloadFile(this); + public void relaodFile() { + getInstance().reloadFile(this); } + } - + public class CustomFile { - - private final String name; - private final String fileName; - private final String homeFolder; + + private String name; + private Plugin plugin; + private String fileName; + private String homeFolder; private FileConfiguration file; - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - + /** * A custom file that is being made. * @param name Name of the file. * @param homeFolder The home folder of the file. + * @param plugin The plugin the files belong to. */ - public CustomFile(String name, String homeFolder) { + public CustomFile(String name, String homeFolder, Plugin plugin) { this.name = name.replace(".yml", ""); + this.plugin = plugin; this.fileName = name; this.homeFolder = homeFolder; - if (new File(plugin.getDataFolder(), "/" + homeFolder).exists()) { if (new File(plugin.getDataFolder(), "/" + homeFolder + "/" + name).exists()) { file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + homeFolder + "/" + name)); @@ -405,13 +402,11 @@ public class FileManager { } } else { new File(plugin.getDataFolder(), "/" + homeFolder).mkdir(); - - if (isLogging()) plugin.getLogger().info("The folder " + homeFolder + "/ was not found so it was created."); - + if (log) Bukkit.getLogger().info("The folder " + homeFolder + "/ was not found so it was created."); file = null; } } - + /** * Get the name of the file without the .yml part. * @return The name of the file without the .yml. @@ -419,7 +414,7 @@ public class FileManager { public String getName() { return name; } - + /** * Get the full name of the file. * @return Full name of the file. @@ -427,7 +422,7 @@ public class FileManager { public String getFileName() { return fileName; } - + /** * Get the name of the home folder of the file. * @return The name of the home folder the files are in. @@ -435,7 +430,15 @@ public class FileManager { public String getHomeFolder() { return homeFolder; } - + + /** + * Get the plugin the file belongs to. + * @return The plugin the file belongs to. + */ + public Plugin getPlugin() { + return plugin; + } + /** * Get the ConfigurationFile. * @return The ConfigurationFile of this file. @@ -443,7 +446,7 @@ public class FileManager { public FileConfiguration getFile() { return file; } - + /** * Check if the file actually exists in the file system. * @return True if it does and false if it doesn't. @@ -451,7 +454,7 @@ public class FileManager { public Boolean exists() { return file != null; } - + /** * Save the custom file. * @return True if it saved correct and false if something went wrong. @@ -460,43 +463,39 @@ public class FileManager { if (file != null) { try { file.save(new File(plugin.getDataFolder(), homeFolder + "/" + fileName)); - - if (isLogging()) plugin.getLogger().info("Successfully saved the " + fileName + "."); - + if (log) Bukkit.getLogger().info("Successfuly saved the " + fileName + "."); return true; } catch (Exception e) { - plugin.getLogger().warning("Could not save " + fileName + "!"); + Bukkit.getLogger().info("Could not save " + fileName + "!"); e.printStackTrace(); return false; } } else { - if (isLogging()) plugin.getLogger().warning("There was a null custom file that could not be found!"); + if (log) Bukkit.getLogger().info("There was a null custom file that could not be found!"); } - return false; } - + /** * Overrides the loaded state file and loads the filesystems file. - * @return True if it reloaded correct and false if the file wasn't found or error. + * @return True if it reloaded correct and false if the file wasn't found or errored. */ public Boolean reloadFile() { if (file != null) { try { file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + homeFolder + "/" + fileName)); - - if (isLogging()) plugin.getLogger().info("Successfully reloaded the " + fileName + "."); - + if (log) Bukkit.getLogger().info("Successfuly reload the " + fileName + "."); return true; } catch (Exception e) { - plugin.getLogger().warning("Could not reload the " + fileName + "!"); + Bukkit.getLogger().info("Could not reload the " + fileName + "!"); e.printStackTrace(); } } else { - if (isLogging()) plugin.getLogger().warning("There was a null custom file that was not found!"); + if (log) Bukkit.getLogger().info("There was a null custom file that was not found!"); } - return false; } + } + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/enums/Messages.java b/src/main/java/com/badbones69/crazyauctions/api/Messages.java similarity index 77% rename from src/main/java/com/badbones69/crazyauctions/api/enums/Messages.java rename to src/main/java/com/badbones69/crazyauctions/api/Messages.java index 2bfe4ce..23be245 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/enums/Messages.java +++ b/src/main/java/com/badbones69/crazyauctions/api/Messages.java @@ -1,8 +1,6 @@ -package com.badbones69.crazyauctions.api.enums; +package com.badbones69.crazyauctions.api; -import com.badbones69.crazyauctions.CrazyAuctions; import com.badbones69.crazyauctions.Methods; -import com.badbones69.crazyauctions.api.FileManager; import com.badbones69.crazyauctions.api.FileManager.Files; import org.bukkit.configuration.file.FileConfiguration; @@ -56,54 +54,47 @@ public enum Messages { "&9/Ah Expired/Collect - &eView and manage your cancelled and expired items.", "&9/Ah Listed - &eView and manage the items you are selling.", "&9/Ah Help - &eView this help menu.")); + + private static final FileManager fileManager = FileManager.getInstance(); private final String path; private String defaultMessage; private List defaultListMessage; - - private static final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - private static final Methods methods = plugin.getStarter().getMethods(); - Messages(String path, String defaultMessage) { + private Messages(String path, String defaultMessage) { this.path = path; this.defaultMessage = defaultMessage; } - Messages(String path, List defaultListMessage) { + private Messages(String path, List defaultListMessage) { this.path = path; this.defaultListMessage = defaultListMessage; } public static String convertList(List list) { - StringBuilder message = new StringBuilder(); - + String message = ""; for (String m : list) { - message.append(methods.color(m)).append("\n"); + message += Methods.color(m) + "\n"; } - - return message.toString(); + return message; } public static String convertList(List list, HashMap placeholders) { - StringBuilder message = new StringBuilder(); + String message = ""; for (String m : list) { - message.append(methods.color(m)).append("\n"); + message += Methods.color(m) + "\n"; } - for (String ph : placeholders.keySet()) { - message = new StringBuilder(methods.color(message.toString().replace(ph, placeholders.get(ph))).replace(ph, placeholders.get(ph).toLowerCase())); + message = Methods.color(message.replace(ph, placeholders.get(ph))).replace(ph, placeholders.get(ph).toLowerCase()); } - return message.toString(); + return message; } public static void addMissingMessages() { FileConfiguration messages = Files.MESSAGES.getFile(); boolean saveFile = false; - for (Messages message : values()) { if (!messages.contains("Messages." + message.getPath())) { saveFile = true; - if (message.getDefaultMessage() != null) { messages.set("Messages." + message.getPath(), message.getDefaultMessage()); } else { @@ -111,22 +102,23 @@ public enum Messages { } } } - - if (saveFile) Files.MESSAGES.saveFile(); + if (saveFile) { + Files.MESSAGES.saveFile(); + } } public String getMessage() { if (isList()) { if (exists()) { - return methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path))); + return Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path))); } else { - return methods.color(convertList(getDefaultListMessage())); + return Methods.color(convertList(getDefaultListMessage())); } } else { if (exists()) { - return methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path)); + return Methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path)); } else { - return methods.getPrefix(getDefaultMessage()); + return Methods.getPrefix(getDefaultMessage()); } } } @@ -135,18 +127,20 @@ public enum Messages { String message; if (isList()) { if (exists()) { - message = methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders)); + message = Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders)); } else { - message = methods.color(convertList(getDefaultListMessage(), placeholders)); + message = Methods.color(convertList(getDefaultListMessage(), placeholders)); } } else { if (exists()) { - message = methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path)); + message = Methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path)); } else { - message = methods.getPrefix(getDefaultMessage()); + message = Methods.getPrefix(getDefaultMessage()); } for (String ph : placeholders.keySet()) { - if (message.contains(ph)) message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase()); + if (message.contains(ph)) { + message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase()); + } } } return message; @@ -155,15 +149,15 @@ public enum Messages { public String getMessageNoPrefix() { if (isList()) { if (exists()) { - return methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path))); + return Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path))); } else { - return methods.color(convertList(getDefaultListMessage())); + return Methods.color(convertList(getDefaultListMessage())); } } else { if (exists()) { - return methods.color(Files.MESSAGES.getFile().getString("Messages." + path)); + return Methods.color(Files.MESSAGES.getFile().getString("Messages." + path)); } else { - return methods.color(getDefaultMessage()); + return Methods.color(getDefaultMessage()); } } } @@ -172,18 +166,20 @@ public enum Messages { String message; if (isList()) { if (exists()) { - message = methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders)); + message = Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders)); } else { - message = methods.color(convertList(getDefaultListMessage(), placeholders)); + message = Methods.color(convertList(getDefaultListMessage(), placeholders)); } } else { if (exists()) { - message = methods.color(Files.MESSAGES.getFile().getString("Messages." + path)); + message = Methods.color(Files.MESSAGES.getFile().getString("Messages." + path)); } else { - message = methods.color(getDefaultMessage()); + message = Methods.color(getDefaultMessage()); } for (String ph : placeholders.keySet()) { - if (message.contains(ph)) message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase()); + if (message.contains(ph)) { + message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase()); + } } } return message; @@ -212,4 +208,5 @@ public enum Messages { private List getDefaultListMessage() { return defaultListMessage; } + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/ShopType.java b/src/main/java/com/badbones69/crazyauctions/api/ShopType.java new file mode 100644 index 0000000..3c3e4ce --- /dev/null +++ b/src/main/java/com/badbones69/crazyauctions/api/ShopType.java @@ -0,0 +1,36 @@ +package com.badbones69.crazyauctions.api; + +public enum ShopType { + + SELL("Sell"), BID("Bid"); + + private final String name; + + /** + * @param name name of the Shop Type. + */ + private ShopType(String name) { + this.name = name; + } + + /** + * @param name name of the Type you want. + * @return Returns the Type as an Enum. + */ + public static ShopType getFromName(String name) { + for (ShopType type : ShopType.values()) { + if (type.getName().equalsIgnoreCase(name)) { + return type; + } + } + return null; + } + + /** + * @return Returns the type name as a string. + */ + public String getName() { + return name; + } + +} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/Version.java b/src/main/java/com/badbones69/crazyauctions/api/Version.java new file mode 100644 index 0000000..7b57a9d --- /dev/null +++ b/src/main/java/com/badbones69/crazyauctions/api/Version.java @@ -0,0 +1,128 @@ +package com.badbones69.crazyauctions.api; + +import org.bukkit.Bukkit; + +public enum Version { + + TOO_OLD(-1), + v1_7_R1(171), v1_7_R2(172), v1_7_R3(173), v1_7_R4(174), + v1_8_R1(181), v1_8_R2(182), v1_8_R3(183), + v1_9_R1(191), v1_9_R2(192), + v1_10_R1(1101), + v1_11_R1(1111), + v1_12_R1(1121), + v1_13_R2(1132), + v1_14_R1(1141), + v1_15_R1(1151), + v1_16_R1(1161), v1_16_R2(1162), v1_16_R3(1163), + TOO_NEW(-2); + + private static Version currentVersion; + private static Version latest; + private final int versionInteger; + + private Version(int versionInteger) { + this.versionInteger = versionInteger; + } + + /** + * + * @return Get the server's Minecraft version. + */ + public static Version getCurrentVersion() { + if (currentVersion == null) { + String ver = Bukkit.getServer().getClass().getPackage().getName(); + int v = Integer.parseInt(ver.substring(ver.lastIndexOf('.') + 1).replace("_", "").replace("R", "").replace("v", "")); + for (Version version : values()) { + if (version.getVersionInteger() == v) { + currentVersion = version; + break; + } + } + if (v > Version.getLatestVersion().getVersionInteger()) { + currentVersion = Version.getLatestVersion(); + } + if (currentVersion == null) { + currentVersion = Version.TOO_NEW; + } + } + return currentVersion; + } + + /** + * Get the latest version allowed by the Version class. + * @return The latest version. + */ + public static Version getLatestVersion() { + if (latest == null) { + Version v = Version.TOO_OLD; + for (Version version : values()) { + if (version.comparedTo(v) == 1) { + v = version; + } + } + return v; + } else { + return latest; + + } + } + + /** + * + * @return The server's minecraft version as an integer. + */ + public int getVersionInteger() { + return this.versionInteger; + } + + /** + * This checks if the current version is older, newer, or is the checked version. + * @param version The version you are checking. + * @return -1 if older, 0 if the same, and 1 if newer. + */ + public int comparedTo(Version version) { + int result = -1; + int current = this.getVersionInteger(); + int check = version.getVersionInteger(); + if (current > check || check == -2) {// check is newer then current + result = 1; + } else if (current == check) {// check is the same as current + result = 0; + } else if (check == -1) {// check is older then current + result = -1; + } + return result; + } + + /** + * Checks to see if the current version is newer then the checked version. + * @param version The version you are checking. + * @return True if newer then the checked version and false if the same or older. + */ + public static boolean isNewer(Version version) { + if (currentVersion == null) getCurrentVersion(); + return currentVersion.versionInteger > version.versionInteger || currentVersion.versionInteger == -2; + } + + /** + * Checks to see if the current version is the same as the checked version. + * @param version The version you are checking. + * @return True if both the current and checked version is the same and false if otherwise. + */ + public static boolean isSame(Version version) { + if (currentVersion == null) getCurrentVersion(); + return currentVersion.versionInteger == version.versionInteger; + } + + /** + * Checks to see if the current version is older than the checked version. + * @param version The version you are checking. + * @return True if older than the checked version and false if the same or newer. + */ + public static boolean isOlder(Version version) { + if (currentVersion == null) getCurrentVersion(); + return currentVersion.versionInteger < version.versionInteger || currentVersion.versionInteger == -1; + } + +} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/economy/Currency.java b/src/main/java/com/badbones69/crazyauctions/api/economy/Currency.java deleted file mode 100644 index dadec63..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/economy/Currency.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.badbones69.crazyauctions.api.economy; - -public enum Currency { - - VAULT("Vault"), - XP_LEVEL("XP_Level"), - XP_TOTAL("XP_Total"); - - private final String name; - - Currency(String name) { - this.name = name; - } - - /** - * Checks if it is a compatible currency. - * @param currency The currency name you are checking. - * @return True if it is supported and false if not. - */ - public static boolean isCurrency(String currency) { - for (Currency value : Currency.values()) { - if (currency.equalsIgnoreCase(value.getName())) return true; - } - - return false; - } - - /** - * Get a currency enum. - * @param currency The currency you want. - * @return The currency enum. - */ - public static Currency getCurrency(String currency) { - for (Currency value : Currency.values()) { - if (currency.equalsIgnoreCase(value.getName())) return value; - } - - return null; - } - - /** - * Get the name of the currency. - * @return The name of the currency. - */ - public String getName() { - return name; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/economy/CurrencyAPI.java b/src/main/java/com/badbones69/crazyauctions/api/economy/CurrencyAPI.java deleted file mode 100644 index cf760bc..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/economy/CurrencyAPI.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.badbones69.crazyauctions.api.economy; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.api.economy.vault.VaultSupport; -import com.badbones69.crazyauctions.api.enums.ShopCategories; -import org.bukkit.entity.Player; - -public class CurrencyAPI { - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - private final VaultSupport vaultSupport = plugin.getStarter().getVaultSupport(); - - /** - * Get the amount that a player has from a specific currency. - * @param player The player you wish to get the amount from. - * @param currency The currency you wish to get from. - * @return The amount that the player has of that currency. - */ - public int getCurrency(Player player, Currency currency) { - try { - switch (currency) { - case VAULT: - vaultSupport.getVault().getBalance(player); - break; - case XP_LEVEL: - player.getLevel(); - break; - case XP_TOTAL: - getTotalExperience(player); - break; - } - } catch (Exception | NoClassDefFoundError ignored) {} - return 0; - } - - /** - * Take an amount from a player's currency. - * @param player The player you wish to take from. - * @param option The ShopOption you wish to use. - */ - public void takeCurrency(Player player, ShopCategories option) { - // takeCurrency(player, option.getCurrency(), option.getCost()); - } - - /** - * Take an amount from a player's currency. - * @param player The player you wish to take from. - * @param currency The currency you wish to use. - * @param amount The amount you want to take. - */ - public void takeCurrency(Player player, Currency currency, int amount) { - try { - switch (currency) { - case VAULT: - vaultSupport.getVault().withdrawPlayer(player, amount); - break; - case XP_LEVEL: - player.setLevel(player.getLevel() - amount); - break; - case XP_TOTAL: - takeTotalExperience(player, amount); - break; - } - } catch (Exception | NoClassDefFoundError ignored) {} - } - - /** - * Give an amount to a player's currency. - * @param player The player you are giving to. - * @param currency The currency you want to use. - * @param amount The amount you are giving to the player. - */ - public void giveCurrency(Player player, Currency currency, int amount) { - try { - switch (currency) { - case VAULT: - vaultSupport.getVault().depositPlayer(player, amount); - break; - case XP_LEVEL: - player.setLevel(player.getLevel() + amount); - break; - case XP_TOTAL: - takeTotalExperience(player, -amount); - break; - } - } catch (Exception | NoClassDefFoundError ignored) {} - } - - /** - * Checks if the player has enough of a currency. - * @param player The player you are checking. - * @param option The ShopOption you wish to check. - * @return True if they have enough to buy it or false if they don't. - */ - public boolean canBuy(Player player, ShopCategories option) { - return canBuy(player, option.getCurrency(), option.getCost()); - } - - /** - * Checks if the player has enough of a currency. - * @param player The player you are checking. - * @param currency The currency you wish to check. - * @param cost The cost of the item you are checking. - * @return True if they have enough to buy it or false if they don't. - */ - public boolean canBuy(Player player, Currency currency, int cost) { - return getCurrency(player, currency) >= cost; - } - - private void takeTotalExperience(Player player, int amount) { - int total = getTotalExperience(player) - amount; - player.setTotalExperience(0); - player.setTotalExperience(total); - player.setLevel(0); - player.setExp(0); - - while (total > player.getExpToLevel()) { - total -= player.getExpToLevel(); - player.setLevel(player.getLevel() + 1); - } - - float xp = (float) total / (float) player.getExpToLevel(); - player.setExp(xp); - } - - private int getTotalExperience(Player player) { // https://www.spigotmc.org/threads/72804 - int experience; - int level = player.getLevel(); - - if (level >= 0 && level <= 15) { - experience = (int) Math.ceil(Math.pow(level, 2) + (6 * level)); - int requiredExperience = 2 * level + 7; - double currentExp = Double.parseDouble(Float.toString(player.getExp())); - experience += Math.ceil(currentExp * requiredExperience); - return experience; - } else if (level > 15 && level <= 30) { - experience = (int) Math.ceil((2.5 * Math.pow(level, 2) - (40.5 * level) + 360)); - int requiredExperience = 5 * level - 38; - double currentExp = Double.parseDouble(Float.toString(player.getExp())); - experience += Math.ceil(currentExp * requiredExperience); - return experience; - } else { - experience = (int) Math.ceil((4.5 * Math.pow(level, 2) - (162.5 * level) + 2220)); - int requiredExperience = 9 * level - 158; - double currentExp = Double.parseDouble(Float.toString(player.getExp())); - experience += Math.ceil(currentExp * requiredExperience); - return experience; - } - } - - /** - * Loads the vault currency if it is on the server. - */ - public void loadCurrency() { - vaultSupport.loadVault(); - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/economy/vault/VaultSupport.java b/src/main/java/com/badbones69/crazyauctions/api/economy/vault/VaultSupport.java deleted file mode 100644 index b5d80f1..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/economy/vault/VaultSupport.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.badbones69.crazyauctions.api.economy.vault; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.utils.func.PluginSupport; -import net.milkbowl.vault.economy.Economy; -import org.bukkit.plugin.RegisteredServiceProvider; - -public class VaultSupport { - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - private Economy vault = null; - - public Economy getVault() { - return vault; - } - - public void loadVault() { - if (PluginSupport.VAULT.isPluginLoaded()) { - RegisteredServiceProvider rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class); - - if (rsp != null) vault = rsp.getProvider(); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java b/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java index 12da0b2..206adf1 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java +++ b/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java @@ -10,4 +10,5 @@ public enum CancelledReason { * Cancelled by the player them self. */ PLAYER_FORCE_CANCEL() + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/enums/ShopCategories.java b/src/main/java/com/badbones69/crazyauctions/api/enums/ShopCategories.java deleted file mode 100644 index e2d84d3..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/enums/ShopCategories.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.badbones69.crazyauctions.api.enums; - -import com.badbones69.crazyauctions.api.economy.Currency; -import com.badbones69.crazyauctions.utils.ItemBuilder; - -import java.util.HashMap; - -public enum ShopCategories { - - SELL("Sell"), - BID("Bid"); - - private final String name; - - private final HashMap shopCategories = new HashMap<>(); - - /** - * @param name name of the Shop Type. - */ - ShopCategories(String name) { - this.name = name; - } - - /** - * @param name name of the Type you want. - * @return Returns the Type as an Enum. - */ - public static ShopCategories getFromName(String name) { - for (ShopCategories type : ShopCategories.values()) { - if (type.getName().equalsIgnoreCase(name)) return type; - } - - return null; - } - - public Currency getCurrency() { - return shopCategories.get(this).currency; - } - - public int getCost() { - return shopCategories.get(this).cost; - } - - /** - * @return Returns the type name as a string. - */ - public String getName() { - return name; - } - - private static class Options { - - private final ItemBuilder itemBuilder; - - private final int slot; - private final boolean inMenu; - private int cost; - private final Currency currency; - - public Options(ItemBuilder itemBuilder, int slot, boolean inMenu, int cost, Currency currency) { - this.itemBuilder = itemBuilder; - this.slot = slot; - this.inMenu = inMenu; - this.cost = cost; - this.currency = currency; - } - - public ItemBuilder getItemBuilder() { - return itemBuilder; - } - - public int getSlot() { - return slot; - } - - public int getCost() { - return cost; - } - - public Currency getCurrency() { - return currency; - } - - public boolean isInMenu() { - return inMenu; - } - - public void setCost(int cost) { - this.cost = cost; - } - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java index 4da1a46..ed32bfa 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java @@ -6,18 +6,21 @@ import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; /** + * * @author BadBones69 * * This event is fired when a player buys something from the selling auction house. + * */ public class AuctionBuyEvent extends Event { - private final HandlerList handlers = new HandlerList(); - private final Player player; - private final long price; - private final ItemStack item; + private static final HandlerList handlers = new HandlerList(); + private Player player; + private long price; + private ItemStack item; /** + * * @param player The player who bought the item. * @param item The item that was bought. * @param price The price of the item. @@ -27,7 +30,11 @@ public class AuctionBuyEvent extends Event { this.item = item; this.price = price; } - + + public static HandlerList getHandlerList() { + return handlers; + } + public HandlerList getHandlers() { return handlers; } @@ -43,4 +50,5 @@ public class AuctionBuyEvent extends Event { public long getPrice() { return price; } + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java index fe13b63..fb013e2 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java @@ -8,20 +8,23 @@ import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; /** + * * @author BadBones69 * * This event is fired when a player's item is cancelled. + * */ public class AuctionCancelledEvent extends Event { - private final HandlerList handlers = new HandlerList(); + private static final HandlerList handlers = new HandlerList(); private OfflinePlayer offlinePlayer; private Player onlinePlayer; - private final boolean isOnline; - private final ItemStack item; - private final CancelledReason reason; + private boolean isOnline; + private ItemStack item; + private CancelledReason reason; /** + * * @param offlinePlayer The player whose item is cancelled. * @param item The item that is cancelled. */ @@ -33,6 +36,7 @@ public class AuctionCancelledEvent extends Event { } /** + * * @param onlinePlayer The player whose item is cancelled. * @param item The item that is cancelled. */ @@ -43,6 +47,10 @@ public class AuctionCancelledEvent extends Event { this.reason = reason; } + public static HandlerList getHandlerList() { + return handlers; + } + public HandlerList getHandlers() { return handlers; } @@ -66,4 +74,5 @@ public class AuctionCancelledEvent extends Event { public CancelledReason getReason() { return reason; } + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java index 5102904..9a99ed5 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java @@ -7,19 +7,22 @@ import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; /** + * * @author BadBones69 * * This event is fired when a player item expires. + * */ public class AuctionExpireEvent extends Event { - private final HandlerList handlers = new HandlerList(); + private static final HandlerList handlers = new HandlerList(); private OfflinePlayer offlinePlayer; private Player onlinePlayer; - private final boolean isOnline; - private final ItemStack item; + private boolean isOnline; + private ItemStack item; /** + * * @param offlinePlayer The player whose item is expiring. * @param item The item that is expiring. */ @@ -30,6 +33,7 @@ public class AuctionExpireEvent extends Event { } /** + * * @param onlinePlayer The player whose item is expiring. * @param item The item that is expiring. */ @@ -39,6 +43,10 @@ public class AuctionExpireEvent extends Event { this.isOnline = true; } + public static HandlerList getHandlerList() { + return handlers; + } + public HandlerList getHandlers() { return handlers; } @@ -58,4 +66,5 @@ public class AuctionExpireEvent extends Event { public ItemStack getItem() { return item; } + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java index 2d7895f..743ea14 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java @@ -1,37 +1,44 @@ package com.badbones69.crazyauctions.api.events; -import com.badbones69.crazyauctions.api.enums.ShopCategories; +import com.badbones69.crazyauctions.api.ShopType; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; /** + * * @author BadBones69 * * This event is fired when a new item is listed onto the auction house. + * */ public class AuctionListEvent extends Event { - private final HandlerList handlers = new HandlerList(); - private final Player player; - private final long price; - private final ShopCategories shop; - private final ItemStack item; + private static final HandlerList handlers = new HandlerList(); + private Player player; + private long price; + private ShopType shop; + private ItemStack item; /** + * * @param player The player who is listing the item. * @param shop The shop type the item is being listed to. * @param item The item being listed. * @param price The price the item is being listed for. */ - public AuctionListEvent(Player player, ShopCategories shop, ItemStack item, long price) { + public AuctionListEvent(Player player, ShopType shop, ItemStack item, long price) { this.player = player; this.shop = shop; this.item = item; this.price = price; } + public static HandlerList getHandlerList() { + return handlers; + } + public HandlerList getHandlers() { return handlers; } @@ -40,7 +47,7 @@ public class AuctionListEvent extends Event { return player; } - public ShopCategories getShopType() { + public ShopType getShopType() { return shop; } @@ -51,4 +58,5 @@ public class AuctionListEvent extends Event { public long getPrice() { return price; } + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java index 5c5bb99..0b391f1 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java @@ -6,16 +6,18 @@ import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; /** + * * This event is fired when a player places a new bid onto an item in the auction house. */ public class AuctionNewBidEvent extends Event { - private final HandlerList handlers = new HandlerList(); - private final Player player; - private final long bid; - private final ItemStack item; + private static final HandlerList handlers = new HandlerList(); + private Player player; + private long bid; + private ItemStack item; /** + * * @param player The player who placed the bid. * @param item The item that was bid on. * @param bid The amount of money that was bid. @@ -26,6 +28,10 @@ public class AuctionNewBidEvent extends Event { this.bid = bid; } + public static HandlerList getHandlerList() { + return handlers; + } + public HandlerList getHandlers() { return handlers; } @@ -41,4 +47,5 @@ public class AuctionNewBidEvent extends Event { public long getBid() { return bid; } + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java index 0f3da3e..b91419a 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java @@ -6,18 +6,21 @@ import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; /** + * * @author BadBones69 * * This event is fired when a bidding item's time has run out and so a player wins the item. + * */ public class AuctionWinBidEvent extends Event { - private final HandlerList handlers = new HandlerList(); - private final Player player; - private final long bid; - private final ItemStack item; + private static final HandlerList handlers = new HandlerList(); + private Player player; + private long bid; + private ItemStack item; /** + * * @param player The player who won the item. * @param item The item that was won. * @param bid The bid that was placed on the item. @@ -28,6 +31,10 @@ public class AuctionWinBidEvent extends Event { this.bid = bid; } + public static HandlerList getHandlerList() { + return handlers; + } + public HandlerList getHandlers() { return handlers; } @@ -43,4 +50,5 @@ public class AuctionWinBidEvent extends Event { public long getBid() { return bid; } + } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java b/src/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java new file mode 100644 index 0000000..83deb9e --- /dev/null +++ b/src/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java @@ -0,0 +1,22 @@ +package com.badbones69.crazyauctions.controllers; + +import com.badbones69.crazyauctions.api.FileManager; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class DupePatch implements Listener { + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPreCommand(PlayerCommandPreprocessEvent event) { + Player player = event.getPlayer(); + + boolean macro = FileManager.Files.CONFIG.getFile().getBoolean("Settings.Patches.Macro-Dupe", true); + + if (!macro) return; + + if (!player.isOnline() || player.isDead()) event.setCancelled(true); + } +} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java b/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java new file mode 100644 index 0000000..bfd2d9c --- /dev/null +++ b/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java @@ -0,0 +1,950 @@ +package com.badbones69.crazyauctions.controllers; + +import com.badbones69.crazyauctions.Methods; +import com.badbones69.crazyauctions.api.*; +import com.badbones69.crazyauctions.api.FileManager.Files; +import com.badbones69.crazyauctions.api.enums.CancelledReason; +import com.badbones69.crazyauctions.api.events.AuctionBuyEvent; +import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent; +import com.badbones69.crazyauctions.api.events.AuctionNewBidEvent; +import com.badbones69.crazyauctions.currency.CurrencyManager; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.logging.Level; + +public class GUI implements Listener { + + private static HashMap bidding = new HashMap<>(); + private static HashMap biddingID = new HashMap<>(); + private static HashMap shopType = new HashMap<>(); // Shop Type + private static HashMap shopCategory = new HashMap<>(); // Category Type + private static HashMap> List = new HashMap<>(); + private static HashMap IDs = new HashMap<>(); + private static CrazyAuctions crazyAuctions = CrazyAuctions.getInstance(); + private static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions"); + + public static void openShop(Player player, ShopType sell, Category cat, int page) { + Methods.updateAuction(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); + List items = new ArrayList<>(); + List ID = new ArrayList<>(); + if (!data.contains("Items")) { + data.set("Items.Clear", null); + Files.DATA.saveFile(); + } + if (cat != null) { + shopCategory.put(player, cat); + } else { + shopCategory.put(player, Category.NONE); + } + if (data.contains("Items")) { + for (String i : data.getConfigurationSection("Items").getKeys(false)) { + List lore = new ArrayList<>(); + if (data.getItemStack("Items." + i + ".Item") != null && (cat.getItems().contains(data.getItemStack("Items." + i + ".Item").getType()) || cat == Category.NONE)) { + if (data.getBoolean("Items." + i + ".Biddable")) { + if (sell == ShopType.BID) { + String seller = data.getString("Items." + i + ".Seller"); + String topbidder = data.getString("Items." + i + ".TopBidder"); + 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")); + } + } 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)); + ID.add(data.getInt("Items." + i + ".StoreID")); + } + } + } + } + } + int maxPage = Methods.getMaxPage(items); + for (; page > maxPage; page--) ; + Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page)); + List options = new ArrayList<>(); + options.add("SellingItems"); + options.add("Cancelled/ExpiredItems"); + options.add("PreviousPage"); + options.add("Refesh"); + options.add("NextPage"); + options.add("Category1"); + options.add("Category2"); + if (sell == ShopType.SELL) { + shopType.put(player, ShopType.SELL); + if (crazyAuctions.isBiddingEnabled()) { + options.add("Bidding/Selling.Selling"); + } + options.add("WhatIsThis.SellingShop"); + } + if (sell == ShopType.BID) { + shopType.put(player, ShopType.BID); + if (crazyAuctions.isSellingEnabled()) { + options.add("Bidding/Selling.Bidding"); + } + options.add("WhatIsThis.BiddingShop"); + } + for (String o : options) { + if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { + if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { + continue; + } + } + String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item"); + String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); + List lore = new ArrayList<>(); + int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot"); + String cName = Methods.color(config.getString("Settings.GUISettings.Category-Settings." + shopCategory.get(player).getName() + ".Name")); + 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)); + } else { + inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); + } + } + for (ItemStack item : Methods.getPage(items, page)) { + int slot = inv.firstEmpty(); + inv.setItem(slot, item); + } + List Id = new ArrayList<>(Methods.getPageInts(ID, page)); + List.put(player, Id); + player.openInventory(inv); + } + + public static void openCategories(Player player, ShopType shop) { + Methods.updateAuction(); + FileConfiguration config = Files.CONFIG.getFile(); + Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Categories"))); + List options = new ArrayList<>(); + options.add("OtherSettings.Back"); + options.add("OtherSettings.WhatIsThis.Categories"); + options.add("Category-Settings.Armor"); + options.add("Category-Settings.Weapons"); + options.add("Category-Settings.Tools"); + options.add("Category-Settings.Food"); + options.add("Category-Settings.Potions"); + options.add("Category-Settings.Blocks"); + options.add("Category-Settings.Other"); + options.add("Category-Settings.None"); + for (String o : options) { + if (config.contains("Settings.GUISettings." + o + ".Toggle")) { + if (!config.getBoolean("Settings.GUISettings." + o + ".Toggle")) { + continue; + } + } + String id = config.getString("Settings.GUISettings." + o + ".Item"); + String name = config.getString("Settings.GUISettings." + o + ".Name"); + int slot = config.getInt("Settings.GUISettings." + o + ".Slot"); + 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)); + } + } + shopType.put(player, shop); + player.openInventory(inv); + } + + public static void openPlayersCurrentList(Player player, int page) { + Methods.updateAuction(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); + List items = new ArrayList<>(); + List ID = new ArrayList<>(); + Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Players-Current-Items"))); + List options = new ArrayList<>(); + options.add("Back"); + options.add("WhatIsThis.CurrentItems"); + for (String o : options) { + if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { + if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { + continue; + } + } + 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"); + 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)); + } + } + if (data.contains("Items")) { + for (String i : data.getConfigurationSection("Items").getKeys(false)) { + if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { + List lore = new ArrayList<>(); + 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)); + ID.add(data.getInt("Items." + i + ".StoreID")); + } + } + } + for (ItemStack item : Methods.getPage(items, page)) { + int slot = inv.firstEmpty(); + inv.setItem(slot, item); + } + List Id = new ArrayList<>(Methods.getPageInts(ID, page)); + List.put(player, Id); + player.openInventory(inv); + } + + public static void openPlayersExpiredList(Player player, int page) { + Methods.updateAuction(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); + List items = new ArrayList<>(); + List ID = new ArrayList<>(); + if (data.contains("OutOfTime/Cancelled")) { + for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { + if (data.getString("OutOfTime/Cancelled." + i + ".Seller") != null) { + if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getName())) { + List lore = new ArrayList<>(); + 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)); + ID.add(data.getInt("OutOfTime/Cancelled." + i + ".StoreID")); + } + } + } + } + int maxPage = Methods.getMaxPage(items); + for (; page > maxPage; page--) ; + Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Cancelled/Expired-Items") + " #" + page)); + List options = new ArrayList<>(); + options.add("Back"); + options.add("PreviousPage"); + options.add("Return"); + options.add("NextPage"); + options.add("WhatIsThis.Cancelled/ExpiredItems"); + for (String o : options) { + if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { + if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { + continue; + } + } + 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"); + 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)); + } + } + for (ItemStack item : Methods.getPage(items, page)) { + int slot = inv.firstEmpty(); + inv.setItem(slot, item); + } + List Id = new ArrayList<>(Methods.getPageInts(ID, page)); + List.put(player, Id); + player.openInventory(inv); + } + + public static void openBuying(Player player, String ID) { + Methods.updateAuction(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); + if (!data.contains("Items." + ID)) { + openShop(player, ShopType.SELL, shopCategory.get(player), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); + return; + } + Inventory inv = Bukkit.createInventory(null, 9, Methods.color(config.getString("Settings.Buying-Item"))); + List options = new ArrayList<>(); + options.add("Confirm"); + options.add("Cancel"); + for (String o : options) { + String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item"); + String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); + ItemStack item; + 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); + } + if (o.equals("Confirm")) { + inv.setItem(0, item); + inv.setItem(1, item); + inv.setItem(2, item); + inv.setItem(3, item); + } + if (o.equals("Cancel")) { + inv.setItem(5, item); + inv.setItem(6, item); + inv.setItem(7, item); + inv.setItem(8, item); + } + } + ItemStack item = data.getItemStack("Items." + ID + ".Item"); + List lore = new ArrayList<>(); + for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) { + 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)); + IDs.put(player, ID); + player.openInventory(inv); + } + + public static void openBidding(Player player, String ID) { + Methods.updateAuction(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); + if (!data.contains("Items." + ID)) { + openShop(player, ShopType.BID, shopCategory.get(player), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); + return; + } + Inventory inv = Bukkit.createInventory(null, 27, Methods.color(config.getString("Settings.Bidding-On-Item"))); + if (!bidding.containsKey(player)) bidding.put(player, 0); + if (Version.isNewer(Version.v1_12_R1)) { + 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")); + } else { + inv.setItem(9, Methods.makeItem("160:5", 1, "&a+1")); + inv.setItem(10, Methods.makeItem("160:5", 1, "&a+10")); + inv.setItem(11, Methods.makeItem("160:5", 1, "&a+100")); + inv.setItem(12, Methods.makeItem("160:5", 1, "&a+1000")); + inv.setItem(14, Methods.makeItem("160:14", 1, "&c-1000")); + inv.setItem(15, Methods.makeItem("160:14", 1, "&c-100")); + inv.setItem(16, Methods.makeItem("160:14", 1, "&c-10")); + inv.setItem(17, Methods.makeItem("160:14", 1, "&c-1")); + } + 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(4, getBiddingItem(player, ID)); + player.openInventory(inv); + } + + public static void openViewer(Player player, String other, int page) { + Methods.updateAuction(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); + List items = new ArrayList<>(); + List ID = new ArrayList<>(); + if (!data.contains("Items")) { + data.set("Items.Clear", null); + Files.DATA.saveFile(); + } + if (data.contains("Items")) { + for (String i : data.getConfigurationSection("Items").getKeys(false)) { + if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(other)) { + List lore = new ArrayList<>(); + if (data.getBoolean("Items." + i + ".Biddable")) { + String seller = data.getString("Items." + i + ".Seller"); + String topbidder = data.getString("Items." + i + ".TopBidder"); + 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")))); + } + } else { + for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) { + 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)); + ID.add(data.getInt("Items." + i + ".StoreID")); + } + } + } + int maxPage = Methods.getMaxPage(items); + for (; page > maxPage; page--) ; + Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page)); + List options = new ArrayList<>(); + options.add("WhatIsThis.Viewing"); + for (String o : options) { + if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { + if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { + continue; + } + } + 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"); + 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)); + } + } + for (ItemStack item : Methods.getPage(items, page)) { + int slot = inv.firstEmpty(); + inv.setItem(slot, item); + } + List.put(player, new ArrayList<>(Methods.getPageInts(ID, page))); + player.openInventory(inv); + } + + public static ItemStack getBiddingGlass(Player player, String ID) { + FileConfiguration config = Files.CONFIG.getFile(); + String id = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item"); + String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name"); + ItemStack item; + int bid = bidding.get(player); + if (config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) { + List lore = new ArrayList<>(); + 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); + } + return item; + } + + public static ItemStack getBiddingItem(Player player, String ID) { + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); + String seller = data.getString("Items." + ID + ".Seller"); + String topbidder = data.getString("Items." + ID + ".TopBidder"); + ItemStack item = data.getItemStack("Items." + ID + ".Item"); + List lore = new ArrayList<>(); + for (String l : config.getStringList("Settings.GUISettings.Bidding")) { + 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); + } + + private static void playClick(Player player) { + if (Files.CONFIG.getFile().contains("Settings.Sounds.Toggle")) { + if (Files.CONFIG.getFile().getBoolean("Settings.Sounds.Toggle")) { + String sound = Files.CONFIG.getFile().getString("Settings.Sounds.Sound"); + try { + player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1); + } catch (Exception e) { + if (Methods.getVersion() >= 191) { + player.playSound(player.getLocation(), Sound.valueOf("UI_BUTTON_CLICK"), 1, 1); + } else { + player.playSound(player.getLocation(), Sound.valueOf("CLICK"), 1, 1); + } + Bukkit.getLogger().log(Level.WARNING, "[Crazy Auctions]>> You set the sound to " + sound + " and this is not a sound for your minecraft version. " + "Please go to the config and set a correct sound or turn the sound off in the toggle setting."); + } + } + } else { + if (Methods.getVersion() >= 191) { + player.playSound(player.getLocation(), Sound.valueOf("UI_BUTTON_CLICK"), 1, 1); + } else { + player.playSound(player.getLocation(), Sound.valueOf("CLICK"), 1, 1); + } + } + } + + @EventHandler + public void onInvClose(InventoryCloseEvent e) { + FileConfiguration config = Files.CONFIG.getFile(); + Inventory inv = e.getInventory(); + Player player = (Player) e.getPlayer(); + if (inv != null) { + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) { + bidding.remove(player); + } + } + } + + @EventHandler + public void onInvClick(InventoryClickEvent e) { + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); + Player player = (Player) e.getWhoClicked(); + final Inventory inv = e.getInventory(); + if (inv != null) { + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Categories")))) { + e.setCancelled(true); + int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { + if (e.getCurrentItem() != null) { + ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { + if (item.getItemMeta().hasDisplayName()) { + for (Category cat : Category.values()) { + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.Category-Settings." + cat.getName() + ".Name")))) { + openShop(player, shopType.get(player), cat, 1); + playClick(player); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { + openShop(player, shopType.get(player), shopCategory.get(player), 1); + playClick(player); + return; + } + } + } + } + } + } + } + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) { + e.setCancelled(true); + int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { + if (e.getCurrentItem() != null) { + ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { + if (item.getItemMeta().hasDisplayName()) { + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bid.Name")))) { + String ID = biddingID.get(player); + int bid = bidding.get(player); + String topBidder = data.getString("Items." + ID + ".TopBidder"); + if (CurrencyManager.getMoney(player) < bid) { + HashMap placeholders = new HashMap<>(); + placeholders.put("%Money_Needed%", (bid - CurrencyManager.getMoney(player)) + ""); + placeholders.put("%money_needed%", (bid - CurrencyManager.getMoney(player)) + ""); + player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders)); + return; + } + if (data.getLong("Items." + ID + ".Price") > bid) { + player.sendMessage(Messages.BID_MORE_MONEY.getMessage()); + return; + } + if (data.getLong("Items." + ID + ".Price") >= bid && !topBidder.equalsIgnoreCase("None")) { + player.sendMessage(Messages.BID_MORE_MONEY.getMessage()); + return; + } + Bukkit.getPluginManager().callEvent(new AuctionNewBidEvent(player, data.getItemStack("Items." + ID + ".Item"), bid)); + data.set("Items." + ID + ".Price", bid); + data.set("Items." + ID + ".TopBidder", player.getName()); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Bid%", bid + ""); + player.sendMessage(Messages.BID_MESSAGE.getMessage(placeholders)); + Files.DATA.saveFile(); + bidding.put(player, 0); + player.closeInventory(); + playClick(player); + return; + } + HashMap priceEdits = new HashMap<>(); + priceEdits.put("&a+1", 1); + priceEdits.put("&a+10", 10); + priceEdits.put("&a+100", 100); + priceEdits.put("&a+1000", 1000); + priceEdits.put("&c-1", -1); + priceEdits.put("&c-10", -10); + priceEdits.put("&c-100", -100); + priceEdits.put("&c-1000", -1000); + for (String price : priceEdits.keySet()) { + if (item.getItemMeta().getDisplayName().equals(Methods.color(price))) { + try { + bidding.put(player, (bidding.get(player) + priceEdits.get(price))); + inv.setItem(4, getBiddingItem(player, biddingID.get(player))); + inv.setItem(13, getBiddingGlass(player, biddingID.get(player))); + playClick(player); + return; + } catch (Exception ex) { + player.closeInventory(); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); + return; + } + } + } + } + } + } + } + } + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.GUIName")))) { + e.setCancelled(true); + final int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { + if (e.getCurrentItem() != null) { + final ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { + if (item.getItemMeta().hasDisplayName()) { + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) { + Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + openShop(player, shopType.get(player), shopCategory.get(player), page + 1); + playClick(player); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) { + Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + if (page == 1) page++; + openShop(player, shopType.get(player), shopCategory.get(player), page - 1); + playClick(player); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Refesh.Name")))) { + Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + openShop(player, shopType.get(player), shopCategory.get(player), page); + playClick(player); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Selling.Name")))) { + openShop(player, ShopType.BID, shopCategory.get(player), 1); + playClick(player); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Bidding.Name")))) { + openShop(player, ShopType.SELL, shopCategory.get(player), 1); + playClick(player); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancelled/ExpiredItems.Name")))) { + openPlayersExpiredList(player, 1); + playClick(player); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.SellingItems.Name")))) { + openPlayersCurrentList(player, 1); + playClick(player); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category1.Name")))) { + openCategories(player, shopType.get(player)); + playClick(player); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category2.Name")))) { + openCategories(player, shopType.get(player)); + playClick(player); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name")))) { + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name")))) { + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name")))) { + return; + } + } + if (List.containsKey(player)) { + if (List.get(player).size() >= slot) { + int id = List.get(player).get(slot); + boolean T = false; + if (data.contains("Items")) { + for (String i : data.getConfigurationSection("Items").getKeys(false)) { + int ID = data.getInt("Items." + i + ".StoreID"); + if (id == ID) { + if (player.hasPermission("crazyAuctions.admin") || player.hasPermission("crazyauctions.force-end")) { + if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) { + int num = 1; + for (; data.contains("OutOfTime/Cancelled." + num); num++) ; + String seller = data.getString("Items." + i + ".Seller"); + Player sellerPlayer = Methods.getPlayer(seller); + if (Methods.isOnline(seller) && sellerPlayer != null) { + sellerPlayer.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage()); + } + AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Bukkit.getOfflinePlayer(seller)), data.getItemStack("Items." + i + ".Item"), CancelledReason.ADMIN_FORCE_CANCEL); + Bukkit.getPluginManager().callEvent(event); + data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); + data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time")); + data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); + data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item")); + data.set("Items." + i, null); + Files.DATA.saveFile(); + player.sendMessage(Messages.ADMIN_FORCE_CENCELLED.getMessage()); + playClick(player); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + openShop(player, shopType.get(player), shopCategory.get(player), page); + return; + } + } + 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 name = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name"); + ItemStack I; + 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); + } + inv.setItem(slot, I); + playClick(player); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); + return; + } + long cost = data.getLong("Items." + i + ".Price"); + if (CurrencyManager.getMoney(player) < cost) { + String it = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Item"); + String name = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name"); + ItemStack I; + 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); + } + inv.setItem(slot, I); + playClick(player); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); + return; + } + 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 name = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name"); + ItemStack I; + 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); + } + inv.setItem(slot, I); + playClick(player); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); + return; + } + playClick(player); + openBidding(player, i); + biddingID.put(player, i); + } else { + playClick(player); + openBuying(player, i); + } + return; + } + } + } + if (!T) { + playClick(player); + openShop(player, shopType.get(player), shopCategory.get(player), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); + return; + } + } + } + } + } + } + } + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Buying-Item")))) { + e.setCancelled(true); + int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { + if (e.getCurrentItem() != null) { + ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { + if (item.getItemMeta().hasDisplayName()) { + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Confirm.Name")))) { + String ID = IDs.get(player); + long cost = data.getLong("Items." + ID + ".Price"); + String seller = data.getString("Items." + ID + ".Seller"); + if (!data.contains("Items." + ID)) { + playClick(player); + openShop(player, shopType.get(player), shopCategory.get(player), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); + return; + } + if (Methods.isInvFull(player)) { + playClick(player); + player.closeInventory(); + player.sendMessage(Messages.INVENTORY_FULL.getMessage()); + return; + } + if (CurrencyManager.getMoney(player) < cost) { + playClick(player); + player.closeInventory(); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Money_Needed%", (cost - CurrencyManager.getMoney(player)) + ""); + placeholders.put("%money_needed%", (cost - CurrencyManager.getMoney(player)) + ""); + player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders)); + return; + } + ItemStack i = data.getItemStack("Items." + ID + ".Item"); + Bukkit.getPluginManager().callEvent(new AuctionBuyEvent(player, i, cost)); + CurrencyManager.removeMoney(player, cost); + CurrencyManager.addMoney(Methods.getOfflinePlayer(seller), cost); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Price%", Methods.getPrice(ID, false)); + placeholders.put("%price%", Methods.getPrice(ID, false)); + placeholders.put("%Player%", player.getName()); + placeholders.put("%player%", player.getName()); + player.sendMessage(Messages.BOUGHT_ITEM.getMessage(placeholders)); + if (Methods.isOnline(seller) && Methods.getPlayer(seller) != null) { + Player sell = Methods.getPlayer(seller); + sell.sendMessage(Messages.PLAYER_BOUGHT_ITEM.getMessage(placeholders)); + } + player.getInventory().addItem(i); + data.set("Items." + ID, null); + Files.DATA.saveFile(); + playClick(player); + openShop(player, shopType.get(player), shopCategory.get(player), 1); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancel.Name")))) { + openShop(player, shopType.get(player), shopCategory.get(player), 1); + playClick(player); + return; + } + } + } + } + } + } + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Players-Current-Items")))) { + e.setCancelled(true); + int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { + if (e.getCurrentItem() != null) { + ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { + if (item.getItemMeta().hasDisplayName()) { + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { + openShop(player, shopType.get(player), shopCategory.get(player), 1); + playClick(player); + return; + } + } + if (List.containsKey(player)) { + if (List.get(player).size() >= slot) { + int id = List.get(player).get(slot); + boolean T = false; + if (data.contains("Items")) { + for (String i : data.getConfigurationSection("Items").getKeys(false)) { + int ID = data.getInt("Items." + i + ".StoreID"); + if (id == ID) { + player.sendMessage(Messages.CANCELLED_ITEM.getMessage()); + AuctionCancelledEvent event = new AuctionCancelledEvent(player, data.getItemStack("Items." + i + ".Item"), CancelledReason.PLAYER_FORCE_CANCEL); + Bukkit.getPluginManager().callEvent(event); + int num = 1; + for (; data.contains("OutOfTime/Cancelled." + num); num++) ; + data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); + data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time")); + data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); + data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item")); + data.set("Items." + i, null); + Files.DATA.saveFile(); + playClick(player); + openPlayersCurrentList(player, 1); + return; + } + } + } + if (!T) { + playClick(player); + openShop(player, shopType.get(player), shopCategory.get(player), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); + return; + } + } + } + } + } + } + } + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Cancelled/Expired-Items")))) { + e.setCancelled(true); + final int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { + if (e.getCurrentItem() != null) { + final ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { + if (item.getItemMeta().hasDisplayName()) { + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { + Methods.updateAuction(); + playClick(player); + openShop(player, shopType.get(player), shopCategory.get(player), 1); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) { + Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + if (page == 1) page++; + playClick(player); + openPlayersExpiredList(player, (page - 1)); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Return.Name")))) { + Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + if (data.contains("OutOfTime/Cancelled")) { + for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { + if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getName())) { + if (Methods.isInvFull(player)) { + player.sendMessage(Messages.INVENTORY_FULL.getMessage()); + break; + } else { + player.getInventory().addItem(data.getItemStack("OutOfTime/Cancelled." + i + ".Item")); + data.set("OutOfTime/Cancelled." + i, null); + } + } + } + } + player.sendMessage(Messages.GOT_ITEM_BACK.getMessage()); + Files.DATA.saveFile(); + playClick(player); + openPlayersExpiredList(player, page); + return; + } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) { + Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + playClick(player); + openPlayersExpiredList(player, (page + 1)); + return; + } + } + if (List.containsKey(player)) { + if (List.get(player).size() >= slot) { + int id = List.get(player).get(slot); + boolean T = false; + if (data.contains("OutOfTime/Cancelled")) { + for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { + int ID = data.getInt("OutOfTime/Cancelled." + i + ".StoreID"); + if (id == ID) { + if (!Methods.isInvFull(player)) { + player.sendMessage(Messages.GOT_ITEM_BACK.getMessage()); + ItemStack IT = data.getItemStack("OutOfTime/Cancelled." + i + ".Item"); + player.getInventory().addItem(IT); + data.set("OutOfTime/Cancelled." + i, null); + Files.DATA.saveFile(); + playClick(player); + openPlayersExpiredList(player, 1); + } else { + player.sendMessage(Messages.INVENTORY_FULL.getMessage()); + } + return; + } + } + } + if (!T) { + playClick(player); + openShop(player, shopType.get(player), shopCategory.get(player), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); + } + } + } + } + } + } + } + } + } + +} diff --git a/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java b/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java new file mode 100644 index 0000000..1347974 --- /dev/null +++ b/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java @@ -0,0 +1,119 @@ +package com.badbones69.crazyauctions.currency; + +import com.badbones69.crazyauctions.api.FileManager.Files; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +public enum CurrencyManager { // Currency Manager + + VAULT("Vault", "Money"); + + private final String pluginName; + private final String name; + + /** + * @param pluginname + * name of the Plugin. + * @param name + * name of the Currency. + */ + private CurrencyManager(String pluginname, String name) { + this.pluginName = pluginname; + this.name = name; + } + + /** + * @param name + * name of the Type you want. + * @return Returns the Currency as a Enum. + */ + public static CurrencyManager getFromName(String name) { + for (CurrencyManager type : CurrencyManager.values()) { + if (type.getPluginName().equalsIgnoreCase(name)) { + return type; + } + } + return null; + } + + /** + * + * @param player + * Player you want the currency from. + * @return Returns the amount they have of the currency + */ + public static Long getMoney(Player player) { + return Vault.getMoney(player); + } + + /** + * + * @param player + * Player you want the currency from. + * @param amount + * The amount you want to take. + */ + public static void removeMoney(Player player, Long amount) { + Vault.removeMoney(player, amount); + } + + /** + * + * @param player + * Player you want the currency from. + * @param amount + * The amount you want to take. + */ + public static void removeMoney(OfflinePlayer player, Long amount) { + Vault.removeMoney(player, amount); + } + + /** + * + * @param player + * Player you want the currency from. + * @param amount + * The amount you want to add. + */ + public static void addMoney(Player player, Long amount) { + Vault.addMoney(player, amount); + } + + /** + * + * @param player + * Player you want the currency from. + * @param amount + * The amount you want to add. + */ + public static void addMoney(OfflinePlayer player, Long amount) { + Vault.addMoney(player, amount); + } + + /** + * @return Returns the Currency name as a string. + */ + public String getName() { + return name; + } + + /** + * @return Returns the Currency name as a string. + */ + public String getPluginName() { + return pluginName; + } + + /** + * + * @return Returns true if the server has the plugin. + */ + public Boolean hasPlugin() { + if (Bukkit.getServer().getPluginManager().getPlugin(pluginName) != null) { + return Files.CONFIG.getFile().getBoolean("Settings.Currencies." + pluginName + ".Enabled"); + } + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/currency/Vault.java b/src/main/java/com/badbones69/crazyauctions/currency/Vault.java new file mode 100644 index 0000000..4444942 --- /dev/null +++ b/src/main/java/com/badbones69/crazyauctions/currency/Vault.java @@ -0,0 +1,57 @@ +package com.badbones69.crazyauctions.currency; + +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.economy.EconomyResponse; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; + +public class Vault { + + public static Economy econ = null; + public static EconomyResponse r; + + public static boolean hasVault() { + return Bukkit.getServer().getPluginManager().getPlugin("Vault") != null; + } + + public static boolean setupEconomy() { + if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) { + return false; + } + RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); + if (rsp == null) { + return false; + } + econ = rsp.getProvider(); + return econ != null; + } + + public static Long getMoney(Player player) { + if (player != null) { + try { + return (long) econ.getBalance(player); + } catch (NullPointerException ignore) { + } + } + return 0L; + } + + public static void removeMoney(Player player, Long amount) { + econ.withdrawPlayer(player, amount); + } + + public static void removeMoney(OfflinePlayer player, Long amount) { + econ.withdrawPlayer(player, amount); + } + + public static void addMoney(Player player, Long amount) { + econ.depositPlayer(player, amount); + } + + public static void addMoney(OfflinePlayer player, Long amount) { + econ.depositPlayer(player, amount); + } + +} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/utils/ItemBuilder.java b/src/main/java/com/badbones69/crazyauctions/utils/ItemBuilder.java deleted file mode 100644 index 8b2a8fc..0000000 --- a/src/main/java/com/badbones69/crazyauctions/utils/ItemBuilder.java +++ /dev/null @@ -1,1261 +0,0 @@ -package com.badbones69.crazyauctions.utils; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.Methods; -import de.tr7zw.changeme.nbtapi.NBTItem; -import org.bukkit.Color; -import org.bukkit.DyeColor; -import org.bukkit.Material; -import org.bukkit.block.Banner; -import org.bukkit.block.banner.Pattern; -import org.bukkit.block.banner.PatternType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.*; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -public class ItemBuilder { - - private NBTItem nbtItem; - - // Item Data - private Material material; - private int damage; - private String itemName; - private final List itemLore; - private int itemAmount; - - // Player - private String player; - - // Skulls - private boolean isHash; - private boolean isURL; - private boolean isHead; - - // Enchantments/Flags - private boolean unbreakable; - private boolean hideItemFlags; - private boolean glowing; - - // Entities - private final boolean isMobEgg; - private EntityType entityType; - - // Potions - private PotionType potionType; - private Color potionColor; - private boolean isPotion; - - // Armor - private Color armorColor; - private boolean isLeatherArmor; - - // Enchantments - private HashMap enchantments; - - // Shields - private boolean isShield; - - // Banners - private boolean isBanner; - private List patterns; - - // Placeholders - private HashMap namePlaceholders; - private HashMap lorePlaceholders; - - // Misc - private ItemStack referenceItem; - private List itemFlags; - - // Custom Data - private int customModelData; - private boolean useCustomModelData; - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - private final Methods methods = plugin.getStarter().getMethods(); - - private final SkullCreator skullCreator = plugin.getStarter().getSkullCreator(); - - /** - * Create a blank item builder. - */ - public ItemBuilder() { - this.nbtItem = null; - this.material = Material.STONE; - this.damage = 0; - this.itemName = ""; - this.itemLore = new ArrayList<>(); - this.itemAmount = 1; - this.player = ""; - - this.isHash = false; - this.isURL = false; - this.isHead = false; - - this.unbreakable = false; - this.hideItemFlags = false; - this.glowing = false; - - this.isMobEgg = false; - this.entityType = EntityType.BAT; - - this.potionType = null; - this.potionColor = null; - this.isPotion = false; - - this.armorColor = null; - this.isLeatherArmor = false; - - this.enchantments = new HashMap<>(); - - this.isShield = false; - - this.isBanner = false; - this.patterns = new ArrayList<>(); - - this.namePlaceholders = new HashMap<>(); - this.lorePlaceholders = new HashMap<>(); - - this.itemFlags = new ArrayList<>(); - } - - /** - * Deduplicate an item builder. - * - * @param itemBuilder The item builder to deduplicate. - */ - public ItemBuilder(ItemBuilder itemBuilder) { - this.nbtItem = itemBuilder.nbtItem; - this.material = itemBuilder.material; - this.damage = itemBuilder.damage; - this.itemName = itemBuilder.itemName; - this.itemLore = new ArrayList<>(itemBuilder.itemLore); - this.itemAmount = itemBuilder.itemAmount; - this.player = itemBuilder.player; - - this.referenceItem = itemBuilder.referenceItem; - this.customModelData = itemBuilder.customModelData; - this.useCustomModelData = itemBuilder.useCustomModelData; - - this.enchantments = new HashMap<>(itemBuilder.enchantments); - - this.isHash = itemBuilder.isHash; - this.isURL = itemBuilder.isURL; - this.isHead = itemBuilder.isHead; - - this.unbreakable = itemBuilder.unbreakable; - this.hideItemFlags = itemBuilder.hideItemFlags; - this.glowing = itemBuilder.glowing; - - this.isMobEgg = itemBuilder.isMobEgg; - this.entityType = itemBuilder.entityType; - - this.potionType = itemBuilder.potionType; - this.potionColor = itemBuilder.potionColor; - this.isPotion = itemBuilder.isPotion; - - this.armorColor = itemBuilder.armorColor; - this.isLeatherArmor = itemBuilder.isLeatherArmor; - - this.isShield = itemBuilder.isShield; - - this.isBanner = itemBuilder.isBanner; - this.patterns = new ArrayList<>(itemBuilder.patterns); - - this.namePlaceholders = new HashMap<>(itemBuilder.namePlaceholders); - this.lorePlaceholders = new HashMap<>(itemBuilder.lorePlaceholders); - this.itemFlags = new ArrayList<>(itemBuilder.itemFlags); - } - - /** - * Gets the nbt item. - */ - public NBTItem getNBTItem() { - nbtItem = new NBTItem(build()); - return nbtItem; - } - - /** - * Gets the material. - */ - public Material getMaterial() { - return material; - } - - /** - * Checks if the item is a banner. - */ - public boolean isBanner() { - return isBanner; - } - - /** - * Checks if an item is a shield. - */ - public boolean isShield() { - return isShield; - } - - /** - * Checks if the item is a spawn mob egg. - */ - public boolean isMobEgg() { - return isMobEgg; - } - - /** - * Returns the player name. - */ - public String getPlayerName() { - return player; - } - - /** - * Get the entity type of the spawn mob egg. - */ - public EntityType getEntityType() { - return entityType; - } - - /** - * Get the name of the item. - */ - public String getName() { - return itemName; - } - - /** - * Get the lore on the item. - */ - public List getLore() { - return itemLore; - } - - /** - * Returns the enchantments on the Item. - */ - public HashMap getEnchantments() { - return enchantments; - } - - /** - * Return a list of Item Flags. - */ - public List getItemFlags() { - return itemFlags; - } - - /** - * Checks if flags are hidden. - */ - public boolean isItemFlagsHidden() { - return hideItemFlags; - } - - /** - * Check if item is Leather Armor - */ - public boolean isLeatherArmor() { - return isLeatherArmor; - } - - /** - * Checks if item is glowing. - */ - public boolean isGlowing() { - return glowing; - } - - /** - * Checks if the item is unbreakable. - */ - public boolean isUnbreakable() { - return unbreakable; - } - - /** - * Returns the amount of the item stack. - */ - public Integer getAmount() { - return itemAmount; - } - - /** - * Get the patterns on the banners. - */ - public List getPatterns() { - return patterns; - } - - /** - * 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 = itemName; - - for (String placeholder : namePlaceholders.keySet()) { - newName = newName.replace(placeholder, namePlaceholders.get(placeholder)).replace(placeholder.toLowerCase(), namePlaceholders.get(placeholder)); - } - - return newName; - } - - /** - * 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() { - - if (nbtItem != null) referenceItem = nbtItem.getItem(); - - ItemStack item = referenceItem != null ? referenceItem : new ItemStack(material); - - if (item.getType() != Material.AIR) { - if (isHead) { // Has to go 1st due to it removing all data when finished. - if (isHash) { // Sauce: https://github.com/deanveloper/SkullCreator - if (isURL) { - skullCreator.itemWithUrl(item, player); - } else { - skullCreator.itemWithBase64(item, player); - } - } - } - - item.setAmount(itemAmount); - ItemMeta itemMeta = item.getItemMeta(); - assert itemMeta != null; - itemMeta.setDisplayName(getUpdatedName()); - itemMeta.setLore(getUpdatedLore()); - - if (itemMeta instanceof org.bukkit.inventory.meta.Damageable) ((org.bukkit.inventory.meta.Damageable) itemMeta).setDamage(damage); - - if (isPotion && (potionType != null || potionColor != null)) { - PotionMeta potionMeta = (PotionMeta) itemMeta; - - if (potionType != null) potionMeta.setBasePotionData(new PotionData(potionType)); - - if (potionColor != null) potionMeta.setColor(potionColor); - } - - if (material == Material.TIPPED_ARROW && potionType != null) { - PotionMeta potionMeta = (PotionMeta) itemMeta; - potionMeta.setBasePotionData(new PotionData(potionType)); - } - - if (isLeatherArmor && armorColor != null) { - LeatherArmorMeta leatherMeta = (LeatherArmorMeta) itemMeta; - leatherMeta.setColor(armorColor); - } - - if (isBanner && !patterns.isEmpty()) { - BannerMeta bannerMeta = (BannerMeta) itemMeta; - bannerMeta.setPatterns(patterns); - } - - if (isShield && !patterns.isEmpty()) { - BlockStateMeta shieldMeta = (BlockStateMeta) itemMeta; - Banner banner = (Banner) shieldMeta.getBlockState(); - banner.setPatterns(patterns); - banner.update(); - shieldMeta.setBlockState(banner); - } - - if (useCustomModelData) itemMeta.setCustomModelData(customModelData); - - itemFlags.forEach(itemMeta :: addItemFlags); - item.setItemMeta(itemMeta); - hideItemFlags(item); - item.addUnsafeEnchantments(enchantments); - addGlow(item); - NBTItem nbt = new NBTItem(item); - - if (isHead && !isHash) nbt.setString("SkullOwner", player); - - if (isMobEgg) { - if (entityType != null) nbt.addCompound("EntityTag").setString("id", "minecraft:" + entityType.name()); - } - - return nbt.getItem(); - } else { - return item; - } - } - - /* - Class based extensions. - */ - - /** - * Set the type of item the builder is set to. - * - * @param material The material you wish to set. - * @return The ItemBuilder with updated info. - */ - public ItemBuilder setMaterial(Material material) { - this.material = material; - this.isHead = material == Material.PLAYER_HEAD; - return this; - } - - /** - * Set the type of item and its metadata in the builder. - * - * @param material The string must be in this form: %Material% or %Material%:%MetaData% - * @return The ItemBuilder with updated info. - */ - public ItemBuilder setMaterial(String material) { - String metaData; - - if (material.contains(":")) { // Sets the durability or another value option. - String[] b = material.split(":"); - material = b[0]; - metaData = b[1]; - - if (metaData.contains("#")) { // :# - String modelData = metaData.split("#")[1]; - - if (isInt(modelData)) { // Value is a number. - this.useCustomModelData = true; - this.customModelData = Integer.parseInt(modelData); - } - } - - metaData = metaData.replace("#" + customModelData, ""); - - if (isInt(metaData)) { // Value is durability. - this.damage = Integer.parseInt(metaData); - } else { // Value is something else. - this.potionType = getPotionType(PotionEffectType.getByName(metaData)); - this.potionColor = getColor(metaData); - this.armorColor = getColor(metaData); - } - - } else if (material.contains("#")) { - String[] b = material.split("#"); - material = b[0]; - - if (isInt(b[1])) { // Value is a number. - this.useCustomModelData = true; - this.customModelData = Integer.parseInt(b[1]); - } - } - - Material matchedMaterial = Material.matchMaterial(material); - - if (matchedMaterial != null) this.material = matchedMaterial; - - switch (this.material.name()) { - case "PLAYER_HEAD": - case "SKULL_ITEM": - this.isHead = true; - break; - case "POTION": - case "SPLASH_POTION": - this.isPotion = true; - break; - case "LEATHER_HELMET": - case "LEATHER_CHESTPLATE": - case "LEATHER_LEGGINGS": - case "LEATHER_BOOTS": - case "LEATHER_HORSE_ARMOR": - this.isLeatherArmor = true; - break; - case "BANNER": - this.isBanner = true; - break; - case "SHIELD": - this.isShield = true; - break; - } - - if (this.material.name().contains("BANNER")) this.isBanner = true; - - return this; - } - - /** - * @param damage The damage value of the item. - * @return The ItemBuilder with an updated damage value. - */ - public ItemBuilder setDamage(int damage) { - this.damage = damage; - return this; - } - - /** - * @param itemName The name of the item. - * @return The ItemBuilder with an updated name. - */ - public ItemBuilder setName(String itemName) { - if (itemName != null) this.itemName = methods.color(itemName); - - return this; - } - - /** - * @param placeholders The placeholders that will be used. - * @return The ItemBuilder with updated placeholders. - */ - public ItemBuilder setNamePlaceholders(HashMap 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.itemLore.clear(); - - for (String line : lore) { - this.itemLore.add(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.itemLore.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(HashMap 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 : itemLore) { - for (String placeholder : lorePlaceholders.keySet()) { - item = item.replace(placeholder, lorePlaceholders.get(placeholder)).replace(placeholder.toLowerCase(), lorePlaceholders.get(placeholder)); - } - - newLore.add(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; - } - - /** - * 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 = getDyeColor(split[1]); - - if (color != null) addPattern(new Pattern(color, pattern)); - - break; - } - } - } catch (Exception ignored) {} - } - - /** - * @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) { - 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 (player != null && player.length() > 16) { - this.isHash = true; - this.isURL = player.startsWith("http"); - } - - return this; - } - - /** - * It will override any enchantments used in ItemBuilder.addEnchantment() below. - * - * @param enchantment A list of enchantments to add to the item. - * @return The ItemBuilder with a list of updated enchantments. - */ - public ItemBuilder setEnchantments(HashMap enchantment) { - if (enchantment != null) this.enchantments = enchantment; - - 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) { - this.enchantments.put(enchantment, level); - 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) { - this.enchantments.remove(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) { - itemFlags.clear(); - - for (String flagString : flagStrings) { - ItemFlag flag = getFlag(flagString); - - if (flag != null) itemFlags.add(flag); - } - - return this; - } - - // Used for multiple Item Flags - public ItemBuilder addItemFlags(List flagStrings) { - for (String flagString : flagStrings) { - try { - ItemFlag itemFlag = ItemFlag.valueOf(flagString.toUpperCase()); - - if (itemFlag != null) 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) 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) 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 item The item to hide flags on. - * @return The ItemBuilder with an updated Item. - */ - public ItemStack hideItemFlags(ItemStack item) { - if (hideItemFlags) { - if (item != null && item.hasItemMeta() && item.getItemMeta() != null) { - ItemMeta itemMeta = item.getItemMeta(); - itemMeta.addItemFlags(ItemFlag.values()); - item.setItemMeta(itemMeta); - return item; - } - } - - return item; - } - - /** - * Sets the converted item as a reference to try and save NBT tags and stuff. - * - * @param referenceItem The item that is being referenced. - * @return The ItemBuilder with updated info. - */ - private ItemBuilder setReferenceItem(ItemStack referenceItem) { - this.referenceItem = referenceItem; - return this; - } - - /** - * @param unbreakable Sets the item to be unbreakable. - * @return The ItemBuilder with an updated Boolean. - */ - public ItemBuilder setUnbreakable(boolean unbreakable) { - this.unbreakable = 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.glowing = glow; - return this; - } - - /** - * The text that will be displayed on the item. - * - * @param texture The skull texture. - * @param profileUUID The uuid of the profile. - * @return The ItemBuilder. - */ - public ItemBuilder texture(String texture, UUID profileUUID) { - return this; - } - - /** - * @param texture The skull texture. - * @return The ItemBuilder. - */ - public ItemBuilder texture(String texture) { - return this; - } - - /** - * @param texture The owner of the skull. - * @return The ItemBuilder. - */ - public ItemBuilder owner(String texture) { - return this; - } - - // Other misc shit - - /** - * 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) { - ItemBuilder itemBuilder = new ItemBuilder().setReferenceItem(item).setAmount(item.getAmount()).setMaterial(item.getType()).setEnchantments(new HashMap<>(item.getEnchantments())); - - if (item.hasItemMeta() && item.getItemMeta() != null) { - ItemMeta itemMeta = item.getItemMeta(); - itemBuilder.setName(itemMeta.getDisplayName()).setLore(itemMeta.getLore()); - NBTItem nbt = new NBTItem(item); - - if (nbt.hasKey("Unbreakable")) itemBuilder.setUnbreakable(nbt.getBoolean("Unbreakable")); - - if (itemMeta instanceof org.bukkit.inventory.meta.Damageable) itemBuilder.setDamage(((org.bukkit.inventory.meta.Damageable) itemMeta).getDamage()); - } - - return itemBuilder; - } - - /** - * 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); - break; - case "name": - itemBuilder.setName(value); - break; - case "amount": - try { - itemBuilder.setAmount(Integer.parseInt(value)); - } catch (NumberFormatException e) { - itemBuilder.setAmount(1); - } - break; - case "lore": - itemBuilder.setLore(Arrays.asList(value.split(","))); - break; - case "player": - itemBuilder.setPlayerName(value); - break; - case "unbreakable-item": - if (value.isEmpty() || value.equalsIgnoreCase("true")) itemBuilder.setUnbreakable(true); - break; - default: - Enchantment enchantment = getEnchantment(option); - - if (enchantment != null && enchantment.getName() != 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 = getDyeColor(value); - if (color != null) itemBuilder.addPattern(new Pattern(color, pattern)); - break; - } - } - } catch (Exception ignored) {} - break; - } - } - } catch (Exception e) { - itemBuilder.setMaterial(Material.RED_TERRACOTTA).setName("&c&lERROR").setLore(Arrays.asList("&cThere is an error", "&cFor : &c" + (placeHolder != null ? placeHolder : ""))); - e.printStackTrace(); - } - - 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()); - } - - /** - * Add glow to an item. - * - * @param item The item to add glow to. - */ - private void addGlow(ItemStack item) { - if (glowing) { - try { - if (item != null && item.getItemMeta() != null) { - if (item.hasItemMeta()) { - if (item.getItemMeta().hasEnchants()) return; - } - - item.addUnsafeEnchantment(Enchantment.LUCK, 1); - ItemMeta meta = item.getItemMeta(); - meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - item.setItemMeta(meta); - } - } catch (NoClassDefFoundError ignored) {} - } - } - - /** - * 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 Color from a string. - * - * @param color The string of the color. - * @return The color from the string. - */ - private static Color getColor(String color) { - if (color != null) { - switch (color.toUpperCase()) { - case "AQUA": - return Color.AQUA; - case "BLACK": - return Color.BLACK; - case "BLUE": - return Color.BLUE; - case "FUCHSIA": - return Color.FUCHSIA; - case "GRAY": - return Color.GRAY; - case "GREEN": - return Color.GREEN; - case "LIME": - return Color.LIME; - case "MAROON": - return Color.MAROON; - case "NAVY": - return Color.NAVY; - case "OLIVE": - return Color.OLIVE; - case "ORANGE": - return Color.ORANGE; - case "PURPLE": - return Color.PURPLE; - case "RED": - return Color.RED; - case "SILVER": - return Color.SILVER; - case "TEAL": - return Color.TEAL; - case "WHITE": - return Color.WHITE; - case "YELLOW": - return Color.YELLOW; - } - - try { - String[] rgb = color.split(","); - return Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2])); - } catch (Exception ignore) {} - } - - return null; - } - - /** - * Get the dye color from a string. - * - * @param color The string of the color. - * @return The dye color from the string. - */ - public static DyeColor getDyeColor(String color) { - if (color != null) { - try { - return DyeColor.valueOf(color.toUpperCase()); - } catch (Exception e) { - try { - String[] rgb = color.split(","); - return DyeColor.getByColor(Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]))); - } catch (Exception ignore) {} - } - } - - 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; - - HashMap 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 list of enchantments and their in-Game names. - */ - private static HashMap getEnchantmentList() { - HashMap 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; - } - - private boolean isInt(String s) { - try { - Integer.parseInt(s); - } catch (NumberFormatException nfe) { - return false; - } - - return true; - } - - private ItemFlag getFlag(String flagString) { - for (ItemFlag flag : ItemFlag.values()) { - if (flag.name().equalsIgnoreCase(flagString)) return flag; - } - - return null; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/utils/SkullCreator.java b/src/main/java/com/badbones69/crazyauctions/utils/SkullCreator.java deleted file mode 100644 index 736e772..0000000 --- a/src/main/java/com/badbones69/crazyauctions/utils/SkullCreator.java +++ /dev/null @@ -1,275 +0,0 @@ -package com.badbones69.crazyauctions.utils; - -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 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 final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - /** - * Creates a player skull based on a player's name. - * - * @param name The Player's name - * @return The head of the Player - * - * @deprecated names don't make for good identifiers - */ - @Deprecated - public ItemStack itemFromName(String name) { - ItemStack item = getPlayerSkullItem(); - - return itemWithName(item, name); - } - - /** - * Creates a player skull based on a player's name. - * - * @param item The item to apply the name to - * @param name The Player's name - * @return The head of the Player - * - * @deprecated names don't make for good identifiers - */ - @Deprecated - public ItemStack itemWithName(ItemStack item, String name) { - notNull(item, "item"); - notNull(name, "name"); - - return plugin.getServer().getUnsafe().modifyItemStack(item, "{SkullOwner:\"" + name + "\"}"); - } - - /** - * Creates a player skull with a UUID. 1.13 only. - * - * @param id The Player's UUID - * @return The head of the Player - */ - public 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 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 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 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 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 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 name. - * - * @param block The block to set - * @param name The player to set it to - * - * @deprecated names don't make for good identifiers - */ - @Deprecated - public void blockWithName(Block block, String name) { - notNull(block, "block"); - notNull(name, "name"); - - setBlockType(block); - ((Skull) block.getState()).setOwningPlayer(Bukkit.getOfflinePlayer(name)); - } - - /** - * 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 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 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 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 + "\"}]}}}" - ); - - if (newerApi()) { - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "data merge block " + args); - } else { - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "blockdata " + args); - } - } - - private boolean newerApi() { - try { - Material.valueOf("PLAYER_HEAD"); - return true; - } catch (IllegalArgumentException e) { - return false; - } - } - - private ItemStack getPlayerSkullItem() { - if (newerApi()) { - return new ItemStack(Material.valueOf("PLAYER_HEAD")); - } else { - return new ItemStack(Material.valueOf("SKULL_ITEM"), 1, (byte) 3); - } - } - - private void setBlockType(Block block) { - try { - block.setType(Material.valueOf("PLAYER_HEAD"), false); - } catch (IllegalArgumentException e) { - block.setType(Material.valueOf("SKULL"), false); - } - } - - private void notNull(Object o, String name) { - if (o == null) { - throw new NullPointerException(name + " should not be null!"); - } - } - - private 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()); - } -} - -/* Format for skull -{ - display:{ - Name:"Cheese" - }, - SkullOwner:{ - Id:"9c919b83-f3fe-456f-a824-7d1d08cc8bd2", - Properties:{ - textures:[ - { - Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTU1ZDYxMWE4NzhlODIxMjMxNzQ5YjI5NjU3MDhjYWQ5NDI2NTA2NzJkYjA5ZTI2ODQ3YTg4ZTJmYWMyOTQ2In19fQ==" - } - ] - } - } -}*/ \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/utils/func/PluginSupport.java b/src/main/java/com/badbones69/crazyauctions/utils/func/PluginSupport.java deleted file mode 100644 index ad345dd..0000000 --- a/src/main/java/com/badbones69/crazyauctions/utils/func/PluginSupport.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.badbones69.crazyauctions.utils.func; - -import com.badbones69.crazyauctions.CrazyAuctions; - -public enum PluginSupport { - - PLACEHOLDERAPI("PlaceholderAPI"), - HOLOGRAPHIC_DISPLAYS("HolographicDisplays"), - DECENT_HOLOGRAMS("DecentHolograms"), - VAULT("Vault"); - - private final String name; - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - PluginSupport(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public boolean isPluginLoaded() { - return plugin.getServer().getPluginManager().getPlugin(name) != null; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/utils/func/ServerProtocol.java b/src/main/java/com/badbones69/crazyauctions/utils/func/ServerProtocol.java deleted file mode 100644 index c0277a0..0000000 --- a/src/main/java/com/badbones69/crazyauctions/utils/func/ServerProtocol.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.badbones69.crazyauctions.utils.func; - -import com.badbones69.crazyauctions.CrazyAuctions; - -/** - * @author Badbones69 - */ -public enum ServerProtocol { - - TOO_OLD(-1), - v1_7_R1(171), v1_7_R2(172), v1_7_R3(173), v1_7_R4(174), - v1_8_R1(181), v1_8_R2(182), v1_8_R3(183), - v1_9_R1(191), v1_9_R2(192), - v1_10_R1(1101), - v1_11_R1(1111), - v1_12_R1(1121), - v1_13_R2(1132), - v1_14_R1(1141), - v1_15_R1(1151), - v1_16_R1(1161), v1_16_R2(1162), v1_16_R3(1163), - v1_17_R1(1171), - v1_18_R1(1181), - v1_18_R2(1182), - v1_19(1191), - TOO_NEW(-2); - - private static ServerProtocol currentProtocol; - private static ServerProtocol latest; - - private final int versionProtocol; - - private static final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - ServerProtocol(int versionProtocol) { - this.versionProtocol = versionProtocol; - } - - public static ServerProtocol getCurrentProtocol() { - - String serVer = plugin.getServer().getClass().getPackage().getName(); - - int serProt = Integer.parseInt( - serVer.substring( - serVer.lastIndexOf('.') + 1 - ).replace("_", "").replace("R", "").replace("v", "") - ); - - for (ServerProtocol protocol : values()) { - if (protocol.versionProtocol == serProt) { - currentProtocol = protocol; - break; - } - } - - if (currentProtocol == null) currentProtocol = ServerProtocol.TOO_NEW; - - return currentProtocol; - } - - public static boolean isLegacy() { - return isOlder(ServerProtocol.v1_18_R1); - } - - public static ServerProtocol getLatestProtocol() { - - if (latest != null) return latest; - - ServerProtocol old = ServerProtocol.TOO_OLD; - - for (ServerProtocol protocol : values()) { - if (protocol.compare(old) == 1) { - old = protocol; - } - } - - return old; - } - - public static boolean isAtLeast(ServerProtocol protocol) { - if (currentProtocol == null) getCurrentProtocol(); - - int proto = currentProtocol.versionProtocol; - - return proto >= protocol.versionProtocol || proto == -2; - } - - public static boolean isNewer(ServerProtocol protocol) { - if (currentProtocol == null) getCurrentProtocol(); - - return currentProtocol.versionProtocol > protocol.versionProtocol || currentProtocol.versionProtocol == -2; - } - - public static boolean isSame(ServerProtocol protocol) { - if (currentProtocol == null) getCurrentProtocol(); - - return currentProtocol.versionProtocol == protocol.versionProtocol; - } - - public static boolean isOlder(ServerProtocol protocol) { - if (currentProtocol == null) getCurrentProtocol(); - - int proto = currentProtocol.versionProtocol; - - return proto < protocol.versionProtocol || proto == -1; - } - - public int compare(ServerProtocol protocol) { - int result = -1; - int current = versionProtocol; - int check = protocol.versionProtocol; - - if (current > check || check == -2) { - result = 1; - } else if (current == check) { - result = 0; - } - - return result; - } -} \ No newline at end of file diff --git a/src/main/resources/config1.12.2-Down.yml b/src/main/resources/config1.12.2-Down.yml new file mode 100644 index 0000000..c181ef7 --- /dev/null +++ b/src/main/resources/config1.12.2-Down.yml @@ -0,0 +1,306 @@ +Settings: + Prefix: '&7[&4Crazy &bAuctions&7]: ' #Prefix of when you get Crazy Auctions Messages. + GUIName: '&4Crazy &bAuctions&8' #Name of the Main GUI. + Players-Current-Items: '&8Your Current Listings' #The Name of the Player Current Items GUI. + Cancelled/Expired-Items: '&8Cancelled/Expired Listings' #Name of the Canceled/Expired GUI. + Buying-Item: '&8Purchase Item: Are You Sure?' #Name of the Buying GUI. + Bidding-On-Item: '&8You Are Bidding On This Item.' #Name of the Bidding GUI. + Categories: '&8Categories' #Name of the Category GUI. + Sell-Time: 2d #The time that each item will sell for. + Bid-Time: 2m 30s #Time for each item that is biddable. + Full-Expire-Time: 10d #The full time the item is in the crazy auctions. + Bid-Winner-Time: 20d #The time the winner of a bid has to claim their prize. + Minimum-Sell-Price: 10 #Minimum amount you can sell an item for. + Max-Beginning-Sell-Price: 1000000 #Max amount you can sell an item for. + Minimum-Bid-Price: 100 #Minimum starting bid. + Max-Beginning-Bid-Price: 1000000 #Maximum starting bid. + Allow-Damaged-Items: False #Allow items that have been damaged. + Category-Page-Opens-First: False #If set to true the categories' page will open when they do /CA. + Feature-Toggle: #Toggle if a feature is on or off. + Selling: true #Able to use the selling part of the auction house. + Bidding: true #Able to use the bidding part of the auction house. + Patches: + Macro-Dupe: true #Turn to false if you have an issue, but it should patch the bug. + Sounds: + Toggle: False #Disable the clicking sound. + Sound: 'CLICK' #Make sure if you use 1.8 or lower you use the 1.8 sound and 1.9 and up use 1.9 sounds. The default sound is 1.8. + #1.8 sounds are found here: http://badbones69.com/javadocs/1.8.8/org/bukkit/Sound.html + #1.9 sounds are found here: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html + GUISettings: #Settings for things in the gui. + SellingItemLore: #The lore on items that are being sold. + - '&7-------------------------' + - '&aClick here to purchase.' + - '' + - '&9Price: &e$%price%' + - '&9Seller: &e%seller%' + - '&7-------------------------' + CurrentLore: #Lore on items that are in your current items GUI. + - '&7-------------------------' + - '&aClick here to cancel.' + - '' + - '&9Price: &e$%price%' + - '&9Expire: &e%time%' + - '&7-------------------------' + Cancelled/ExpiredLore: #Lore on items that are in your canceled/expired GUI. + - '&7-------------------------' + - '&aClick here to return to you.' + - '' + - '&9Full Expire: &e%time%' + - '&7-------------------------' + Bidding: #Lore on Bidding Items. + - '&7-------------------------' + - '&aClick here to bid.' + - '' + - '&9Seller: &e%seller%' + - '&9Current Bid: &e$%topbid%' + - '&9Top Bidder: &e%topbidder%' + - '&9Time Left: &e%time%' + - '&7-------------------------' + Category-Settings: + Armor: + Item: '315' + Toggle: true + Slot: 11 + Name: '&6&lArmor' + Lore: + - '&7This category contains all' + - '&7armor that is currently being sold.' + Weapons: + Item: '283' + Toggle: true + Slot: 12 + Name: '&6&lWeapons' + Lore: + - '&7This category contains all' + - '&7weapons that are currently being sold.' + Tools: + Item: '285' + Toggle: true + Slot: 13 + Name: '&6&lTools' + Lore: + - '&7This category contains all' + - '&7tools that are currently being sold.' + Food: + Item: '322' + Toggle: true + Slot: 14 + Name: '&6&lFood' + Lore: + - '&7This category contains all' + - '&7food that is currently being sold.' + Potions: + Item: '373:8227' + Toggle: true + Slot: 15 + Name: '&6&lPotions' + Lore: + - '&7This category contains all' + - '&7potions that are currently being sold.' + Blocks: + Item: '2' + Toggle: true + Slot: 16 + Name: '&6&lBlocks' + Lore: + - '&7This category contains all' + - '&7blocks that are currently being sold.' + Other: + Item: '371' + Toggle: true + Slot: 17 + Name: '&6&lOthers' + Lore: + - '&7This category contains all the' + - '&7other items currently being sold.' + None: + Item: '166' + Toggle: true + Slot: 23 + Name: '&6&lNone' + Lore: + - '&7This category contains all' + - '&7items currently being sold.' + OtherSettings: #Other Settings for the GUIs. + SellingItems: #The button for your current items. + Item: '264' #The item that this button is. + Toggle: true #If the item is in the gui or not. + Slot: 46 #The slot it is in. I recommend not changing these. If you do make sure they are still in the bottom row. + Name: '&6Items You are Selling' #Name of the item. + Lore: #Lore of the item. + - '&aClick here to view all the items you' + - '&aare currently selling on the auction.' + Cancelled/ExpiredItems: #The button for Canceled/Expired Items. + Item: '394' + Toggle: true + Slot: 47 + Name: '&6Collect Expired / Canceled Items' + Lore: + - '&aClick here to view and collect all of the' + - '&aitems you have canceled or has expired.' + PreviousPage: #The button for Previous Page. + Item: '339' + Toggle: true + Slot: 49 + Name: '&6Previous Page' + Lore: { } + Refesh: #The button for Refresh Page. + Item: '175' + Toggle: true + Slot: 50 + Name: '&6Refresh Page' + Lore: { } + NextPage: #The button for Next Page. + Item: '339' + Toggle: true + Slot: 51 + Name: '&6Next Page' + Lore: { } + Category1: #The button for Next Page. + Item: '54' + Toggle: true + Slot: 52 + Name: '&6Categories' + Lore: + - '&bCurrent Category: &6%category%' + - '&aWant to see items in specific categories?' + - '&aClick here to see all categories of items.' + Category2: #The button for Next Page. + Item: '54' + Toggle: true + Slot: 48 + Name: '&6Categories' + Lore: + - '&bCurrent Category: &6%category%' + - '&aWant to see items in specific categories?' + - '&aClick here to see all categories of items.' + Bidding/Selling: #Switch between Bidding and Selling. + Selling: + Item: '341' + Toggle: true + Slot: 53 + Name: '&6Currently looking at items being sold.' + Lore: + - '&7&l(&6&l!&7&l) &7Click here to see items' + - '&7that you can bid on.' + Bidding: + Item: '378' + Toggle: true + Slot: 53 + Name: '&6Currently looking at items that can be bid on.' + Lore: + - '&7&l(&6&l!&7&l) &7Click here to see items' + - '&7that you can buy at a price.' + WhatIsThis: #The info on all the Books buttons. + SellingShop: #The Book in the main shop. + Item: '340' + Toggle: true + Slot: 54 + Name: '&6What Is This Page?' + Lore: + - '&aThis is the crazy auctions, here you can' + - '&aput items for sale, and buy items' + - '&athat others have put for sale.' + - '' + - '&aThe auction is also a great place to make' + - '&amoney by selling items that others' + - '&amay be interested in buying.' + BiddingShop: #The Book in the main shop. + Item: '340' + Toggle: true + Slot: 54 + Name: '&6What Is This Page?' + Lore: + - '&aThis is the crazy auctions, here you can' + - '&aput items for sale, and bid on items' + - '&athat others have put for sale.' + - '' + - '&aThe bidding auction is also a great place to' + - '&amake money by bidding off items that others' + - '&amay be interested in bidding on.' + CurrentItems: #The Book in the Current items GUI. + Item: '340' + Toggle: true + Slot: 54 + Name: '&6What Is This Page?' + Lore: + - '&aThese are your current listings, all of' + - '&athe items you currenty have listed on' + - '&acrazy auctions are displayed here.' + - '' + - '&aYou can cancel and view your listings' + - '&aexpire time here.' + Cancelled/ExpiredItems: #The Book in the Canceled/Expired Items GUI. + Item: '340' + Toggle: true + Slot: 54 + Name: '&6What Is This Page?' + Lore: + - '&aThis page houses all of your cancelled and' + - '&aexpired items, when a listings is cancelled' + - '&aor expires you will be able to return that' + - '&aitem back to you from this menu.' + - '' + - '&aJust click on the item and if you have enough' + - '&ainventory space you will receive that item.' + Viewing: #The Book in the Viewing Items GUI. + Item: '340' + Toggle: true + Slot: 50 + Name: '&6What Is This Page?' + Lore: + - '&aThis page shows all the items that' + - '&aa player has currently on the bidding' + - '&aand selling market. You can quickly see' + - '&awhat a specific player is selling.' + Categories: #The Book in the Viewing Items GUI. + Item: '340' + Toggle: true + Slot: 54 + Name: '&6What Is This Page?' + Lore: + - '&aThis page shows all the categories' + - '&athat you can choose from. When you click' + - '&aa category it will open the gui with only' + - '&aitems that belong to that category.' + Back: #The Back Buttons. + Item: '339' + Slot: 46 + Name: '&6Back' + Return: #The Return Buttons. + Item: '390' + Slot: 50 + Name: '&6Return All' + Lore: + - '&aClick here to return all cancelled' + - '&aand expired items to your inventory.' + Confirm: #The Confirm Buttons. + Item: '160:5' + Name: '&aConfirm' + Cancel: #The Cancel Buttons. + Item: '160:14' + Name: '&cCancel' + Your-Item: #The item that shows when you try to buy/bid on your item. + Item: '166' + Name: '&cYou Can''t Purchase Your Own Item.' + Cant-Afford: #The item that shows when you can't afford this item. + Item: '166' + Name: '&cYou Can''t Afford This Item.' + Top-Bidder: #The item for when a player is already the top bidder. + Item: '166' + Name: '&cYou are already the top bidder.' + Bidding: #The item in the middle when bidding on an item. + Item: '160:15' + Name: '&7Bidding' + Lore: + - '&7<--&aAdd &cRemove&7-->' + - '&9Your Current Bid: &e$%bid%' + - '&9Current Top Bid: &e$%topbid%' + Bid: #The button for when you want to confirm your bid. + Item: '160:3' + Name: '&bBid Now' + Lore: + - '&7Click here to Bid Now.' + BlackList: + - '7' + - '120' \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config1.13-Up.yml similarity index 99% rename from src/main/resources/config.yml rename to src/main/resources/config1.13-Up.yml index ebaf756..eb10ebd 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config1.13-Up.yml @@ -19,6 +19,8 @@ Settings: Feature-Toggle: #Toggle if a feature is on or off. Selling: true #Able to use the selling part of the auction house. Bidding: true #Able to use the bidding part of the auction house. + Patches: + Macro-Dupe: true #Turn to false if you have an issue, but it should patch the bug. Sounds: Toggle: false #Disable the clicking sound. Sound: 'CLICK' #Make sure if you use 1.8 or lower you use the 1.8 sound and 1.9 and up use 1.9 sounds. The default sound is 1.8. diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3150de6..5de4b8b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,16 +1,12 @@ -name: "CrazyAuctions" -main: "${group}.CrazyAuctions" - -authors: [BadBones69, RyderBelserion] - -version: ${version} -api-version: "1.13" -description: ${description} - -softdepend: [Vault] - -website: https://modrinth.com/plugin/crazyauctions - +name: CrazyAuctions +author: BadBones69 +main: com.badbones69.crazyauctions.Main +website: https://www.spigotmc.org/resources/authors/badbones69.9719/ +version: ${version}${build.number} +depend: [Vault] +api-version: 1.13 +description: A plugin to auction off items globally. commands: - crazyauctions: - description: Opens the main menu for CrazyAuctions. \ No newline at end of file + ca: + description: Opens the Crazy Auctions GUI. + aliases: [crazyauction, crazyauctions, ah, hdv] \ No newline at end of file From 172df2dfa37331c5b87acf91a29b669c58d3e75c Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Sat, 11 Nov 2023 12:53:47 -0500 Subject: [PATCH 3/7] update buildscript --- .gitignore | 26 +- CONTRIBUTING.md | 22 + LICENSE | 2 +- README.md | 121 +++- build.gradle.kts | 29 + buildSrc/build.gradle.kts | 11 + buildSrc/settings.gradle.kts | 14 + .../src/main/kotlin/paper-plugin.gradle.kts | 23 + .../src/main/kotlin/root-plugin.gradle.kts | 46 ++ common/build.gradle.kts | 14 + .../common/CrazyAuctionsPlugin.java | 81 +++ .../common/config/ConfigBuilder.java | 30 + .../common/config/types/Config.java | 43 ++ .../common/config/types/Messages.java | 47 ++ .../common/config/types/PluginConfig.java | 33 + .../crazyauctions/common/data/UserCache.java | 39 + gradle.properties | 15 + gradle/libs.versions.toml | 46 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 63721 bytes gradle/wrapper/gradle-wrapper.properties | 7 + gradlew | 249 +++++++ gradlew.bat | 92 +++ paper/build.gradle.kts | 125 ++++ .../com/badbones69/crazyauctions/Main.java | 0 .../com/badbones69/crazyauctions/Methods.java | 0 .../crazyauctions/api/Category.java | 0 .../crazyauctions/api/CrazyAuctions.java | 0 .../crazyauctions/api/FileManager.java | 0 .../crazyauctions/api/Messages.java | 0 .../crazyauctions/api/ShopType.java | 0 .../badbones69/crazyauctions/api/Version.java | 0 .../api/enums/CancelledReason.java | 0 .../api/events/AuctionBuyEvent.java | 0 .../api/events/AuctionCancelledEvent.java | 0 .../api/events/AuctionExpireEvent.java | 0 .../api/events/AuctionListEvent.java | 0 .../api/events/AuctionNewBidEvent.java | 0 .../api/events/AuctionWinBidEvent.java | 0 .../crazyauctions/controllers/DupePatch.java | 0 .../crazyauctions/controllers/GUI.java | 0 .../currency/CurrencyManager.java | 0 .../crazyauctions/currency/Vault.java | 0 .../crazyauctions/v2/CrazyAuctions.java | 55 ++ .../crazyauctions/v2/CrazyStarter.java | 30 + .../crazyauctions/v2/api/CrazyManager.java | 34 + .../v2/api/enums/Permissions.java | 38 + .../v2/api/enums/support/DataSupport.java | 19 + .../v2/api/events/AuctionAddEvent.java | 62 ++ .../v2/api/events/AuctionBidEvent.java | 65 ++ .../v2/api/events/AuctionBuyEvent.java | 65 ++ .../v2/api/events/AuctionCancelEvent.java | 82 +++ .../v2/api/events/AuctionExpireEvent.java | 55 ++ .../v2/api/events/AuctionListEvent.java | 65 ++ .../v2/api/events/AuctionWinEvent.java | 65 ++ .../crazyauctions/v2/api/frame/ItemUtils.java | 27 + .../crazyauctions/v2/api/frame/PaperCore.java | 140 ++++ .../v2/api/frame/PaperUtils.java | 25 + .../frame/adapters/LocationTypeAdapter.java | 52 ++ .../v2/api/frame/command/CommandContext.java | 268 +++++++ .../v2/api/frame/command/CommandEngine.java | 164 +++++ .../v2/api/frame/command/CommandFlow.java | 30 + .../v2/api/frame/command/CommandManager.java | 123 ++++ .../frame/command/builders/CommandActor.java | 48 ++ .../command/builders/CommandDataEntry.java | 14 + .../command/builders/CommandHelpEntry.java | 156 ++++ .../command/builders/annotations/Hidden.java | 7 + .../frame/command/builders/args/Argument.java | 3 + .../command/builders/args/ArgumentType.java | 9 + .../command/builders/args/CommandArgs.java | 22 + .../args/builder/BooleanArgument.java | 12 + .../builders/args/builder/DoubleArgument.java | 34 + .../builders/args/builder/FloatArgument.java | 34 + .../builders/args/builder/IntArgument.java | 28 + .../args/builder/custom/PlayerArgument.java | 15 + .../builders/other/ComponentBuilder.java | 94 +++ .../builders/reqs/CommandRequirements.java | 57 ++ .../reqs/CommandRequirementsBuilder.java | 33 + .../v2/api/frame/items/BaseItemBuilder.java | 673 ++++++++++++++++++ .../v2/api/frame/items/ItemBuilder.java | 23 + .../v2/api/frame/items/ItemNbt.java | 57 ++ .../v2/api/manager/enums/AuctionType.java | 28 + .../api/manager/interfaces/AuctionItem.java | 25 + .../api/manager/objects/AuctionButtons.java | 88 +++ .../api/manager/objects/AuctionCategory.java | 44 ++ .../v2/api/manager/objects/AuctionHouse.java | 91 +++ .../manager/objects/InventorySettings.java | 30 + .../objects/auctiontype/BiddingAuction.java | 74 ++ .../objects/auctiontype/SellingAuction.java | 54 ++ .../v2/commands/AuctionCommand.java | 21 + .../v2/commands/admin/CommandReload.java | 23 + .../inventories/AuctionInventory.java | 23 + .../inventories/AuctionInventoryClick.java | 35 + .../crazyauctions/v2/events/DataListener.java | 27 + .../v2/storage/interfaces/UserManager.java | 28 + .../v2/storage/objects/UserData.java | 24 + .../v2/storage/types/StorageManager.java | 17 + .../types/file/yaml/YamlUserManager.java | 110 +++ .../v2/support/PlaceholderSupport.java | 17 + .../v2/support/economy/Currency.java | 51 ++ .../v2/support/economy/CurrencyAPI.java | 131 ++++ .../support/economy/vault/VaultSupport.java | 26 + .../crazyauctions/v2/utils/ItemUtils.java | 10 + .../v2/utils/misc/ColorUtils.java | 15 + .../src}/main/resources/config1.12.2-Down.yml | 0 .../src}/main/resources/config1.13-Up.yml | 0 {src => paper/src}/main/resources/data.yml | 0 .../src}/main/resources/messages.yml | 0 {src => paper/src}/main/resources/plugin.yml | 0 .../src}/main/resources/test-file.yml | 0 pom.xml | 116 --- settings.gradle.kts | 17 + 111 files changed, 4871 insertions(+), 152 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 build.gradle.kts create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/settings.gradle.kts create mode 100644 buildSrc/src/main/kotlin/paper-plugin.gradle.kts create mode 100644 buildSrc/src/main/kotlin/root-plugin.gradle.kts create mode 100644 common/build.gradle.kts create mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/CrazyAuctionsPlugin.java create mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/config/ConfigBuilder.java create mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/config/types/Config.java create mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/config/types/Messages.java create mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/config/types/PluginConfig.java create mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/data/UserCache.java create mode 100644 gradle.properties create mode 100644 gradle/libs.versions.toml create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 paper/build.gradle.kts rename {src => paper/src}/main/java/com/badbones69/crazyauctions/Main.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/Methods.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/Category.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/FileManager.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/Messages.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/ShopType.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/Version.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/controllers/GUI.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java (100%) rename {src => paper/src}/main/java/com/badbones69/crazyauctions/currency/Vault.java (100%) create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyAuctions.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyStarter.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/CrazyManager.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/Permissions.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/support/DataSupport.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionAddEvent.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBidEvent.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBuyEvent.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionCancelEvent.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionExpireEvent.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionListEvent.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionWinEvent.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/ItemUtils.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperCore.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperUtils.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/adapters/LocationTypeAdapter.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandContext.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandEngine.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandFlow.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandManager.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandActor.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandDataEntry.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandHelpEntry.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/annotations/Hidden.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/Argument.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/ArgumentType.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/CommandArgs.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/BooleanArgument.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/DoubleArgument.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/FloatArgument.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/IntArgument.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/custom/PlayerArgument.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/other/ComponentBuilder.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirements.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirementsBuilder.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/BaseItemBuilder.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemBuilder.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemNbt.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/enums/AuctionType.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/interfaces/AuctionItem.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionButtons.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionCategory.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionHouse.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/InventorySettings.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/BiddingAuction.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/SellingAuction.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/commands/AuctionCommand.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/commands/admin/CommandReload.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventory.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventoryClick.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/events/DataListener.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/storage/interfaces/UserManager.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/storage/objects/UserData.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/StorageManager.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/file/yaml/YamlUserManager.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/support/PlaceholderSupport.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/Currency.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/CurrencyAPI.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/vault/VaultSupport.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/utils/ItemUtils.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/utils/misc/ColorUtils.java rename {src => paper/src}/main/resources/config1.12.2-Down.yml (100%) rename {src => paper/src}/main/resources/config1.13-Up.yml (100%) rename {src => paper/src}/main/resources/data.yml (100%) rename {src => paper/src}/main/resources/messages.yml (100%) rename {src => paper/src}/main/resources/plugin.yml (100%) rename {src => paper/src}/main/resources/test-file.yml (100%) delete mode 100644 pom.xml create mode 100644 settings.gradle.kts diff --git a/.gitignore b/.gitignore index 72db3d1..a4bf8ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,22 @@ +build +.gradle +.idea -\.idea/ +buildSrc/.gradle +buildSrc/build -*.iml +common/.gradle +common/build -*.class +jars -target/classes/ +paper/build +paper/.gradle -target/ - -\.DS_Store - -dependency-reduced-pom.xml +run +!paper/run/config +!paper/run/spigot.yml +!paper/run/bukkit.yml +!paper/run/eula.txt +!paper/run/server.properties +!paper/run/plugins \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..7ae017d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,22 @@ +# Contributing to CrazyCrates +Contributions to the project are always welcome, Pull Requests do have some guidelines before being approved. + +## You should always create the fork as a personal repository not in an organization. +Any pull request made by a fork in an organization prevents modifications. Everyone has their own way of doing things and rather asking you to change that. A personal fork lets us change the things +that we have a tick about. + +If you do not use a personal fork, We have to manually merge your pull request which means it's marked as closed instead of merged. + +## Requirements + * `git` + * Java 17 ( Adoptium is recommended ) + +Pull Requests must be labeled properly according to if it's a bug fix, a new feature or enhancements to the code base. + * `git checkout -b fix/your_fix` + * `git checkout -b feature/your_feature` + * `git checkout -b quality/your_enhancement` + * Commit your changes using `git commit -m 'your commit'` + * Push to your branch using `git push` + * Open a pull request to the `main` branch on our repository to add your change. + +You must explain what your pull request is changing and if needed, Supply a video of your change as Pull Requests are a way to get feedback. \ No newline at end of file diff --git a/LICENSE b/LICENSE index 4383cc3..cae7779 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2016 Crazy Crew +Copyright (c) 2016-2023 CrazyCrew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 07ed220..8998c42 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,110 @@ -## Crazy Auctions +
-[![Join us on Discord](https://img.shields.io/discord/182615261403283459.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.badbones69.com) +[![crazyauctions](https://raw.githubusercontent.com/RyderBelserion/Assets/main/crazycrew/webp/CrazyAuctionsBanner.webp)](https://modrinth.com/plugin/crazyauctions) -[![CrazyAuctions's Stargazers](https://img.shields.io/github/stars/Crazy-Crew/Crazy-Auctions?label=stars&logo=github)](https://github.com/Crazy-Crew/Crazy-Auctions/stargazers) -[![CrazyAuctions's Forks](https://img.shields.io/github/forks/Crazy-Crew/Crazy-Auctions?label=forks&logo=github)](https://github.com/Crazy-Crew/Crazy-Auctions/network/members) -[![CrazyAuctions's Watchers](https://img.shields.io/github/watchers/Crazy-Crew/Crazy-Auctions?label=watchers&logo=github)](https://github.com/Crazy-Crew/Crazy-Auctions/watchers) +
-CrazyAuctions is a simple auctions plugin where you can sell your items and bid on other items! +[![Contributors][contributors-shield]][contributors-url] +[![Forks][forks-shield]][forks-url] +[![Stargazers][stars-shield]][stars-url] +[![Issues][issues-shield]][issues-url] +[![GPU License][license-shield]][license-url] +[![Contact][discord-shield]][discord-url] +![CodeFactor][codefactor-shield] -## Contact -[![Join us on Discord](https://img.shields.io/discord/182615261403283459.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.badbones69.com) +![Paper](https://cdn.jsdelivr.net/gh/intergrav/devins-badges/assets/compact/supported/paper_vector.svg) +![Purpur](https://cdn.jsdelivr.net/gh/intergrav/devins-badges/assets/compact/supported/purpur_vector.svg) -Join us on [Discord](https://discord.badbones69.com) +

+ Auction off your items in style! +
+ Explore the docs » +
+
+ Report Bug + · + Request Feature + · + Get Support +

+
-## Downloads -[![Build Status](https://jenkins.badbones69.com/view/Stable/job/Crazy-Auctions/badge/icon)](https://jenkins.badbones69.com/view/Stable/job/Crazy-Auctions/) + +
+ Table of Contents +
    +
  1. + Getting Started + +
  2. +
  3. Roadmap
  4. +
  5. Contributing
  6. +
  7. License
  8. +
  9. Contact
  10. +
+
-Downloads can be obtained from the [spigot page](https://www.spigotmc.org/resources/crazy-auctions.25219/) or the [Jenkins](https://jenkins.badbones69.com/view/Stable/job/Crazy-Auctions/). +## Resource Page -## Plugin Data -[![bStats Graph Data](https://bstats.org/signatures/bukkit/CrazyAuctions.svg)](https://bstats.org/plugin/bukkit/CrazyAuctions/4624) +### Beta Builds +All beta builds will be on Modrinth marked as beta.
-## API -In Progress. +![Modrinth](https://raw.githubusercontent.com/intergrav/devins-badges/v3/assets/cozy/available/modrinth_64h.png) -### Dependency Information +## Getting Started -#### Maven -In Progress. +How to get started with contributing / maintaining your own version of CrazyAuctions! -#### Gradle -In Progress. +### Prerequisites -## Working with CrazyAuctions. +A list of things necessary to make sure you can build CrazyAuctions properly. +* Intellij IDEA + * > https://www.jetbrains.com/idea/download/ +* Gradle -#### Contributing -Fork the project & open a pull request. +### Installation -#### Compiling -Clone the project & run the install task. +1. Clone the repo + ```sh + git clone https://github.com/Crazy-Crew/CrazyAuctions.git + ``` +2. Open the repository using Intellij IDEA & wait until it finishes downloading/indexing. +3. Run the assemble task. + ```gradle + ./gradlew assemble + ``` + +## Roadmap + +Check our public [trello board](https://trello.com/b/CcPYmsBt) for our current plans, any bugs and general tracking of the project progress. + +## Contributing + +1. Fork the Project +2. Create your Feature Branch (`git checkout -b feature/yourfeature`) +3. Commit your Changes (`git commit -m 'your amazing feature.'`) +4. Push to the Branch (`git push`) +5. Open a Pull Request to the dev branch to add your feature/fix. + +## License + +Distributed under the MIT License. See [`LICENSE`](/LICENSE) for more information. + +[discord-shield]: https://img.shields.io/discord/182615261403283459.svg?style=flat&logo=appveyor +[discord-url]: https://discord.gg/crazycrew + +[contributors-shield]: https://img.shields.io/github/contributors/Crazy-Crew/CrazyAuctions.svg?style=flat&logo=appveyor +[contributors-url]: https://github.com/Crazy-Crew/CrazyAuctions/graphs/contributors +[forks-shield]: https://img.shields.io/github/forks/Crazy-Crew/CrazyAuctions.svg?style=flat&logo=appveyor +[forks-url]: https://github.com/Crazy-Crew/CrazyAuctions/network/members +[stars-shield]: https://img.shields.io/github/stars/Crazy-Crew/CrazyAuctions.svg?style=flat&logo=appveyor +[stars-url]: https://github.com/Crazy-Crew/CrazyAuctions/stargazers +[issues-shield]: https://img.shields.io/github/issues/Crazy-Crew/CrazyAuctions.svg?style=flat&logo=appveyor +[issues-url]: https://github.com/Crazy-Crew/CrazyAuctions/issues +[license-shield]: https://img.shields.io/github/license/Crazy-Crew/CrazyAuctions.svg?style=flat&logo=appveyor +[license-url]: https://github.com/Crazy-Crew/CrazyAuctions/blob/master/LICENSE + +[codefactor-shield]: https://img.shields.io/codefactor/grade/github/crazy-crew/CrazyAuctions/main?style=flat&logo=appveyor \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..c088781 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,29 @@ +plugins { + id("root-plugin") +} + +defaultTasks("build") + +tasks { + assemble { + val jarsDir = File("$rootDir/jars") + if (jarsDir.exists()) jarsDir.delete() + + subprojects.forEach { project -> + dependsOn(":${project.name}:build") + + doLast { + if (!jarsDir.exists()) jarsDir.mkdirs() + + if (project.name == "core") return@doLast + + val file = file("${project.layout.buildDirectory.get()}/libs/${rootProject.name}-${rootProject.version}.jar") + + copy { + from(file) + into(jarsDir) + } + } + } + } +} \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..742a7b8 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + `kotlin-dsl` +} + +dependencies { + implementation(libs.paperweight.plugin) + + implementation(libs.jpenilla.plugin) + + implementation(libs.shadow.plugin) +} \ No newline at end of file diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 0000000..4720f82 --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,14 @@ +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 diff --git a/buildSrc/src/main/kotlin/paper-plugin.gradle.kts b/buildSrc/src/main/kotlin/paper-plugin.gradle.kts new file mode 100644 index 0000000..24d0097 --- /dev/null +++ b/buildSrc/src/main/kotlin/paper-plugin.gradle.kts @@ -0,0 +1,23 @@ +plugins { + id("io.papermc.paperweight.userdev") + + id("root-plugin") +} + +repositories { + maven("https://repo.papermc.io/repository/maven-public/") +} + +dependencies { + paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT") +} + +tasks { + assemble { + dependsOn(reobfJar) + } + + reobfJar { + outputJar.set(file("${project.layout.buildDirectory.get()}/libs/${rootProject.name}-${rootProject.version}.jar")) + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/root-plugin.gradle.kts b/buildSrc/src/main/kotlin/root-plugin.gradle.kts new file mode 100644 index 0000000..57bb9dc --- /dev/null +++ b/buildSrc/src/main/kotlin/root-plugin.gradle.kts @@ -0,0 +1,46 @@ +plugins { + id("com.github.johnrengelman.shadow") + + `maven-publish` + `java-library` +} + +repositories { + maven("https://repo.triumphteam.dev/snapshots/") + + maven("https://repo.crazycrew.us/releases/") + + maven("https://jitpack.io") + + mavenCentral() +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of("17")) +} + +tasks { + compileJava { + options.encoding = Charsets.UTF_8.name() + options.release.set(17) + } + + shadowJar { + mergeServiceFiles() + + exclude("META-INF/**") + } +} + +publishing { + repositories { + maven { + credentials { + this.username = System.getenv("gradle_username") + this.password = System.getenv("gradle_password") + } + + url = uri("https://repo.crazycrew.us/releases/") + } + } +} \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts new file mode 100644 index 0000000..89b9b31 --- /dev/null +++ b/common/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + id("root-plugin") +} + +project.group = "${rootProject.group}.common" +project.version = "${rootProject.version}" + +dependencies { + api(libs.configme) { + exclude("org.yaml", "snakeyaml") + } + + compileOnly(libs.annotations) +} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/CrazyAuctionsPlugin.java b/common/src/main/java/com/badbones69/crazyauctions/common/CrazyAuctionsPlugin.java new file mode 100644 index 0000000..019f2ee --- /dev/null +++ b/common/src/main/java/com/badbones69/crazyauctions/common/CrazyAuctionsPlugin.java @@ -0,0 +1,81 @@ +package com.badbones69.crazyauctions.common; + +import ch.jalu.configme.SettingsManager; +import ch.jalu.configme.SettingsManagerBuilder; +import com.badbones69.crazyauctions.common.config.ConfigBuilder; +import com.badbones69.crazyauctions.common.config.types.PluginConfig; +import java.io.File; +import java.nio.file.Path; + +public class CrazyAuctionsPlugin { + + private final Path path; + + public CrazyAuctionsPlugin(Path path) { + this.path = path; + } + + private static SettingsManager locale; + private static SettingsManager config; + private static SettingsManager pluginConfig; + + public void load() { + File pluginConfigFile = new File(this.path.toFile(), "plugin-config.yml"); + + pluginConfig = SettingsManagerBuilder + .withYamlFile(pluginConfigFile) + .useDefaultMigrationService() + .configurationData(ConfigBuilder.buildPluginConfig()) + .create(); + + File localeDir = new File(this.path.toFile(), "locale"); + //FileUtils.extract("/locale/", this.path, false); + + File localeFile = new File(localeDir, pluginConfig.getProperty(PluginConfig.LOCALE_FILE) + ".yml"); + + locale = SettingsManagerBuilder + .withYamlFile(localeFile) + .useDefaultMigrationService() + .configurationData(ConfigBuilder.buildLocale()) + .create(); + + // Create config.yml + File configFile = new File(this.path.toFile(), "config.yml"); + + config = SettingsManagerBuilder + .withYamlFile(configFile) + .useDefaultMigrationService() + .configurationData(ConfigBuilder.buildConfig()) + .create(); + + } + + public void reload() { + // Reload configs. + pluginConfig.reload(); + config.reload(); + + locale.reload(); + + File localeDir = new File(this.path.toFile(), "locale"); + File localeFile = new File(localeDir, pluginConfig.getProperty(PluginConfig.LOCALE_FILE) + ".yml"); + + locale = SettingsManagerBuilder + .withYamlFile(localeFile) + .useDefaultMigrationService() + .configurationData(ConfigBuilder.buildLocale()) + .create(); + } + + public static SettingsManager getPluginConfig() { + return pluginConfig; + } + + public static SettingsManager getLocale() { + return locale; + } + + public static SettingsManager getConfig() { + return config; + } +} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/config/ConfigBuilder.java b/common/src/main/java/com/badbones69/crazyauctions/common/config/ConfigBuilder.java new file mode 100644 index 0000000..a3eb53b --- /dev/null +++ b/common/src/main/java/com/badbones69/crazyauctions/common/config/ConfigBuilder.java @@ -0,0 +1,30 @@ +package com.badbones69.crazyauctions.common.config; + +import ch.jalu.configme.configurationdata.ConfigurationData; +import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; +import com.badbones69.crazyauctions.common.config.types.Config; +import com.badbones69.crazyauctions.common.config.types.Messages; +import com.badbones69.crazyauctions.common.config.types.PluginConfig; + +public class ConfigBuilder { + + private ConfigBuilder() {} + + public static ConfigurationData buildPluginConfig() { + return ConfigurationDataBuilder.createConfiguration( + PluginConfig.class + ); + } + + public static ConfigurationData buildConfig() { + return ConfigurationDataBuilder.createConfiguration( + Config.class + ); + } + + public static ConfigurationData buildLocale() { + return ConfigurationDataBuilder.createConfiguration( + Messages.class + ); + } +} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Config.java b/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Config.java new file mode 100644 index 0000000..0e66d3d --- /dev/null +++ b/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Config.java @@ -0,0 +1,43 @@ +package com.badbones69.crazyauctions.common.config.types; + +import ch.jalu.configme.Comment; +import ch.jalu.configme.SettingsHolder; +import ch.jalu.configme.configurationdata.CommentsConfiguration; +import ch.jalu.configme.properties.Property; +import static ch.jalu.configme.properties.PropertyInitializer.newProperty; + +public class Config implements SettingsHolder { + + public Config() {} + + @Override + public void registerComments(CommentsConfiguration conf) { + String[] header = { + "Github: https://github.com/Crazy-Crew", + "", + "Issues: https://github.com/Crazy-Crew/CrazyAuctions/issues", + "Features: https://github.com/Crazy-Crew/CrazyAuctions//discussions/categories/features", + "", + "Legacy color codes such as &7,&c no longer work. You must use MiniMessage", + "https://docs.advntr.dev/minimessage/format.html#color" + }; + + String[] deprecation = { + "", + "Warning: This section is subject to change so it is considered deprecated.", + "This is your warning before the change happens.", + "" + }; + + conf.setComment("misc", header); + } + + @Comment("Allow damage items to be auctioned off.") + public static final Property damaged_items = newProperty("misc.allow-damaged-items", false); + + @Comment("Whether or not to allow `ah sell` or not.") + public static final Property selling_module = newProperty("modules.selling-module", true); + + @Comment("Whether or not to allow `ah buy` or not.") + public static final Property bidding_module = newProperty("modules.bidding-module", true); +} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Messages.java b/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Messages.java new file mode 100644 index 0000000..31670d2 --- /dev/null +++ b/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Messages.java @@ -0,0 +1,47 @@ +package com.badbones69.crazyauctions.common.config.types; + +import ch.jalu.configme.SettingsHolder; +import ch.jalu.configme.configurationdata.CommentsConfiguration; +import ch.jalu.configme.properties.Property; +import ch.jalu.configme.properties.PropertyInitializer; + +public class Messages implements SettingsHolder { + + public Messages() {} + + @Override + public void registerComments(CommentsConfiguration conf) { + String[] header = { + "Submit your translations here: https://github.com/Crazy-Crew/CrazyAuctions/discussions/categories/translations", + "", + "Legacy color codes such as &7,&c no longer work. You must use MiniMessage", + "https://docs.advntr.dev/minimessage/format.html#color" + }; + + String[] deprecation = { + "", + "Warning: This section is subject to change so it is considered deprecated.", + "This is your warning before the change happens.", + "" + }; + + conf.setComment("general", header); + } + + public static final Property unknown_command = PropertyInitializer.newProperty("general.unknown-command", "{prefix}The command {command} is not known."); + + public static final Property INVALID_SYNTAX = PropertyInitializer.newProperty("general.invalid-syntax", "{prefix}{value} is an invalid {action}."); + + public static final Property NO_PERMISSION = PropertyInitializer.newProperty("general.no-permission", "{prefix}You do not have permission to use that command!"); + + public static final Property REQUIRED_ARGUMENT = PropertyInitializer.newProperty("general.checks.required-argument", "{prefix}This argument is not optional"); + + public static final Property OPTIONAL_ARGUMENT = PropertyInitializer.newProperty("general.checks.optional-argument", "{prefix}This argument is optional"); + + public static final Property NOT_ENOUGH_ARGS = PropertyInitializer.newProperty("general.checks.not-enough-args", "{prefix}You did not supply enough arguments."); + + public static final Property TOO_MANY_ARGS = PropertyInitializer.newProperty("general.checks.too-many-args", "{prefix}You put more arguments then I can handle."); + + public static final Property MUST_BE_PLAYER = PropertyInitializer.newProperty("general.player-checks.must-be-player", "{prefix}You must be a player to use this command."); + +} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/config/types/PluginConfig.java b/common/src/main/java/com/badbones69/crazyauctions/common/config/types/PluginConfig.java new file mode 100644 index 0000000..7bc2f51 --- /dev/null +++ b/common/src/main/java/com/badbones69/crazyauctions/common/config/types/PluginConfig.java @@ -0,0 +1,33 @@ +package com.badbones69.crazyauctions.common.config.types; + +import ch.jalu.configme.Comment; +import ch.jalu.configme.SettingsHolder; +import ch.jalu.configme.properties.Property; +import ch.jalu.configme.properties.PropertyInitializer; +import static ch.jalu.configme.properties.PropertyInitializer.newProperty; + +/** + * Description: The plugin-settings.yml options. + */ +public class PluginConfig implements SettingsHolder { + + // Empty constructor required by SettingsHolder + protected PluginConfig() {} + + @Comment({ + "Choose what language you want the plugin to be in.", + "", + "Available Languages: en-US" + }) + public static final Property LOCALE_FILE = PropertyInitializer.newProperty("language", "en-US"); + + @Comment("Whether you want CrazyAuctions to shut up or not, This option is ignored by errors.") + public static final Property verbose_logging = newProperty("verbose_logging", true); + + @Comment({ + "Sends anonymous statistics about how the plugin is used to bstats.org.", + "bstats is a service for plugin developers to find out how the plugin being used,", + "This information helps us figure out how to better improve the plugin." + }) + public static final Property toggle_metrics = newProperty("toggle_metrics", true); +} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/data/UserCache.java b/common/src/main/java/com/badbones69/crazyauctions/common/data/UserCache.java new file mode 100644 index 0000000..6fae776 --- /dev/null +++ b/common/src/main/java/com/badbones69/crazyauctions/common/data/UserCache.java @@ -0,0 +1,39 @@ +package com.badbones69.crazyauctions.common.data; + +import java.nio.file.Path; +import java.util.UUID; + +public interface UserCache { + + /** + * Add a player to the hashmap if absent. + * + * @param uuid player uuid + */ + void addPlayer(final UUID uuid); + + /** + * Remove the player from the hashmap. + * + * @param uuid player uuid + */ + void removePlayer(final UUID uuid); + + /** + * Fetch the player if online or offline. + * + * @param uuid player uuid + * @return player object + */ + String getPlayerName(final UUID uuid); + + /** + * Fetch the uuid file of the player. + * + * @param path the path i.e. 'CrazyAuctions/userdata/random-uuid.' + * @param uuid the player uuid + * @return the complete path + */ + Path getFile(final Path path, UUID uuid); + +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..4f7595f --- /dev/null +++ b/gradle.properties @@ -0,0 +1,15 @@ +org.gradle.jvmargs = '-Xmx3G' +org.gradle.parallel = false +org.gradle.warning.mode = all + +authors = ["Ryderbelserion, Badbones69"] +website = https://modrinth.com/plugin/crazycrates +sources = https://github.com/Crazy-Crew/CrazyCrates +issues = https://github.com/Crazy-Crew/CrazyCrates/issues + +group = us.crazycrew.crazycrates +description = Add unlimited crates to your server with 10 different crate types to choose from! +version = 1.18 +apiVersion = 1.20 + +minecraftVersion=1.20.2 \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..f8deb82 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,46 @@ +[versions] +paperweight_version = "1.5.8" +run_paper_version = "2.2.0" +shadow_version = "8.1.1" + +jetbrains_kotlin = "1.9.10" + +cluster_version = "2.4" +kyori_version = "4.14.0" + +[plugins] +hangar = { id = "io.papermc.hangar-publish-plugin", version = "0.1.0" } +modrinth = { id = "com.modrinth.minotaur", version = "2.8.4" } + +[libraries] +cluster_paper = { module = "com.ryderbelserion.cluster:cluster-paper", version.ref = "cluster_version" } +cluster_api = { module = "com.ryderbelserion.cluster:cluster-api", version.ref = "cluster_version" } + +adventure = { module = "net.kyori:adventure-api", version.ref = "kyori_version" } +minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "kyori_version" } + +nbtapi = { module = "de.tr7zw:item-nbt-api", version = "2.12.0" } + +annotations = { module = "org.jetbrains:annotations", version = "24.0.1" } +kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "jetbrains_kotlin" } + +triumphcmds = { module = "dev.triumphteam:triumph-cmd-bukkit", version = "2.0.0-SNAPSHOT" } + +configme = { module = "ch.jalu:configme", version = "1.4.1" } + +metrics = { module = "org.bstats:bstats-bukkit", version = "3.0.2" } + +itemsadder = { module = "com.github.LoneDev6:api-itemsadder", version = "3.6.1" } +oraxen = { module = "com.github.oraxen:oraxen", version = "1.162.0" } + +holographicdisplays = { module = "me.filoghost.holographicdisplays:holographicdisplays-api", version = "3.0.0" } +decentholograms = { module = "com.github.decentsoftware-eu:decentholograms", version = "2.8.4" } + +placeholderapi = { module = "me.clip:placeholderapi", version = "2.11.4" } + +# Plugins +paperweight_plugin = { module = "io.papermc.paperweight:paperweight-userdev", version.ref = "paperweight_version" } +jpenilla_plugin = { module = "xyz.jpenilla:run-task", version.ref = "run_paper_version" } +shadow_plugin = { module = "com.github.johnrengelman:shadow", version.ref = "shadow_version" } + +kotlin_plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "jetbrains_kotlin" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..7f93135c49b765f8051ef9d0a6055ff8e46073d8 GIT binary patch literal 63721 zcmb5Wb9gP!wgnp7wrv|bwr$&XvSZt}Z6`anZSUAlc9NHKf9JdJ;NJVr`=eI(_pMp0 zy1VAAG3FfAOI`{X1O)&90s;U4K;XLp008~hCjbEC_fbYfS%6kTR+JtXK>nW$ZR+`W ze|#J8f4A@M|F5BpfUJb5h>|j$jOe}0oE!`Zf6fM>CR?!y@zU(cL8NsKk`a z6tx5mAkdjD;J=LcJ;;Aw8p!v#ouk>mUDZF@ zK>yvw%+bKu+T{Nk@LZ;zkYy0HBKw06_IWcMHo*0HKpTsEFZhn5qCHH9j z)|XpN&{`!0a>Vl+PmdQc)Yg4A(AG-z!+@Q#eHr&g<9D?7E)_aEB?s_rx>UE9TUq|? z;(ggJt>9l?C|zoO@5)tu?EV0x_7T17q4fF-q3{yZ^ipUbKcRZ4Qftd!xO(#UGhb2y>?*@{xq%`(-`2T^vc=#< zx!+@4pRdk&*1ht2OWk^Z5IAQ0YTAXLkL{(D*$gENaD)7A%^XXrCchN&z2x+*>o2FwPFjWpeaL=!tzv#JOW#( z$B)Nel<+$bkH1KZv3&-}=SiG~w2sbDbAWarg%5>YbC|}*d9hBjBkR(@tyM0T)FO$# zPtRXukGPnOd)~z=?avu+4Co@wF}1T)-uh5jI<1$HLtyDrVak{gw`mcH@Q-@wg{v^c zRzu}hMKFHV<8w}o*yg6p@Sq%=gkd~;`_VGTS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L_2;knQ!DuDl0R`|%jr+}jFzXtrHIKc323?JO{l&;VF z*L1+}JU7%QJOg|5|Tc|D8fN zJORAg=_vsy{ak|o);@)Yh8Lkcg@$FG3k@ep36BRa^>~UmnRPziS>Z=`Jb2x*Q#`%A zU*i3&Vg?TluO@X0O;r2Jl6LKLUOVhSqg1*qOt^|8*c7 zo(298@+r$k_wQNGHv{|$tW(T8L+4_`FQ{kEW5Jgg{yf7ey4ss_(SNKfz(N9lx&a;< je(UuV8hP?p&}TPdm1I$XmG#(RzlD&B2izSj9sl%y5~4qc literal 0 HcmV?d00001 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..3fa8f86 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..1aa94a4 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts new file mode 100644 index 0000000..be8b59b --- /dev/null +++ b/paper/build.gradle.kts @@ -0,0 +1,125 @@ +import io.papermc.hangarpublishplugin.model.Platforms + +plugins { + alias(libs.plugins.modrinth) + alias(libs.plugins.hangar) + + id("xyz.jpenilla.run-paper") + + id("paper-plugin") +} + +project.group = "${rootProject.group}.paper" + +repositories { + maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") + + maven("https://repo.codemc.org/repository/maven-public/") + + maven("https://repo.crazycrew.us/first-party/") + + maven("https://repo.crazycrew.us/third-party/") + + flatDir { dirs("libs") } +} + +dependencies { + +} + +tasks { + runServer { + jvmArgs("-Dnet.kyori.ansi.colorLevel=truecolor") + + minecraftVersion("1.20.2") + } + + shadowJar { + listOf( + "de.tr7zw.changeme.nbtapi", + "org.bstats", + "ch.jalu" + ).forEach { + relocate(it, "libs.$it") + } + } + + processResources { + val props = mapOf( + "name" to rootProject.name, + "group" to project.group.toString(), + "version" to rootProject.version, + "description" to rootProject.description, + "authors" to rootProject.properties["authors"], + "apiVersion" to "1.20", + "website" to "https://modrinth.com/plugin/${rootProject.name.lowercase()}" + ) + + filesMatching("plugin.yml") { + expand(props) + } + } +} + +val isSnapshot = true +val type = if (isSnapshot) "beta" else "release" +val other = if (isSnapshot) "Beta" else "Release" + +val file = file("${rootProject.rootDir}/jars/${rootProject.name}-${rootProject.version}.jar") + +val description = """ +## Fixes: + * Fix not crates being wrongly labeled as virtual crates if they are quadcrate, quickcrate or ones that need to be in the physical world. + +## Other: + * [Feature Requests](https://github.com/Crazy-Crew/${rootProject.name}/issues) + * [Bug Reports](https://github.com/Crazy-Crew/${rootProject.name}/issues) +""".trimIndent() + +val versions = listOf( + "1.20", + "1.20.1", + "1.20.2" +) + +modrinth { + autoAddDependsOn.set(false) + + token.set(System.getenv("modrinth_token")) + + projectId.set(rootProject.name.lowercase()) + + versionName.set("${rootProject.name} ${rootProject.version}") + versionNumber.set("${rootProject.version}") + + versionType.set(type) + + uploadFile.set(file("${rootProject.rootDir}/jars/${rootProject.name}-${rootProject.version}.jar")) + + gameVersions.addAll(versions) + + changelog.set(description) + + loaders.addAll("paper", "purpur") +} + +hangarPublish { + publications.register("plugin") { + version.set(rootProject.version as String) + + id.set(rootProject.name) + + channel.set(if (isSnapshot) "Beta" else "Release") + + changelog.set(description) + + apiKey.set(System.getenv("hangar_key")) + + platforms { + register(Platforms.PAPER) { + jar.set(file("${rootProject.rootDir}/jars/${rootProject.name}-${rootProject.version}.jar")) + platformVersions.set(versions) + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/Main.java b/paper/src/main/java/com/badbones69/crazyauctions/Main.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/Main.java rename to paper/src/main/java/com/badbones69/crazyauctions/Main.java diff --git a/src/main/java/com/badbones69/crazyauctions/Methods.java b/paper/src/main/java/com/badbones69/crazyauctions/Methods.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/Methods.java rename to paper/src/main/java/com/badbones69/crazyauctions/Methods.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/Category.java b/paper/src/main/java/com/badbones69/crazyauctions/api/Category.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/Category.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/Category.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java b/paper/src/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/FileManager.java b/paper/src/main/java/com/badbones69/crazyauctions/api/FileManager.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/FileManager.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/FileManager.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/Messages.java b/paper/src/main/java/com/badbones69/crazyauctions/api/Messages.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/Messages.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/Messages.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/ShopType.java b/paper/src/main/java/com/badbones69/crazyauctions/api/ShopType.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/ShopType.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/ShopType.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/Version.java b/paper/src/main/java/com/badbones69/crazyauctions/api/Version.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/Version.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/Version.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java b/paper/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java diff --git a/src/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java b/paper/src/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java rename to paper/src/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java diff --git a/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java b/paper/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/controllers/GUI.java rename to paper/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java diff --git a/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java b/paper/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java rename to paper/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java diff --git a/src/main/java/com/badbones69/crazyauctions/currency/Vault.java b/paper/src/main/java/com/badbones69/crazyauctions/currency/Vault.java similarity index 100% rename from src/main/java/com/badbones69/crazyauctions/currency/Vault.java rename to paper/src/main/java/com/badbones69/crazyauctions/currency/Vault.java diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyAuctions.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyAuctions.java new file mode 100644 index 0000000..de1e841 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyAuctions.java @@ -0,0 +1,55 @@ +package com.badbones69.crazyauctions; + +import com.badbones69.crazyauctions.api.CrazyManager; +import com.badbones69.crazyauctions.api.frame.PaperCore; +import com.badbones69.crazyauctions.api.frame.command.CommandManager; +import com.badbones69.crazyauctions.commands.inventories.AuctionInventoryClick; +import com.badbones69.crazyauctions.events.DataListener; +import org.bukkit.plugin.java.JavaPlugin; + +public class CrazyAuctions extends JavaPlugin { + + private final ApiManager apiManager; + private final PaperCore paperCore; + private CommandManager commandManager; + + private CrazyManager crazyManager; + + public CrazyAuctions(ApiManager apiManager, PaperCore paperCore) { + this.apiManager = apiManager; + this.paperCore = paperCore; + } + + @Override + public void onEnable() { + this.commandManager = CommandManager.create(); + + this.crazyManager = new CrazyManager(); + this.crazyManager.load(true); + + getServer().getPluginManager().registerEvents(new DataListener(), this); + getServer().getPluginManager().registerEvents(new AuctionInventoryClick(), this); + + } + + @Override + public void onDisable() { + if (this.crazyManager != null) this.crazyManager.stop(); + } + + public ApiManager getApiManager() { + return this.apiManager; + } + + public PaperCore getPaperCore() { + return this.paperCore; + } + + public CommandManager getCommandManager() { + return this.commandManager; + } + + public CrazyManager getCrazyManager() { + return this.crazyManager; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyStarter.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyStarter.java new file mode 100644 index 0000000..700825f --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyStarter.java @@ -0,0 +1,30 @@ +package com.badbones69.crazyauctions; + +import com.badbones69.crazyauctions.api.frame.PaperCore; +import io.papermc.paper.plugin.bootstrap.BootstrapContext; +import io.papermc.paper.plugin.bootstrap.PluginBootstrap; +import io.papermc.paper.plugin.bootstrap.PluginProviderContext; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import com.badbones69.crazyauctions.config.types.PluginConfig; + +@SuppressWarnings("ALL") +public class CrazyStarter implements PluginBootstrap { + + private ApiManager apiManager; + + @Override + public void bootstrap(@NotNull BootstrapContext context) { + this.apiManager = new ApiManager(context.getDataDirectory()); + this.apiManager.load(); + } + + @Override + public @NotNull JavaPlugin createPlugin(@NotNull PluginProviderContext context) { + PaperCore paperCore = new PaperCore(context.getDataDirectory(), Bukkit.getConsoleSender(), ApiManager.getPluginConfig().getProperty(PluginConfig.COMMAND_PREFIX), ApiManager.getPluginConfig().getProperty(PluginConfig.CONSOLE_PREFIX)); + paperCore.enable(); + + return new CrazyAuctions(this.apiManager, paperCore); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/CrazyManager.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/CrazyManager.java new file mode 100644 index 0000000..884856d --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/CrazyManager.java @@ -0,0 +1,34 @@ +package com.badbones69.crazyauctions.api; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.storage.types.StorageManager; +import org.bukkit.plugin.java.JavaPlugin; + +public class CrazyManager { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private StorageManager storageManager; + + public void load(boolean serverStart) { + if (serverStart) { + this.storageManager = new StorageManager(); + + this.storageManager.init(); + } + } + + public void reload() { + if (this.plugin.getApiManager() != null) this.plugin.getApiManager().reload(); + + if (this.storageManager.getUserManager() != null) this.storageManager.getUserManager().save(false); + } + + public void stop() { + + } + + public StorageManager getStorageManager() { + return this.storageManager; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/Permissions.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/Permissions.java new file mode 100644 index 0000000..7f2b613 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/Permissions.java @@ -0,0 +1,38 @@ +package com.badbones69.crazyauctions.api.enums; + +import org.bukkit.permissions.PermissionDefault; + +public enum Permissions { + + PLAYER_HELP("player.help", "Gives access to the help command.", PermissionDefault.TRUE); + + private final String node; + private final String description; + private final PermissionDefault permissionDefault; + + Permissions(String node, String description, PermissionDefault permissionDefault) { + this.node = node; + this.description = description; + this.permissionDefault = permissionDefault; + } + + public String getNode() { + return this.node; + } + + public String getDescription() { + return this.description; + } + + public PermissionDefault getPermissionDefault() { + return this.permissionDefault; + } + + public String getBuiltPermission(String action) { + return "crazyauctions." + action + "." + this.node; + } + + public String getBuiltPermission() { + return "crazyauctions.command." + this.node; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/support/DataSupport.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/support/DataSupport.java new file mode 100644 index 0000000..affcc65 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/support/DataSupport.java @@ -0,0 +1,19 @@ +package com.badbones69.crazyauctions.api.enums.support; + +import com.badbones69.crazyauctions.storage.interfaces.UserManager; +import com.badbones69.crazyauctions.storage.types.file.yaml.YamlUserManager; + +public enum DataSupport { + + yaml(YamlUserManager.class); + + private final Class classObject; + + DataSupport(Class classObject) { + this.classObject = classObject; + } + + public Class getClassObject() { + return this.classObject; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionAddEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionAddEvent.java new file mode 100644 index 0000000..ca70dfc --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionAddEvent.java @@ -0,0 +1,62 @@ +package com.badbones69.crazyauctions.api.events; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.api.manager.interfaces.AuctionItem; +import com.badbones69.crazyauctions.api.manager.objects.AuctionHouse; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import java.util.UUID; + +/** + * Description: This event is fired when an item is added to an auction house. + */ +public class AuctionAddEvent extends Event { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private static final HandlerList handlerList = new HandlerList(); + + private final UUID uuid; + private final Player player; + private final AuctionItem auctionItem; + private final AuctionHouse auctionHouse; + + /** + * A constructor to include values for a bid event. + * + * @param uuid the uuid of the player who placed the bid. + * @param auctionHouse the auction house the item is being added to. + * @param auctionItem the auction item being added. + */ + public AuctionAddEvent(UUID uuid, AuctionHouse auctionHouse, AuctionItem auctionItem) { + this.uuid = uuid; + this.player = this.plugin.getServer().getPlayer(uuid); + this.auctionHouse = auctionHouse; + this.auctionItem = auctionItem; + } + + public AuctionItem getAuctionItem() { + return auctionItem; + } + + public AuctionHouse getAuctionHouse() { + return auctionHouse; + } + + public Player getPlayer() { + return this.player; + } + + public UUID getUUID() { + return this.uuid; + } + + @Override + public @NotNull HandlerList getHandlers() { + return handlerList; + } + +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBidEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBidEvent.java new file mode 100644 index 0000000..c928dbd --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBidEvent.java @@ -0,0 +1,65 @@ +package com.badbones69.crazyauctions.api.events; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import java.util.UUID; + +/** + * Description: This event is fired when a player bids on an auction. + */ +public class AuctionBidEvent extends Event { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private static final HandlerList handlerList = new HandlerList(); + + private final UUID uuid; + private final Player player; + + private final ItemStack item; + + private final long bidPrice; + + /** + * A constructor to include values for a bid event. + * + * @param uuid the uuid of the player who placed the bid. + * @param item the item that was bid on. + * @param bidPrice the amount of money that was bid. + */ + public AuctionBidEvent(UUID uuid, ItemStack item, long bidPrice) { + this.uuid = uuid; + + this.player = this.plugin.getServer().getPlayer(uuid); + + this.item = item; + + this.bidPrice = bidPrice; + } + + public ItemStack getBidItem() { + return this.item; + } + + public long getBidPrice() { + return this.bidPrice; + } + + public Player getPlayer() { + return this.player; + } + + public UUID getUUID() { + return this.uuid; + } + + @Override + public @NotNull HandlerList getHandlers() { + return handlerList; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBuyEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBuyEvent.java new file mode 100644 index 0000000..3a37ddb --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBuyEvent.java @@ -0,0 +1,65 @@ +package com.badbones69.crazyauctions.api.events; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import java.util.UUID; + +/** + * Description: This event is fired when a player buys an item. + */ +public class AuctionBuyEvent extends Event { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private static final HandlerList handlerList = new HandlerList(); + + private final UUID uuid; + private final Player player; + + private final ItemStack item; + + private final long price; + + /** + * A constructor to include values for a buy event. + * + * @param uuid the uuid of the player who purchased the item. + * @param item the item that was purchased. + * @param price the amount of money used to buy. + */ + public AuctionBuyEvent(UUID uuid, ItemStack item, long price) { + this.uuid = uuid; + + this.player = this.plugin.getServer().getPlayer(uuid); + + this.item = item; + + this.price = price; + } + + public ItemStack getWinningItem() { + return this.item; + } + + public long getBuyPrice() { + return this.price; + } + + public Player getPlayer() { + return this.player; + } + + public UUID getUUID() { + return this.uuid; + } + + @Override + public @NotNull HandlerList getHandlers() { + return handlerList; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionCancelEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionCancelEvent.java new file mode 100644 index 0000000..8b3e87d --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionCancelEvent.java @@ -0,0 +1,82 @@ +package com.badbones69.crazyauctions.api.events; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import java.util.UUID; + +/** + * Description: This event is fired when an auction is cancelled. + */ +public class AuctionCancelEvent extends Event { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private static final HandlerList handlerList = new HandlerList(); + + private final UUID uuid; + private final Player player; + private final OfflinePlayer offlinePlayer; + + private final ItemStack item; + + /** + * A constructor to include values for when an item is cancelled. + * + * @param uuid the uuid of the player whose item cancelled. + */ + public AuctionCancelEvent(UUID uuid, ItemStack item) { + this.uuid = uuid; + + this.player = this.plugin.getServer().getPlayer(uuid); + + this.offlinePlayer = this.plugin.getServer().getOfflinePlayer(uuid); + + this.item = item; + } + + /** + * @return the expired item. + */ + public ItemStack getExpiredItem() { + return this.item; + } + + /** + * Only use this when the player is online. + * + * @return the online player. + */ + public Player getPlayer() { + return this.player; + } + + /** + * Only use this when the player is offline. + * + * @return the offline player. + */ + public OfflinePlayer getOfflinePlayer() { + return this.offlinePlayer; + } + + /** + * @return the player's uuid. + */ + public UUID getUUID() { + return this.uuid; + } + + /** + * @return the handler list. + */ + @Override + public @NotNull HandlerList getHandlers() { + return handlerList; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionExpireEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionExpireEvent.java new file mode 100644 index 0000000..62e1cd2 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionExpireEvent.java @@ -0,0 +1,55 @@ +package com.badbones69.crazyauctions.api.events; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import java.util.UUID; + +/** + * Description: This event is fired when an auction expires. + */ +public class AuctionExpireEvent extends Event { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private static final HandlerList handlerList = new HandlerList(); + + private final UUID uuid; + private final Player player; + + private final ItemStack item; + + /** + * A constructor to include values for when an item expired. + * + * @param uuid the uuid of the player whose auction expired. + */ + public AuctionExpireEvent(UUID uuid, ItemStack item) { + this.uuid = uuid; + + this.player = this.plugin.getServer().getPlayer(uuid); + + this.item = item; + } + + public ItemStack getExpiredItem() { + return this.item; + } + + public Player getPlayer() { + return this.player; + } + + public UUID getUUID() { + return this.uuid; + } + + @Override + public @NotNull HandlerList getHandlers() { + return handlerList; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionListEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionListEvent.java new file mode 100644 index 0000000..43a747c --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionListEvent.java @@ -0,0 +1,65 @@ +package com.badbones69.crazyauctions.api.events; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import java.util.UUID; + +/** + * Description: This event is fired when a player lists an item. + */ +public class AuctionListEvent extends Event { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private static final HandlerList handlerList = new HandlerList(); + + private final UUID uuid; + private final Player player; + + private final ItemStack item; + + private final long bidPrice; + + /** + * A constructor to include values for a bid event. + * + * @param uuid the uuid of the player who placed the bid. + * @param item the item that was bid on. + * @param bidPrice the amount of money that was bid. + */ + public AuctionListEvent(UUID uuid, ItemStack item, long bidPrice) { + this.uuid = uuid; + + this.player = this.plugin.getServer().getPlayer(uuid); + + this.item = item; + + this.bidPrice = bidPrice; + } + + public ItemStack getBidItem() { + return this.item; + } + + public long getBidPrice() { + return this.bidPrice; + } + + public Player getPlayer() { + return this.player; + } + + public UUID getUUID() { + return this.uuid; + } + + @Override + public @NotNull HandlerList getHandlers() { + return handlerList; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionWinEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionWinEvent.java new file mode 100644 index 0000000..8dd2ba3 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionWinEvent.java @@ -0,0 +1,65 @@ +package com.badbones69.crazyauctions.api.events; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import java.util.UUID; + +/** + * Description: This event is fired when an auction has a winner. + */ +public class AuctionWinEvent extends Event { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private static final HandlerList handlerList = new HandlerList(); + + private final UUID uuid; + private final Player player; + + private final ItemStack item; + + private final long price; + + /** + * A constructor to include values for a win event. + * + * @param uuid the uuid of the player who won the bid. + * @param item the item that was won. + * @param price the amount of money that was bid. + */ + public AuctionWinEvent(UUID uuid, ItemStack item, long price) { + this.uuid = uuid; + + this.player = this.plugin.getServer().getPlayer(uuid); + + this.item = item; + + this.price = price; + } + + public ItemStack getWinningItem() { + return this.item; + } + + public long getWinningPrice() { + return this.price; + } + + public Player getPlayer() { + return this.player; + } + + public UUID getUUID() { + return this.uuid; + } + + @Override + public @NotNull HandlerList getHandlers() { + return handlerList; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/ItemUtils.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/ItemUtils.java new file mode 100644 index 0000000..98e128e --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/ItemUtils.java @@ -0,0 +1,27 @@ +package com.badbones69.crazyauctions.api.frame; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +public class ItemUtils { + + private final Material skull = Material.PLAYER_HEAD; + + public ItemStack skull() { + return new ItemStack(skull); + } + + public boolean isPlayerSkull(Material itemStack) { + return itemStack != skull; + } + + private String getVersion() { + String version = Bukkit.getServer().getClass().getPackage().getName(); + return version.substring(version.lastIndexOf('.') + 1); + } + + public Class craftClass(String name) throws ClassNotFoundException { + return Class.forName("org.bukkit.craftbukkit." + getVersion() + "." + name); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperCore.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperCore.java new file mode 100644 index 0000000..bf43192 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperCore.java @@ -0,0 +1,140 @@ +package com.badbones69.crazyauctions.api.frame; + +import com.badbones69.crazyauctions.ApiManager; +import com.badbones69.crazyauctions.config.types.Locale; +import com.badbones69.crazyauctions.config.types.PluginConfig; +import com.badbones69.crazyauctions.frame.CrazyCore; +import com.badbones69.crazyauctions.frame.storage.FileHandler; +import net.kyori.adventure.audience.Audience; +import java.nio.file.Path; + +public class PaperCore extends CrazyCore { + + private final Path path; + private final Audience audience; + private final FileHandler fileHandler; + private final String prefix; + private final String consolePrefix; + + public PaperCore(Path path, Audience audience, String prefix, String consolePrefix) { + // Create directory. + this.path = path; + this.path.toFile().mkdir(); + + this.audience = audience; + this.prefix = prefix; + this.consolePrefix = consolePrefix; + + this.fileHandler = new FileHandler(); + } + + @Override + public void enable() { + super.enable(); + } + + @Override + public void disable() { + super.disable(); + } + + @Override + public Path getDirectory() { + return this.path; + } + + @Override + public String getPrefix() { + return this.prefix; + } + + @Override + public String getConsolePrefix() { + return this.consolePrefix; + } + + @Override + public FileHandler getFileHandler() { + return this.fileHandler; + } + + @Override + public Audience adventure() { + return this.audience; + } + + @Override + public String commandTooFewArgs() { + return ApiManager.getLocale().getProperty(Locale.NOT_ENOUGH_ARGS); + } + + @Override + public String commandTooManyArgs() { + return ApiManager.getLocale().getProperty(Locale.TOO_MANY_ARGS); + } + + @Override + public String commandOptionalMsg() { + return ApiManager.getLocale().getProperty(Locale.OPTIONAL_ARGUMENT); + } + + @Override + public String commandRequiredMsg() { + return ApiManager.getLocale().getProperty(Locale.REQUIRED_ARGUMENT); + } + + @Override + public String commandRequirementNotPlayer() { + return ApiManager.getLocale().getProperty(Locale.MUST_BE_PLAYER); + } + + @Override + public String commandRequirementNoPermission() { + return ApiManager.getLocale().getProperty(Locale.NO_PERMISSION); + } + + @Override + public String commandHelpHeader() { + return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_HEADER); + } + + @Override + public String commandHelpFooter() { + return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_FOOTER); + } + + @Override + public String commandInvalidPage() { + return ApiManager.getPluginConfig().getProperty(PluginConfig.INVALID_HELP_PAGE); + } + + @Override + public String commandPageFormat() { + return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_FORMAT); + } + + @Override + public String commandHoverFormat() { + return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_HOVER_FORMAT); + } + + @Override + public String commandHoverAction() { + return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_HOVER_ACTION); + } + + @Override + public String commandNavigationText() { + return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_GO_TO_PAGE); + } + + @Override + public String commandNavigationNextButton() { + return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_NEXT); + } + + @Override + public String commandNavigationBackButton() { + return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_BACK); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperUtils.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperUtils.java new file mode 100644 index 0000000..43e1bf3 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperUtils.java @@ -0,0 +1,25 @@ +package com.badbones69.crazyauctions.api.frame; + +public class PaperUtils { + + private static boolean hasClass(String className) { + try { + Class.forName(className); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + + public static boolean isSpigot() { + return hasClass("org.spigotmc.SpigotConfig") && !hasClass("io.papermc.paper.configuration.Configuration") || !hasClass("com.destroystokyo.paper.PaperConfig"); + } + + public static boolean isPaper() { + return hasClass("io.papermc.paper.configuration.Configuration") || hasClass("com.destroystokyo.paper.PaperConfig"); + } + + public static boolean isFolia() { + return hasClass("io.papermc.paper.threadedregions.RegionizedServer"); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/adapters/LocationTypeAdapter.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/adapters/LocationTypeAdapter.java new file mode 100644 index 0000000..da9219f --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/adapters/LocationTypeAdapter.java @@ -0,0 +1,52 @@ +package com.badbones69.crazyauctions.api.frame.adapters; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import org.bukkit.Bukkit; +import org.bukkit.Location; + +import java.io.IOException; + +public class LocationTypeAdapter extends TypeAdapter { + + @Override + public void write(JsonWriter out, Location location) throws IOException { + out.beginObject(); + out.name("world").value(location.getWorld().getName()); + out.name("x").value(location.getX()); + out.name("y").value(location.getY()); + out.name("z").value(location.getZ()); + out.name("yaw").value(location.getYaw()); + out.name("pitch").value(location.getPitch()); + out.endObject(); + } + + @Override + public Location read(JsonReader reader) throws IOException { + reader.beginObject(); + + String worldName = null; + double x = 0, y = 0, z = 0; + float yaw = 0, pitch = 0; + + while (reader.hasNext()) { + String name = reader.nextName(); + + switch (name) { + case "world" -> worldName = reader.nextString(); + case "x" -> x = reader.nextDouble(); + case "y" -> y = reader.nextDouble(); + case "z" -> z = reader.nextDouble(); + case "yaw" -> yaw = (float) reader.nextDouble(); + case "pitch" -> pitch = (float) reader.nextDouble(); + default -> reader.skipValue(); + } + } + + reader.endObject(); + + assert worldName != null; + return new Location(Bukkit.getWorld(worldName), x, y, z, yaw, pitch); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandContext.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandContext.java new file mode 100644 index 0000000..a5dd49d --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandContext.java @@ -0,0 +1,268 @@ +package com.badbones69.crazyauctions.api.frame.command; + +import com.badbones69.crazyauctions.ApiManager; +import com.badbones69.crazyauctions.api.frame.command.builders.CommandActor; +import com.badbones69.crazyauctions.api.frame.command.builders.args.CommandArgs; +import com.badbones69.crazyauctions.config.types.Locale; +import com.badbones69.crazyauctions.frame.utils.AdventureUtils; +import com.badbones69.crazyauctions.support.PlaceholderSupport; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.permissions.Permission; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +public class CommandContext implements CommandActor, CommandArgs { + + private final Audience audience; + private final List args; + private String label; + + private Player player; + + public CommandContext(Audience audience, String label, List args) { + this.audience = audience; + + if (audience instanceof Player) { + this.player = (Player) audience; + } + + this.label = label; + this.args = args; + } + + @Override + public void reply(String message) { + if (message.isBlank() || message.isEmpty()) return; + + Component component = AdventureUtils.parse(message); + + this.audience.sendMessage(component); + } + + @Override + public void reply(boolean hasPrefix, String prefix, String message) { + if (message.isBlank() || message.isEmpty()) return; + + if (hasPrefix) { + Component component = AdventureUtils.parse(prefix).append(AdventureUtils.parse(prefix)); + + this.audience.sendMessage(component); + + return; + } + + Component component = AdventureUtils.parse(message); + + this.audience.sendMessage(component); + } + + @Override + public void reply(boolean hasPrefix, String prefix, Component component) { + if (hasPrefix) { + this.audience.sendMessage(AdventureUtils.parse(prefix).append(component)); + return; + } + + this.audience.sendMessage(component); + } + + @Override + public void reply(Component component) { + this.audience.sendMessage(component); + } + + @Override + public void send(Audience audience, String message) { + if (message.isBlank() || message.isEmpty()) return; + + Component component = AdventureUtils.parse(message); + + audience.sendMessage(component); + } + + @Override + public void send(Audience audience, Component component) { + audience.sendMessage(component); + } + + @Override + public void send(Audience audience, String message, String prefix, boolean hasPrefix) { + if (hasPrefix) { + audience.sendMessage(AdventureUtils.parse(prefix).append(AdventureUtils.parse(message))); + return; + } + + send(audience, message); + } + + @Override + public void send(Audience audience, Component message, String prefix, boolean hasPrefix) { + if (hasPrefix) { + audience.sendMessage(AdventureUtils.parse(prefix).append(message)); + return; + } + + send(audience, message); + } + + @Override + public Audience getSender() { + return this.audience; + } + + @Override + public boolean isPlayer() { + return getPlayer() != null; + } + + @Override + public Player getPlayer() { + return this.player; + } + + @Override + public boolean hasPermission(Permission permission) { + return this.player.hasPermission(permission); + } + + @Override + public boolean hasPermission(String rawPermission) { + return this.player.hasPermission(rawPermission); + } + + @Override + public void setLabel(String label) { + this.label = label; + } + + @Override + public String getLabel() { + return this.label; + } + + public List getArgs() { + return Collections.unmodifiableList(this.args); + } + + @Override + public void removeArgs(int arg) { + this.args.remove(arg); + } + + @Override + public int getArgAsInt(int index, boolean notifySender) { + Integer value = null; + + try { + value = Integer.parseInt(this.args.get(index)); + } catch (NumberFormatException exception) { + if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) + .replaceAll("\\{value}", this.args.get(index)) + .replaceAll("\\{action}", "number"))); + } + + if (value != null) return value; + + return 1; + } + + @Override + public long getArgAsLong(int index, boolean notifySender) { + Long value = null; + + try { + value = Long.parseLong(this.args.get(index)); + } catch (NumberFormatException exception) { + if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) + .replaceAll("\\{value}", this.args.get(index)) + .replaceAll("\\{action}", "number"))); + } + + if (value != null) return value; + + return 1L; + } + + @Override + public double getArgAsDouble(int index, boolean notifySender) { + Double value = null; + + try { + value = Double.parseDouble(this.args.get(index)); + } catch (NumberFormatException exception) { + if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) + .replaceAll("\\{value}", this.args.get(index)) + .replaceAll("\\{action}", "number"))); + } + + if (value != null) return value; + + return 0.1; + } + + @Override + public boolean getArgAsBoolean(int index, boolean notifySender) { + String lowercase = this.args.get(index).toLowerCase(); + + switch (lowercase) { + case "true", "on", "1" -> { + return true; + } + case "false", "off", "0" -> { + return false; + } + default -> { + if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) + .replaceAll("\\{value}", this.args.get(index).toLowerCase()) + .replaceAll("\\{action}", "boolean"))); + + return false; + } + } + } + + @Override + public float getArgAsFloat(int index, boolean notifySender) { + Float value = null; + + try { + value = Float.parseFloat(this.args.get(index)); + } catch (NumberFormatException exception) { + if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) + .replaceAll("\\{value}", this.args.get(index)) + .replaceAll("\\{action}", "number"))); + } + + if (value != null) return value; + + return 1F; + } + + @Override + public Player getArgAsPlayer(int index, boolean notifySender) { + Player player = Bukkit.getServer().getPlayer(this.args.get(index)); + + if (player == null) { + if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) + .replaceAll("\\{value}", this.args.get(index)) + .replaceAll("\\{action}", "player"))); + + return null; + } + + return player; + } + + @Override + public OfflinePlayer getArgAsOfflinePlayer(int index) { + CompletableFuture future = CompletableFuture.supplyAsync(() -> Bukkit.getServer().getOfflinePlayer(this.args.get(index))).thenApply(OfflinePlayer::getUniqueId); + + return Bukkit.getServer().getOfflinePlayer(future.join()); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandEngine.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandEngine.java new file mode 100644 index 0000000..b5a8fee --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandEngine.java @@ -0,0 +1,164 @@ +package com.badbones69.crazyauctions.api.frame.command; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.api.frame.command.builders.CommandDataEntry; +import com.badbones69.crazyauctions.api.frame.command.builders.args.Argument; +import com.badbones69.crazyauctions.frame.CrazyCore; +import com.badbones69.crazyauctions.frame.utils.AdventureUtils; +import com.badbones69.crazyauctions.support.PlaceholderSupport; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import java.util.*; + +public abstract class CommandEngine extends Command { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private final LinkedList labels = new LinkedList<>(); + public final LinkedList requiredArgs = new LinkedList<>(); + public final LinkedList optionalArgs = new LinkedList<>(); + + private final HashMap commandData = new HashMap<>(); + + protected CommandEngine(@NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List aliases) { + super(name, description, usageMessage, aliases); + } + + public void execute(CommandContext context, String[] args) { + perform(context, args); + } + + public void execute(CommandContext context) { + StringBuilder label = new StringBuilder(context.getLabel()); + + if (!context.getArgs().isEmpty()) { + for (CommandEngine engine : this.plugin.getCommandManager().getClasses()) { + boolean isPresent = context.getArgs().stream().findFirst().isPresent(); + + if (isPresent) { + label.append(" ").append(context.getArgs().get(0)); + + context.removeArgs(0); + context.setLabel(label.toString()); + + engine.execute(context); + return; + } + } + } + + if (!validate(context)) return; + + perform(context, new String[0]); + } + + @Override + public boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) { + List arguments = Arrays.asList(args); + + CommandContext context = new CommandContext( + sender, + label, + arguments + ); + + if (arguments.isEmpty()) { + execute(context); + return true; + } + + execute(context, args); + + return true; + } + + protected abstract void perform(CommandContext context, String[] args); + + private boolean validate(CommandContext context) { + if (context.getArgs().size() < this.requiredArgs.size()) { + context.reply(CrazyCore.api().commandTooFewArgs()); + sendValidFormat(context); + return false; + } + + if (context.getArgs().size() > this.requiredArgs.size() + this.optionalArgs.size()) { + context.reply(CrazyCore.api().commandTooManyArgs()); + sendValidFormat(context); + return false; + } + + return true; + } + + private void sendValidFormat(CommandContext context) { + ArrayList arguments = new ArrayList<>(); + + arguments.addAll(this.requiredArgs); + arguments.addAll(this.optionalArgs); + + this.requiredArgs.sort(Comparator.comparing(Argument::order)); + + if (context.isPlayer()) { + StringBuilder format = new StringBuilder("/" + "crazycrates:" + getLabel()); + + TextComponent.@NotNull Builder emptyComponent = Component.text(); + + StringBuilder types = new StringBuilder(); + + for (Argument arg : arguments) { + String value = this.optionalArgs.contains(arg) ? " (" + arg.name() + ") " : " <" + arg.name() + ">"; + + String msg = this.optionalArgs.contains(arg) ? CrazyCore.api().commandOptionalMsg() : CrazyCore.api().commandRequiredMsg(); + + Component argComponent = AdventureUtils.parse(value).hoverEvent(HoverEvent.showText(AdventureUtils.parse(PlaceholderSupport.setPlaceholders(msg)))).asComponent(); + + emptyComponent.append(argComponent); + + boolean isPresent = arg.argumentType().getPossibleValues().stream().findFirst().isPresent(); + + if (isPresent) types.append(" ").append(arg.argumentType().getPossibleValues().stream().findFirst().get()); + } + + TextComponent.@NotNull Builder finalComponent = emptyComponent + .hoverEvent(HoverEvent.showText(AdventureUtils.parse("Click me to insert into chat"))) + .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, format.append(types).toString())) + .append(emptyComponent.build()); + + context.reply(finalComponent.build()); + + return; + } + + StringBuilder format = new StringBuilder("/" + "crazycrates:" + getLabel()); + + for (Argument arg : arguments) { + String value = this.optionalArgs.contains(arg) ? "(" + arg.name() + ") " : "<" + arg.name() + "> "; + + format.append(value); + } + + context.reply(format.toString()); + } + + public List getLabels() { + return Collections.unmodifiableList(this.labels); + } + + public Map getCommandData() { + return Collections.unmodifiableMap(this.commandData); + } + + public List getRequiredArgs() { + return Collections.unmodifiableList(this.requiredArgs); + } + + public List getOptionalArgs() { + return Collections.unmodifiableList(this.optionalArgs); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandFlow.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandFlow.java new file mode 100644 index 0000000..d8f80cd --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandFlow.java @@ -0,0 +1,30 @@ +package com.badbones69.crazyauctions.api.frame.command; + +import com.badbones69.crazyauctions.api.frame.command.builders.CommandActor; +import com.badbones69.crazyauctions.api.frame.command.builders.CommandDataEntry; +import com.badbones69.crazyauctions.api.frame.command.builders.CommandHelpEntry; +import java.util.List; +import java.util.Map; + +public interface CommandFlow { + + void addCommand(CommandEngine engine); + + boolean hasCommand(String label); + + CommandHelpEntry generateCommandHelp(CommandActor actor); + + int defaultHelpPerPage(); + + void updateHelpPerPage(int newAmount); + + CommandDataEntry getCommand(String label); + + void removeCommand(String label); + + Map getCommands(); + + List getClasses(); + + List handleTabComplete(String[] args, CommandEngine engine); +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandManager.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandManager.java new file mode 100644 index 0000000..1618ac3 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandManager.java @@ -0,0 +1,123 @@ +package com.badbones69.crazyauctions.api.frame.command; + +import com.badbones69.crazyauctions.api.frame.command.builders.CommandActor; +import com.badbones69.crazyauctions.api.frame.command.builders.CommandDataEntry; +import com.badbones69.crazyauctions.api.frame.command.builders.CommandHelpEntry; +import com.badbones69.crazyauctions.api.frame.command.builders.annotations.Hidden; +import com.badbones69.crazyauctions.api.frame.command.builders.args.Argument; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import java.util.*; + +public class CommandManager implements CommandFlow { + + private final HashMap commands = new HashMap<>(); + + private final LinkedList classes = new LinkedList<>(); + + private int defaultHelpPerPage = 10; + + public static CommandManager create() { + return new CommandManager(); + } + + @Override + public void addCommand(CommandEngine engine) { + // If the label already exists. We return! + if (hasCommand(engine.getLabel())) return; + + // Create data entry. + CommandDataEntry entry = new CommandDataEntry(); + + // Set visibility if annotation is present. + entry.setHidden(engine.getClass().isAnnotationPresent(Hidden.class)); + + if (entry.isHidden()) return; + + // Add to the hash-map & linked list! + this.commands.put(engine.getLabel(), entry); + this.classes.add(engine); + + // Add command to the server map! + Bukkit.getServer().getCommandMap().register("crazycrates", engine); + } + + @Override + public boolean hasCommand(String label) { + return this.commands.containsKey(label); + } + + @Override + public CommandHelpEntry generateCommandHelp(CommandActor actor) { + return new CommandHelpEntry(this, actor); + } + + @Override + public int defaultHelpPerPage() { + return this.defaultHelpPerPage; + } + + @Override + public void updateHelpPerPage(int newAmount) { + this.defaultHelpPerPage = newAmount; + } + + @Override + public CommandDataEntry getCommand(String label) { + if (hasCommand(label)) return this.commands.get(label); + + return null; + } + + @Override + public void removeCommand(String label) { + if (!hasCommand(label)) return; + + Command value = Bukkit.getServer().getCommandMap().getCommand(label); + + if (value != null && value.isRegistered()) value.unregister(Bukkit.getServer().getCommandMap()); + + this.commands.remove(label); + } + + @Override + public Map getCommands() { + return Collections.unmodifiableMap(this.commands); + } + + @Override + public List getClasses() { + return Collections.unmodifiableList(this.classes); + } + + @Override + public List handleTabComplete(String[] args, CommandEngine engine) { + List completions = Arrays.asList(args); + + if (completions.size() >= 1) { + int relativeIndex = this.classes.size(); + int argToComplete = completions.size() + 1 - relativeIndex; + if (engine.requiredArgs.size() >= argToComplete) { + ArrayList arguments = new ArrayList<>(); + + arguments.addAll(engine.requiredArgs); + arguments.addAll(engine.optionalArgs); + + ArrayList possibleValues = new ArrayList<>(); + + for (Argument argument : arguments) { + if (argument.order() == argToComplete) { + List possibleValuesArgs = argument.argumentType().getPossibleValues(); + + possibleValues = new ArrayList<>(possibleValuesArgs); + break; + } + } + + return possibleValues; + } + } + + return Collections.emptyList(); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandActor.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandActor.java new file mode 100644 index 0000000..2b88bab --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandActor.java @@ -0,0 +1,48 @@ +package com.badbones69.crazyauctions.api.frame.command.builders; + +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; +import org.bukkit.entity.Player; +import org.bukkit.permissions.Permission; + +import java.util.List; + +public interface CommandActor { + + void reply(String message); + + void reply(boolean hasPrefix, String prefix, String message); + + void reply(boolean hasPrefix, String prefix, Component component); + + void reply(Component component); + + void send(Audience audience, String message); + + void send(Audience audience, Component component); + + void send(Audience audience, String message, String prefix, boolean hasPrefix); + + void send(Audience audience, Component message, String prefix, boolean hasPrefix); + + Audience getSender(); + + boolean isPlayer(); + + Player getPlayer(); + + boolean hasPermission(Permission permission); + + boolean hasPermission(String rawPermission); + + void setLabel(String alias); + + String getLabel(); + + List getArgs(); + + void removeArgs(int arg); + + //CommandHelpEntry getHelpEntry(); + +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandDataEntry.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandDataEntry.java new file mode 100644 index 0000000..1d9d28c --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandDataEntry.java @@ -0,0 +1,14 @@ +package com.badbones69.crazyauctions.api.frame.command.builders; + +public class CommandDataEntry { + + private boolean isHidden = false; + + public void setHidden(boolean value) { + this.isHidden = value; + } + + public boolean isHidden() { + return this.isHidden; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandHelpEntry.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandHelpEntry.java new file mode 100644 index 0000000..8a33077 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandHelpEntry.java @@ -0,0 +1,156 @@ +package com.badbones69.crazyauctions.api.frame.command.builders; + +import com.badbones69.crazyauctions.ApiManager; +import com.badbones69.crazyauctions.api.frame.command.CommandEngine; +import com.badbones69.crazyauctions.api.frame.command.CommandManager; +import com.badbones69.crazyauctions.api.frame.command.builders.args.Argument; +import com.badbones69.crazyauctions.api.frame.command.builders.other.ComponentBuilder; +import com.badbones69.crazyauctions.config.types.PluginConfig; +import com.badbones69.crazyauctions.frame.CrazyCore; +import com.badbones69.crazyauctions.support.PlaceholderSupport; +import net.kyori.adventure.text.event.ClickEvent; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Map; +import static com.badbones69.crazyauctions.frame.utils.AdventureUtils.hover; +import static com.badbones69.crazyauctions.frame.utils.AdventureUtils.send; + +public class CommandHelpEntry { + + private final CommandManager manager; + private final CommandActor actor; + + private int page = 1; + private int perPage; + private int totalPages; + private int totalResults; + private boolean lastPage; + + public CommandHelpEntry(CommandManager manager, CommandActor actor) { + this.manager = manager; + this.actor = actor; + + this.perPage = manager.defaultHelpPerPage(); + } + + public void showHelp() { + this.showHelp(this.actor); + } + + public void showHelp(CommandActor actor) { + int min = this.perPage * (this.page - 1); + int max = min + this.perPage; + + this.totalResults = this.manager.getCommands().size(); + + this.totalPages = this.totalResults / this.perPage; + + if (min >= this.totalResults) { + actor.reply(ApiManager.getPluginConfig().getProperty(PluginConfig.INVALID_HELP_PAGE).replaceAll("\\{page}", String.valueOf(page))); + return; + } + + Map entries = this.manager.getCommands(); + + for (int value = min; value < max; value++) { + if (this.totalResults - 1 < value) continue; + + CommandEngine command = this.manager.getClasses().get(value); + + CommandDataEntry dataEntry = entries.get(command.getLabel()); + + boolean isHidden = dataEntry.isHidden(); + + StringBuilder baseFormat = new StringBuilder("/" + command.getLabel()); + + String format = CrazyCore.api().commandPageFormat() + .replaceAll("\\{command}", baseFormat.toString()) + .replaceAll("\\{description}", command.getDescription()); + + // Only add aliases if the list isn't empty. + if (!command.getAliases().isEmpty()) baseFormat.append(" ").append(command.getLabels().get(0)); + + ArrayList arguments = new ArrayList<>(); + + arguments.addAll(command.getOptionalArgs()); + arguments.addAll(command.getRequiredArgs()); + + arguments.sort(Comparator.comparingInt(Argument::order)); + + if (actor.isPlayer()) { + StringBuilder types = new StringBuilder(); + + ComponentBuilder builder = new ComponentBuilder(); + + for (Argument arg : arguments) { + String argValue = command.optionalArgs.contains(arg) ? " (" + arg.name() + ") " : " <" + arg.name() + ">"; + + types.append(argValue); + } + + builder.setMessage(format.replaceAll("\\{args}", String.valueOf(types))); + + String hoverShit = baseFormat.append(types).toString(); + + String hoverFormat = CrazyCore.api().commandHoverFormat(); + + builder.hover(PlaceholderSupport.setPlaceholders(hoverFormat).replaceAll("\\{commands}", hoverShit)).click(hoverShit, ClickEvent.Action.valueOf(CrazyCore.api().commandHoverAction().toUpperCase())); + + actor.reply(builder.build()); + } + + String footer = CrazyCore.api().commandHelpFooter(); + + if (actor.isPlayer()) { + String text = CrazyCore.api().commandNavigationText(); + + if (page > 1) { + int number = page-1; + + hover(actor.getPlayer(), footer.replaceAll("\\{page}", String.valueOf(page)), text.replaceAll("\\{page}", String.valueOf(number)), CrazyCore.api().commandNavigationBackButton(), "/crazycrates help " + number, ClickEvent.Action.RUN_COMMAND); + } else if (page < this.manager.getClasses().size()) { + int number = page+1; + + hover(actor.getPlayer(), footer.replaceAll("\\{page}", String.valueOf(page)), text.replaceAll("\\{page}", String.valueOf(number)), CrazyCore.api().commandNavigationNextButton(), "/crazycrates help " + number, ClickEvent.Action.RUN_COMMAND); + } + } else { + send(actor.getSender(), footer.replaceAll("\\{page}", String.valueOf(page)), false, ""); + } + } + + this.lastPage = max >= this.totalResults; + } + + public void setPage(int page) { + this.page = page; + } + + public void setPerPage(int perPage) { + this.perPage = perPage; + } + + public void setPage(int page, int perPage) { + this.setPage(page); + this.setPerPage(perPage); + } + + public int getPage() { + return this.page; + } + + public int getPerPage() { + return this.perPage; + } + + public int getTotalResults() { + return this.totalResults; + } + + public int getTotalPages() { + return this.totalPages; + } + + public boolean isLastPage() { + return this.lastPage; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/annotations/Hidden.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/annotations/Hidden.java new file mode 100644 index 0000000..10fe620 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/annotations/Hidden.java @@ -0,0 +1,7 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.annotations; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Hidden {} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/Argument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/Argument.java new file mode 100644 index 0000000..b8e8dd3 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/Argument.java @@ -0,0 +1,3 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.args; + +public record Argument(String name, int order, ArgumentType argumentType) {} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/ArgumentType.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/ArgumentType.java new file mode 100644 index 0000000..3de171b --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/ArgumentType.java @@ -0,0 +1,9 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.args; + +import java.util.List; + +public abstract class ArgumentType { + + public abstract List getPossibleValues(); + +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/CommandArgs.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/CommandArgs.java new file mode 100644 index 0000000..b769c88 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/CommandArgs.java @@ -0,0 +1,22 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.args; + +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +public interface CommandArgs { + + int getArgAsInt(int index, boolean notifySender); + + long getArgAsLong(int index, boolean notifySender); + + double getArgAsDouble(int index, boolean notifySender); + + boolean getArgAsBoolean(int index, boolean notifySender); + + float getArgAsFloat(int index, boolean notifySender); + + Player getArgAsPlayer(int index, boolean notifySender); + + OfflinePlayer getArgAsOfflinePlayer(int index); + +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/BooleanArgument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/BooleanArgument.java new file mode 100644 index 0000000..7311812 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/BooleanArgument.java @@ -0,0 +1,12 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.args.builder; + +import com.badbones69.crazyauctions.api.frame.command.builders.args.ArgumentType; +import java.util.List; + +public class BooleanArgument extends ArgumentType { + + @Override + public List getPossibleValues() { + return List.of("true", "false"); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/DoubleArgument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/DoubleArgument.java new file mode 100644 index 0000000..dbc4007 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/DoubleArgument.java @@ -0,0 +1,34 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.args.builder; + +import com.badbones69.crazyauctions.api.frame.command.builders.args.ArgumentType; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; + +public class DoubleArgument extends ArgumentType { + + private final int numberCap; + + public DoubleArgument(Integer numberCap) { + if (numberCap == null) { + this.numberCap = 100; + return; + } + + this.numberCap = numberCap; + } + + @Override + public List getPossibleValues() { + List numbers = new ArrayList<>(); + + DecimalFormat decimalFormat = new DecimalFormat("0.0"); + + for (double value = 0.1; value <= this.numberCap; value += 0.1) { + String formattedNumber = decimalFormat.format(value); + numbers.add(formattedNumber); + } + + return numbers; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/FloatArgument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/FloatArgument.java new file mode 100644 index 0000000..751a92e --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/FloatArgument.java @@ -0,0 +1,34 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.args.builder; + +import com.badbones69.crazyauctions.api.frame.command.builders.args.ArgumentType; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; + +public class FloatArgument extends ArgumentType { + + private final int numberCap; + + public FloatArgument(Integer numberCap) { + if (numberCap == null) { + this.numberCap = 100; + return; + } + + this.numberCap = numberCap; + } + + @Override + public List getPossibleValues() { + List numbers = new ArrayList<>(); + + DecimalFormat decimalFormat = new DecimalFormat("0.0f"); + + for (float value = 0.1f; value <= this.numberCap; value += 0.1f) { + String formattedValue = decimalFormat.format(value); + numbers.add(formattedValue); + } + + return numbers; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/IntArgument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/IntArgument.java new file mode 100644 index 0000000..be72dc9 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/IntArgument.java @@ -0,0 +1,28 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.args.builder; + +import com.badbones69.crazyauctions.api.frame.command.builders.args.ArgumentType; +import java.util.ArrayList; +import java.util.List; + +public class IntArgument extends ArgumentType { + + private final int numberCap; + + public IntArgument(Integer numberCap) { + if (numberCap == null) { + this.numberCap = 100; + return; + } + + this.numberCap = numberCap; + } + + @Override + public List getPossibleValues() { + List numbers = new ArrayList<>(); + + for (int value = 1; value <= this.numberCap; value += 1) numbers.add(String.valueOf(value)); + + return numbers; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/custom/PlayerArgument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/custom/PlayerArgument.java new file mode 100644 index 0000000..418a102 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/custom/PlayerArgument.java @@ -0,0 +1,15 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.args.builder.custom; + +import com.badbones69.crazyauctions.api.frame.command.builders.args.ArgumentType; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import java.util.List; +import java.util.stream.Collectors; + +public class PlayerArgument extends ArgumentType { + + @Override + public List getPossibleValues() { + return Bukkit.getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/other/ComponentBuilder.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/other/ComponentBuilder.java new file mode 100644 index 0000000..8de7164 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/other/ComponentBuilder.java @@ -0,0 +1,94 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.other; + +import com.badbones69.crazyauctions.frame.utils.AdventureUtils; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import org.jetbrains.annotations.NotNull; + +public class ComponentBuilder { + + private String message; + + private final TextComponent.@NotNull Builder builder = Component.text(); + + private final PreciseComponentBuilder preciseBuilder; + + public ComponentBuilder() { + this.preciseBuilder = new PreciseComponentBuilder(); + } + + public void setMessage(String message) { + this.message = message; + } + + public ComponentBuilder append(Component component) { + this.builder.append(component); + + return this; + } + + public Component parse(String value) { + return AdventureUtils.parse(value); + } + + public ComponentBuilder hover(String hoverText) { + this.builder.hoverEvent(HoverEvent.showText(parse(hoverText))); + + return this; + } + + public ComponentBuilder click(String clickText, ClickEvent.Action action) { + this.builder.clickEvent(ClickEvent.clickEvent(action, clickText)); + + return this; + } + + public class PreciseComponentBuilder { + private final TextComponent.@NotNull Builder preciseBuilder = Component.text(); + + public PreciseComponentBuilder text(String text) { + this.preciseBuilder.append(parse(text)); + + return this; + } + + public PreciseComponentBuilder hoverText(String text, String hoverText) { + this.preciseBuilder.append(parse(text)); + this.preciseBuilder.hoverEvent(HoverEvent.showText(parse(hoverText))); + + return this; + } + + public PreciseComponentBuilder hoverText(String hoverText) { + this.preciseBuilder.hoverEvent(HoverEvent.showText(parse(hoverText))); + + return this; + } + + public PreciseComponentBuilder click(String clickText, ClickEvent.Action action) { + this.preciseBuilder.clickEvent(ClickEvent.clickEvent(action, clickText)); + + return this; + } + + public @NotNull TextComponent getPreciseBuilder() { + return this.preciseBuilder.build(); + } + } + + public PreciseComponentBuilder getPreciseComponent() { + return this.preciseBuilder; + } + + public @NotNull TextComponent build() { + Component message = AdventureUtils.parse(this.message); + + if (getPreciseComponent() != null) { + return this.builder.append(message).append(getPreciseComponent().getPreciseBuilder()).build(); + } + + return this.builder.append(message).build(); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirements.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirements.java new file mode 100644 index 0000000..209154c --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirements.java @@ -0,0 +1,57 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.reqs; + +import com.badbones69.crazyauctions.api.frame.command.CommandContext; +import com.badbones69.crazyauctions.frame.CrazyCore; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.permissions.Permission; + +public class CommandRequirements { + + private final boolean asPlayer; + private Permission permission; + private String rawPermission; + + public CommandRequirements(boolean asPlayer, Permission permission, String rawPermission) { + this.asPlayer = asPlayer; + + if (permission != null) this.permission = permission; + + if (!rawPermission.isEmpty() || !rawPermission.isBlank()) this.rawPermission = rawPermission; + } + + public boolean checkRequirements(boolean notifySender, CommandContext context) { + if (asPlayer && !context.isPlayer()) { + if (notifySender) context.reply(CrazyCore.api().commandRequirementNotPlayer()); + + // The command is not valid. + return false; + } + + // The sender is console sender so automatically valid. + if (context.getSender() instanceof ConsoleCommandSender) return true; + + if (this.permission != null && !context.hasPermission(this.permission) || this.rawPermission != null && !context.hasPermission(this.rawPermission)) { + String value = this.permission != null ? this.permission.getName() : this.rawPermission; + + if (notifySender) context.reply(CrazyCore.api().commandRequirementNoPermission().replaceAll("\\{permission}", value)); + + // The command is not valid. + return false; + } + + // The command is valid. + return true; + } + + public Permission getPermission() { + return this.permission; + } + + public String getRawPermission() { + return this.rawPermission; + } + + public boolean isPlayer() { + return this.asPlayer; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirementsBuilder.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirementsBuilder.java new file mode 100644 index 0000000..7e76844 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirementsBuilder.java @@ -0,0 +1,33 @@ +package com.badbones69.crazyauctions.api.frame.command.builders.reqs; + +import org.bukkit.permissions.Permission; + +public class CommandRequirementsBuilder { + + private boolean asPlayer = false; + private Permission permission = null; + private String rawPermission = ""; + + public CommandRequirementsBuilder asPlayer(boolean value) { + this.asPlayer = value; + return this; + } + + public CommandRequirementsBuilder withPermission(Permission permission) { + this.permission = permission; + return this; + } + + public CommandRequirementsBuilder withOutPermission(Permission permission) { + return this; + } + + public CommandRequirementsBuilder withRawPermission(String rawPermission) { + this.rawPermission = rawPermission; + return this; + } + + public CommandRequirements build() { + return new CommandRequirements(asPlayer, permission, rawPermission); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/BaseItemBuilder.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/BaseItemBuilder.java new file mode 100644 index 0000000..5b4956c --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/BaseItemBuilder.java @@ -0,0 +1,673 @@ +package com.badbones69.crazyauctions.api.frame.items; + +import com.badbones69.crazyauctions.api.frame.ItemUtils; +import com.badbones69.crazyauctions.frame.CrazyLogger; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextDecoration; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.DyeColor; +import org.bukkit.FireworkEffect; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.block.Banner; +import org.bukkit.block.banner.Pattern; +import org.bukkit.block.banner.PatternType; +import org.bukkit.enchantments.Enchantment; +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.FireworkEffectMeta; +import org.bukkit.inventory.meta.FireworkMeta; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.inventory.meta.trim.ArmorTrim; +import org.bukkit.inventory.meta.trim.TrimMaterial; +import org.bukkit.inventory.meta.trim.TrimPattern; +import org.bukkit.potion.PotionData; +import org.bukkit.potion.PotionType; +import org.bukkit.util.Consumer; +import java.lang.reflect.Field; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import java.util.stream.Collectors; + +public class BaseItemBuilder> { + + private final ItemUtils SKULL_CHECKER = new ItemUtils(); + + private final GsonComponentSerializer gson = GsonComponentSerializer.gson(); + + // Core. + private ItemStack itemStack; + private ItemMeta itemMeta; + + private Material material; + + // Custom Lore. + private Field LORE_FIELD; + + // Custom Model Data. + private boolean isCustomModelData; + + private int customModelData; + + // Custom Heads. + private boolean isHead; + private Field profile; + private String texture; + + // Potions + private boolean isPotion; + private boolean isTippedArrow; + private Color potionColor; + private PotionType potionType; + + // Leather. + private boolean isLeather; + private boolean isArmor; + private TrimMaterial trimMaterial; + private TrimPattern trimPattern; + private Color armorColor; + + // Banners. + private boolean isBanner; + private List patterns; + + // Shields. + private boolean isShield; + + // Firework. + private boolean isFirework; + private boolean isFireworkStar; + + // Enchantments/Flags + private boolean isDurable; + private boolean hideFlags; + private boolean isGlowing; + + protected BaseItemBuilder() { + this.itemStack = null; + this.itemMeta = null; + this.material = Material.AIR; + this.LORE_FIELD = null; + this.isCustomModelData = false; + this.customModelData = 0; + this.isHead = false; + this.profile = null; + this.texture = ""; + this.isPotion = false; + this.isTippedArrow = false; + this.potionColor = Color.WHITE; + this.potionType = PotionType.MUNDANE; + this.isLeather = false; + this.armorColor = Color.WHITE; + this.isBanner = false; + this.patterns = Collections.emptyList(); + this.isShield = false; + this.isFirework = false; + this.isFireworkStar = false; + this.isDurable = false; + this.hideFlags = false; + this.isGlowing = false; + } + + protected BaseItemBuilder(ItemStack itemStack) { + this.itemStack = itemStack; + + try { + Class metaClass = SKULL_CHECKER.craftClass("inventory.CraftMetaItem"); + + LORE_FIELD = metaClass.getDeclaredField("lore"); + LORE_FIELD.setAccessible(true); + } catch (NoSuchFieldException | ClassNotFoundException exception) { + CrazyLogger.warn("Failed to make the lore field accessible as it was not found. Perhaps an invalid item was supplied?"); + } + + this.material = itemStack.getType(); + + switch (this.material) { + case PLAYER_HEAD -> this.isHead = true; + case POTION, SPLASH_POTION -> this.isPotion = true; + case TIPPED_ARROW -> this.isTippedArrow = true; + case LEATHER_HELMET, LEATHER_CHESTPLATE, LEATHER_LEGGINGS, LEATHER_BOOTS, LEATHER_HORSE_ARMOR -> this.isLeather = true; + case SHIELD -> this.isShield = true; + case FIREWORK_ROCKET -> this.isFirework = true; + case FIREWORK_STAR -> this.isFireworkStar = true; + } + + String name = this.material.name(); + + this.isArmor = name.endsWith("_HELMET") || name.endsWith("_CHESTPLATE") || name.endsWith("_LEGGINGS") || name.endsWith("_BOOTS"); + + // Accounts for all banners. + if (this.material.name().contains("BANNER")) this.isBanner = true; + + // if (this.material.name().contains("SPAWN_EGG")) this.isEgg = true; + + this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta() : Bukkit.getServer().getItemFactory().getItemMeta(material); + } + + public Base setDisplayName(Component displayName) { + this.itemMeta.displayName(displayName.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE)); + return (Base) this; + } + + public Base setLore(Component ... lore) { + return setLore(Arrays.asList(lore)); + } + + public Base setLore(List lore) { + List jsonLore = lore.stream().filter(Objects::nonNull).map(this.gson::serialize).toList(); + + try { + LORE_FIELD.set(this.itemMeta, jsonLore); + } catch (IllegalAccessException exception) { + exception.printStackTrace(); + } + + return (Base) this; + } + + public Base addLore(Consumer> lore) { + List components; + + try { + List jsonLore = (List) LORE_FIELD.get(this.itemMeta); + + components = (jsonLore == null) ? new ArrayList<>() : jsonLore.stream().map(this.gson::deserialize).collect(Collectors.toList()); + } catch (Exception exception) { + components = new ArrayList<>(); + exception.printStackTrace(); + } + + lore.accept(components); + return (Base) this; + } + + public Base setAmount(int amount) { + this.itemStack.setAmount(amount); + return (Base) this; + } + + public Base addEnchantment(Enchantment enchantment, int level, boolean ignoreLevelRestriction) { + this.itemMeta.addEnchant(enchantment, level, ignoreLevelRestriction); + return (Base) this; + } + + public Base removeEnchantment(Enchantment enchantment) { + this.itemMeta.removeEnchant(enchantment); + return (Base) this; + } + + public Base setEnchantments(HashMap enchantments, boolean ignoreLevelRestriction) { + enchantments.forEach((enchantment, integer) -> this.itemMeta.addEnchant(enchantment, integer, ignoreLevelRestriction)); + return (Base) this; + } + + public Base addPatterns(List patterns) { + patterns.forEach(this::addPatterns); + return (Base) this; + } + + public Base addPattern(Pattern pattern) { + this.patterns.add(pattern); + return (Base) this; + } + + public Base setPattern(List patterns) { + this.patterns = patterns; + return (Base) this; + } + + public Base addItemFlags(List flags) { + flags.forEach(flag -> { + try { + ItemFlag itemFlag = ItemFlag.valueOf(flag.toUpperCase()); + + addItemFlag(itemFlag); + } catch (Exception exception) { + CrazyLogger.warn("Failed to add item flag: " + flag + ". The flag is invalid!"); + } + }); + + return (Base) this; + } + + public Base setTexture(String texture) { + this.texture = texture; + + return (Base) this; + } + + public Base setValue(String material) { + if (material == null || material.isEmpty()) { + CrazyLogger.warn("Material cannot be null or empty, Output: " + material + "."); + CrazyLogger.warn("Please take a screenshot of this before asking for support."); + + return (Base) this; + } + + String metaData; + + if (isPotion || isTippedArrow) { + if (material.contains(";")) { + String[] section = material.split(";"); + + String[] sectionOne = section[0].split(":"); + String[] sectionTwo = section[1].split(":"); + + try { + this.potionType = PotionType.valueOf(sectionOne[1]); + } catch (Exception exception) { + CrazyLogger.warn("Failed to set potion type " + sectionOne[1] + ". The potion type inputted is invalid."); + } + + this.potionColor = getColor(sectionTwo[1]); + } + + return (Base) this; + } + + if (material.contains(":")) { // Sets the durability or another value option. + String[] materialSplit = material.split(":"); + + material = materialSplit[0]; + metaData = materialSplit[1]; + + if (metaData.contains("#")) { // :# + String modelData = metaData.split("#")[1]; + + if (isValidInteger(modelData)) { + this.isCustomModelData = true; + this.customModelData = Integer.parseInt(modelData); + } + } + + metaData = metaData.replace("#" + customModelData, ""); + + if (isValidInteger(metaData)) { // Value is durability. + int damage = Integer.parseInt(metaData); + + if (this.itemMeta instanceof Damageable) ((Damageable) this.itemMeta).setDamage(damage); + } else { // Value is something else. + if (isPotion) { + this.potionType = PotionType.valueOf(metaData); + + if (getColor(metaData) != null) this.potionColor = getColor(metaData); + } + + if (isLeather) this.armorColor = getColor(metaData); + } + } else if (material.contains("#")) { + String[] materialSplit = material.split("#"); + material = materialSplit[0]; + + if (isValidInteger(materialSplit[1])) { // Value is a number. + this.isCustomModelData = true; + this.customModelData = Integer.parseInt(materialSplit[1]); + } + } + + Material matchedMaterial = Material.matchMaterial(material); + + if (matchedMaterial != null) this.material = matchedMaterial; + + if (this.isArmor) ((ArmorMeta) itemMeta).setTrim(new ArmorTrim(this.trimMaterial, this.trimPattern)); + + this.itemStack.setType(this.material); + + setItemMeta(this.itemStack.getItemMeta()); + + return (Base) this; + } + + public Base hideFlags(boolean hideFlags) { + this.hideFlags = hideFlags; + return (Base) this; + } + + public Base setGlow(boolean isGlowing) { + this.isGlowing = isGlowing; + return (Base) this; + } + + public Base setTrim(TrimMaterial trimMaterial, TrimPattern trimPattern) { + this.trimMaterial = trimMaterial; + this.trimPattern = trimPattern; + + return (Base) this; + } + + public Base setDurable(boolean isDurable) { + this.isDurable = isDurable; + return (Base) this; + } + + public Base setEffect(FireworkEffect... effects) { + return setEffect(Arrays.asList(effects)); + } + + public Base setEffect(List effects) { + if (effects.isEmpty()) return (Base) this; + + if (this.isFireworkStar) { + FireworkEffectMeta effectMeta = (FireworkEffectMeta) this.getItemMeta(); + + effectMeta.setEffect(effects.get(0)); + this.setItemMeta(effectMeta); + } + + if (this.isFirework) { + FireworkMeta fireworkMeta = (FireworkMeta) this.getItemMeta(); + + fireworkMeta.addEffects(effects); + this.setItemMeta(fireworkMeta); + } + + return (Base) this; + } + + public Base setPower(int power) { + if (this.isFirework) { + FireworkMeta fireworkMeta = (FireworkMeta) this.getItemMeta(); + + fireworkMeta.setPower(power); + + this.setItemMeta(fireworkMeta); + } + + return (Base) this; + } + + public ItemStack build() { + if (this.material != Material.AIR) { + if (this.isHead) { + // Set the field to accessible. + exposeField(); + + setPlayerTexture(this.texture); + } + + if (this.isPotion || this.isTippedArrow && (this.potionType != null || this.potionColor != null)) { + PotionMeta potionMeta = (PotionMeta) this.itemMeta; + + if (this.potionType != null) potionMeta.setBasePotionData(new PotionData(this.potionType)); + + if (this.potionColor != null) potionMeta.setColor(this.potionColor); + + this.setItemMeta(potionMeta); + } + + if (this.isLeather && this.armorColor != null) { + LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) this.itemMeta; + leatherArmorMeta.setColor(this.armorColor); + } + + if (this.isBanner && !this.patterns.isEmpty()) { + BannerMeta bannerMeta = (BannerMeta) this.itemMeta; + bannerMeta.setPatterns(this.patterns); + } + + if (this.isShield && !this.patterns.isEmpty()) { + BlockStateMeta shieldMeta = (BlockStateMeta) this.itemMeta; + Banner banner = (Banner) shieldMeta.getBlockState(); + + banner.setPatterns(this.patterns); + banner.update(); + + shieldMeta.setBlockState(banner); + } + + if (this.isCustomModelData) this.itemMeta.setCustomModelData(this.customModelData); + + if (this.hideFlags) this.itemMeta.addItemFlags(ItemFlag.values()); + + this.itemMeta.setUnbreakable(this.isDurable); + + this.addGlow(); + } else { + CrazyLogger.warn("Material cannot be AIR."); + } + + this.itemStack.setItemMeta(this.itemMeta); + + return this.itemStack; + } + + private void addItemFlag(ItemFlag itemFlag) { + this.itemMeta.addItemFlags(itemFlag); + } + + private void setPlayerTexture(String texture) { + this.texture = texture; + + Player player = Bukkit.getServer().getPlayer(this.texture); + + if (player != null) { + setOwner(player); + return; + } + + if (this.texture.startsWith("http")) { + setTexture(convert(this.texture), UUID.randomUUID()); + return; + } + + setTexture(this.texture, UUID.randomUUID()); + } + + private void setOwner(OfflinePlayer player) { + if (this.SKULL_CHECKER.isPlayerSkull(this.material)) return; + + SkullMeta skullMeta = (SkullMeta) this.getItemMeta(); + + skullMeta.setOwningPlayer(player); + + this.setItemMeta(skullMeta); + } + + private void addGlow() { + if (this.isGlowing) { + if (this.itemMeta.hasEnchants()) return; + + this.itemMeta.addEnchant(Enchantment.LUCK, 1, false); + + this.setItemMeta(this.itemMeta); + } + } + + private void exposeField() { + if (this.SKULL_CHECKER.isPlayerSkull(this.material)) return; + + Field field; + + try { + SkullMeta skullMeta = (SkullMeta) this.SKULL_CHECKER.skull().getItemMeta(); + field = skullMeta.getClass().getDeclaredField("profile"); + + field.setAccessible(true); + } catch (NoSuchFieldException exception) { + CrazyLogger.warn("Failed to make the meta field for profile accessible as it was not found. Perhaps an invalid item meta or field supplied?"); + + field = null; + } + + this.profile = field; + } + + private boolean isValidInteger(String value) { + try { + Integer.parseInt(value); + } catch (NumberFormatException exception) { + return false; + } + + return true; + } + + private Color getColor(String color) { + if (color != null) { + switch (color.toUpperCase()) { + case "AQUA" -> { + return Color.AQUA; + } + case "BLACK" -> { + return Color.BLACK; + } + case "BLUE" -> { + return Color.BLUE; + } + case "FUCHSIA" -> { + return Color.FUCHSIA; + } + case "GRAY" -> { + return Color.GRAY; + } + case "GREEN" -> { + return Color.GREEN; + } + case "LIME" -> { + return Color.LIME; + } + case "MAROON" -> { + return Color.MAROON; + } + case "NAVY" -> { + return Color.NAVY; + } + case "OLIVE" -> { + return Color.OLIVE; + } + case "ORANGE" -> { + return Color.ORANGE; + } + case "PURPLE" -> { + return Color.PURPLE; + } + case "RED" -> { + return Color.RED; + } + case "SILVER" -> { + return Color.SILVER; + } + case "TEAL" -> { + return Color.TEAL; + } + case "WHITE" -> { + return Color.WHITE; + } + case "YELLOW" -> { + return Color.YELLOW; + } + } + + try { + String[] rgb = color.split(","); + return Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2])); + } catch (Exception ignore) {} + } + + return null; + } + + 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 = getDyeColor(split[1]); + + if (color != null) this.addPattern(new Pattern(color, pattern)); + + break; + } + } + } catch (Exception ignored) {} + } + + public DyeColor getDyeColor(String color) { + if (color != null) { + try { + return DyeColor.valueOf(color.toUpperCase()); + } catch (Exception exception) { + try { + String[] rgb = color.split(","); + return DyeColor.getByColor(Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]))); + } catch (Exception ignore) {} + } + } + + return null; + } + + private void setTexture(String texture, UUID uuid) { + if (this.SKULL_CHECKER.isPlayerSkull(this.material)) return; + + if (this.profile == null) return; + + SkullMeta skullMeta = (SkullMeta) this.itemMeta; + GameProfile gameProfile = new GameProfile(uuid, null); + + gameProfile.getProperties().put("textures", new Property("textures", texture)); + + try { + this.profile.set(skullMeta, gameProfile); + } catch (Exception exception) { + CrazyLogger.warn("Failed to set the meta & game profile. Perhaps an invalid texture?"); + CrazyLogger.warn("Your Input: " + texture + "."); + } + + setItemMeta(skullMeta); + } + + private String convert(String url) { + URL actualLink; + + try { + actualLink = new URL(url); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + + String encode = "{\"textures\":{\"SKIN\":{\"url\":\"" + actualLink + "\"}}}"; + + return Base64.getEncoder().encodeToString(encode.getBytes()); + } + + // Protected getters for extended builders. + protected ItemStack getItemStack() { + return this.itemStack; + } + + protected void setItemStack(ItemStack itemStack) { + this.itemStack = itemStack; + } + + protected ItemMeta getItemMeta() { + return this.itemMeta; + } + + protected void setItemMeta(ItemMeta itemMeta) { + this.itemMeta = itemMeta; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemBuilder.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemBuilder.java new file mode 100644 index 0000000..4c6d422 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemBuilder.java @@ -0,0 +1,23 @@ +package com.badbones69.crazyauctions.api.frame.items; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +public class ItemBuilder extends BaseItemBuilder { + + public ItemBuilder() { + super(); + } + + public ItemBuilder(ItemStack itemStack) { + super(itemStack); + } + + public static ItemBuilder setStack(ItemStack itemStack) { + return new ItemBuilder(itemStack); + } + + public static ItemBuilder setMaterial(Material material) { + return new ItemBuilder(new ItemStack(material)); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemNbt.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemNbt.java new file mode 100644 index 0000000..f4ce10f --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemNbt.java @@ -0,0 +1,57 @@ +package com.badbones69.crazyauctions.api.frame.items; + +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.java.JavaPlugin; + +public class ItemNbt { + + private final JavaPlugin plugin; + + public ItemNbt(JavaPlugin plugin) { + this.plugin = plugin; + } + + public ItemStack setString(ItemStack itemStack, String key, String value) { + ItemMeta meta = itemStack.getItemMeta(); + + if (meta == null) return null; + + meta.getPersistentDataContainer().set(new NamespacedKey(this.plugin, key), PersistentDataType.STRING, value); + itemStack.setItemMeta(meta); + + return itemStack; + } + + public String getString(ItemStack itemStack, String key) { + ItemMeta meta = itemStack.getItemMeta(); + + if (meta == null) return null; + + return meta.getPersistentDataContainer().get(new NamespacedKey(this.plugin, key), PersistentDataType.STRING); + } + + public ItemStack setBoolean(ItemStack itemStack, String key, boolean value) { + ItemMeta meta = itemStack.getItemMeta(); + + if (meta == null) return null; + + meta.getPersistentDataContainer().set(new NamespacedKey(this.plugin, key), PersistentDataType.BOOLEAN, value); + itemStack.setItemMeta(meta); + + return itemStack; + } + + public ItemStack removeTag(ItemStack itemStack, String key) { + ItemMeta meta = itemStack.getItemMeta(); + + if (meta == null) return null; + + meta.getPersistentDataContainer().remove(new NamespacedKey(this.plugin, key)); + itemStack.setItemMeta(meta); + + return itemStack; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/enums/AuctionType.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/enums/AuctionType.java new file mode 100644 index 0000000..ada77c8 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/enums/AuctionType.java @@ -0,0 +1,28 @@ +package com.badbones69.crazyauctions.api.manager.enums; + +/** + * Description: Defines the auction type to use + */ +public enum AuctionType { + + BID("Bid"), + SELL("Sell"); + + private final String name; + + AuctionType(String name) { + this.name = name; + } + + public static AuctionType getTypeFromName(String name) { + for (AuctionType type : AuctionType.values()) { + if (type.getName().equalsIgnoreCase(name)) return type; + } + + return null; + } + + public String getName() { + return this.name; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/interfaces/AuctionItem.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/interfaces/AuctionItem.java new file mode 100644 index 0000000..d365f3f --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/interfaces/AuctionItem.java @@ -0,0 +1,25 @@ +package com.badbones69.crazyauctions.api.manager.interfaces; + +import com.badbones69.crazyauctions.api.manager.enums.AuctionType; +import org.bukkit.inventory.ItemStack; +import java.util.UUID; + +public interface AuctionItem { + + UUID auctionID = UUID.randomUUID(); + + default UUID getAuctionID() { + return auctionID; + } + + AuctionType getAuctionType(); + + UUID getSeller(); + + long getPrice(); + + long getExpireTime(); + + ItemStack getSellingItem(); + +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionButtons.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionButtons.java new file mode 100644 index 0000000..761622f --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionButtons.java @@ -0,0 +1,88 @@ +package com.badbones69.crazyauctions.api.manager.objects; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.plugin.java.JavaPlugin; + +public class AuctionButtons { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + /* + private final ItemBuilder sellingItemsButton; + private final ItemBuilder sellingInfoButton; + private final ItemBuilder biddingInfoButton; + private final ItemBuilder currentListingsInfoButton; + private final ItemBuilder expiredItemsButton; + private final ItemBuilder expiredInfoButton; + private final ItemBuilder categoriesButton; + private final ItemBuilder categoriesInfoButton; + private final ItemBuilder nextPageButton; + private final ItemBuilder refreshPageButton; + private final ItemBuilder backPageButton; + private final ItemBuilder switchModeButton; + + public AuctionButtons(FileConfiguration file) { + String path = "auction-house.settings.buttons."; + sellingItemsButton = ItemUtils.convertString(file.getString(path + "selling-items")); + sellingInfoButton = ItemUtils.convertString(file.getString(path + "info.selling-items")); + biddingInfoButton = ItemUtils.convertString(file.getString(path + "info.bidding")); + currentListingsInfoButton = ItemUtils.convertString(file.getString(path + "info.current-listings")); + expiredItemsButton = ItemUtils.convertString(file.getString(path + "expired-items")); + expiredInfoButton = ItemUtils.convertString(file.getString(path + "info.expired-items")); + categoriesButton = ItemUtils.convertString(file.getString(path + "categories")); + categoriesInfoButton = ItemUtils.convertString(file.getString(path + "info.categories")); + nextPageButton = ItemUtils.convertString(file.getString(path + "next-page")); + refreshPageButton = ItemUtils.convertString(file.getString(path + "refresh-page")); + backPageButton = ItemUtils.convertString(file.getString(path + "back-page")); + switchModeButton = ItemUtils.convertString(file.getString(path + "switch-mode")); + } + + + public ItemBuilder getSellingItemsButton() { + return sellingItemsButton; + } + + public ItemBuilder getSellingInfoButton() { + return sellingInfoButton; + } + + public ItemBuilder getBiddingInfoButton() { + return biddingInfoButton; + } + + public ItemBuilder getCurrentListingsInfoButton() { + return currentListingsInfoButton; + } + + public ItemBuilder getExpiredItemsButton() { + return expiredItemsButton; + } + + public ItemBuilder getExpiredInfoButton() { + return expiredInfoButton; + } + + public ItemBuilder getCategoriesButton() { + return categoriesButton; + } + + public ItemBuilder getCategoriesInfoButton() { + return categoriesInfoButton; + } + + public ItemBuilder getNextPageButton() { + return nextPageButton; + } + + public ItemBuilder getRefreshPageButton() { + return refreshPageButton; + } + + public ItemBuilder getBackPageButton() { + return backPageButton; + } + + public ItemBuilder getSwitchModeButton() { + return switchModeButton; + }*/ +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionCategory.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionCategory.java new file mode 100644 index 0000000..5b63411 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionCategory.java @@ -0,0 +1,44 @@ +package com.badbones69.crazyauctions.api.manager.objects; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.api.frame.items.ItemBuilder; +import org.bukkit.Material; +import org.bukkit.plugin.java.JavaPlugin; +import java.util.List; + +/** + * Description: Creates the auction categories + */ +public class AuctionCategory { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private String name; + private int slot; + //private ItemBuilder displayItem; + private List categoryItemList; + + //TODO make it so each AH can have their own categories and the default ones should be able to be disabled. + public AuctionCategory(String name, int slot, ItemBuilder displayItem, List categoryItemList) { + this.name = name; + this.slot = slot; + //this.displayItem = displayItem; + this.categoryItemList = categoryItemList; + } + + public String getName() { + return name; + } + + public int getSlot() { + return slot; + } + + //public ItemBuilder getDisplayItem() { + // return displayItem; + //} + + public List getCategoryItemList() { + return categoryItemList; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionHouse.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionHouse.java new file mode 100644 index 0000000..e0b3727 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionHouse.java @@ -0,0 +1,91 @@ +package com.badbones69.crazyauctions.api.manager.objects; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.api.manager.enums.AuctionType; +import com.badbones69.crazyauctions.api.manager.interfaces.AuctionItem; +import com.badbones69.crazyauctions.api.manager.objects.auctiontype.BiddingAuction; +import com.badbones69.crazyauctions.api.manager.objects.auctiontype.SellingAuction; +import com.badbones69.crazyauctions.api.events.AuctionAddEvent; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.java.JavaPlugin; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * Description: Creates the main auction house menu + */ +public class AuctionHouse { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private String name; + private FileConfiguration auctionFile; + private InventorySettings inventorySettings; + private List auctionItems = new ArrayList<>(); + private List auctionCategories = new ArrayList<>(); + + public AuctionHouse(FileConfiguration file) { + this.name = file.getString("auction-house.settings.name"); + this.auctionFile = file; + this.inventorySettings = new InventorySettings(file); + //Loads the auction house listings into the auction house. + //TODO this needs to be moved to a seperated data file that doesnt hold all the auction house settings. + for (String auctionID : file.getConfigurationSection("auction-house.item-on-auction").getKeys(false)) { + String path = "auction-house.item-on-auction" + auctionID + "."; + AuctionType auctionType = AuctionType.getTypeFromName(file.getString(path + "auction-type")); + if (auctionType == AuctionType.SELL) { + auctionItems.add(new SellingAuction( + UUID.fromString(file.getString(path + "seller-uuid")), + file.getLong(path + "price"), + file.getLong(path + "expire-time"), + file.getItemStack(path + "selling-item"))); + } else { + auctionItems.add(new BiddingAuction( + UUID.fromString(file.getString(path + "seller-uuid")), + UUID.fromString(file.getString(path + "highest-bidder-uuid")), + file.getLong(path + "price"), + file.getLong(path + "current-bid"), + file.getLong(path + "expire-time"), + file.getItemStack(path + "selling-item"))); + } + } + //Loads the category items into the auction house. + //TODO Need to add the default categories like isPotion, isArmor, isFood, Ect... + //for (String category : file.getConfigurationSection("auction-house.categories").getKeys(false)) { + // String path = "auction-house.categories." + category + "."; + // auctionCategories.add(new AuctionCategory( + // category, + // file.getInt(path + "slot"), + //ItemUtils.convertString(file.getString(path + "item")), + //file.getStringList(path + "items").stream().map(Material :: matchMaterial).collect(Collectors.toList()))); + //} + } + + public String getName() { + return name; + } + + public FileConfiguration getAuctionFile() { + return auctionFile; + } + + public InventorySettings getInventorySettings() { + return inventorySettings; + } + + public List getAuctionItems() { + return auctionItems; + } + + public long getAuctionCount(AuctionType auctionType) { + return auctionItems.stream().filter(auctionItem -> auctionType == auctionItem.getAuctionType()).count(); + } + + public void addAuctionItem(AuctionItem auctionItem) { + auctionItems.add(auctionItem); + AuctionAddEvent event = new AuctionAddEvent(auctionItem.getSeller(), this, auctionItem); + Bukkit.getServer().getPluginManager().callEvent(event); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/InventorySettings.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/InventorySettings.java new file mode 100644 index 0000000..3170b66 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/InventorySettings.java @@ -0,0 +1,30 @@ +package com.badbones69.crazyauctions.api.manager.objects; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +/** + * Description: Creates the auction house inventory settings + */ +public class InventorySettings { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private final String title; + private final AuctionButtons auctionButtons = null; + + public InventorySettings(FileConfiguration file) { + String path = "auction-house.settings."; + this.title = file.getString(path + "inventory-title"); + //this.auctionButtons = new AuctionButtons(file); + } + + public String getTitle() { + return title; + } + + public AuctionButtons getAuctionButtons() { + return auctionButtons; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/BiddingAuction.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/BiddingAuction.java new file mode 100644 index 0000000..14ede86 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/BiddingAuction.java @@ -0,0 +1,74 @@ +package com.badbones69.crazyauctions.api.manager.objects.auctiontype; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.api.manager.enums.AuctionType; +import com.badbones69.crazyauctions.api.manager.interfaces.AuctionItem; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; +import java.util.UUID; + +/** + * Description: Creates the bidding auction type + */ +public class BiddingAuction implements AuctionItem { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + AuctionType auctionType = AuctionType.BID; + UUID seller; + UUID highestBidder; + long price; + long currentBid; + long expireTime; + ItemStack sellingItem; + + public BiddingAuction(UUID seller, UUID highestBidder, long price, long currentBid, long expireTime, ItemStack sellingItem) { + this.seller = seller; + this.highestBidder = highestBidder; + this.price = price; + this.currentBid = 0; + this.expireTime = expireTime; + this.sellingItem = sellingItem; + } + + @Override + public AuctionType getAuctionType() { + return auctionType; + } + + @Override + public UUID getSeller() { + return seller; + } + + public UUID getHighestBidder() { + return highestBidder; + } + + public void setHighestBidder(UUID highestBidder) { + this.highestBidder = highestBidder; + } + + @Override + public long getPrice() { + return price; + } + + public long getCurrentBid() { + return currentBid; + } + + public void setCurrentBid(long currentBid) { + this.currentBid = currentBid; + } + + @Override + public long getExpireTime() { + return expireTime; + } + + @Override + public ItemStack getSellingItem() { + return sellingItem; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/SellingAuction.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/SellingAuction.java new file mode 100644 index 0000000..12a2578 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/SellingAuction.java @@ -0,0 +1,54 @@ +package com.badbones69.crazyauctions.api.manager.objects.auctiontype; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.api.manager.enums.AuctionType; +import com.badbones69.crazyauctions.api.manager.interfaces.AuctionItem; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; +import java.util.UUID; + +/** + * Description: Creates the selling auction type + */ +public class SellingAuction implements AuctionItem { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + AuctionType auctionType = AuctionType.SELL; + UUID seller; + long price; + long expireTime; + ItemStack sellingItem; + + public SellingAuction(UUID seller, long price, long expireTime, ItemStack sellingItem) { + this.seller = seller; + this.price = price; + this.expireTime = expireTime; + this.sellingItem = sellingItem; + } + + @Override + public AuctionType getAuctionType() { + return auctionType; + } + + @Override + public UUID getSeller() { + return seller; + } + + @Override + public long getPrice() { + return price; + } + + @Override + public long getExpireTime() { + return expireTime; + } + + @Override + public ItemStack getSellingItem() { + return sellingItem; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/AuctionCommand.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/AuctionCommand.java new file mode 100644 index 0000000..68135c4 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/AuctionCommand.java @@ -0,0 +1,21 @@ +package com.badbones69.crazyauctions.commands; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.api.frame.command.CommandContext; +import com.badbones69.crazyauctions.api.frame.command.CommandEngine; +import org.bukkit.plugin.java.JavaPlugin; +import java.util.Collections; + +public class AuctionCommand extends CommandEngine { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + protected AuctionCommand() { + super("auctions", "Opens the auction house", "/crazyauctions:auctions", Collections.emptyList()); + } + + @Override + protected void perform(CommandContext context, String[] args) { + + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/admin/CommandReload.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/admin/CommandReload.java new file mode 100644 index 0000000..bd2479d --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/admin/CommandReload.java @@ -0,0 +1,23 @@ +package com.badbones69.crazyauctions.commands.admin; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.api.CrazyManager; +import com.badbones69.crazyauctions.api.frame.command.CommandContext; +import com.badbones69.crazyauctions.api.frame.command.CommandEngine; +import org.bukkit.plugin.java.JavaPlugin; +import java.util.Collections; + +public class CommandReload extends CommandEngine { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + private final CrazyManager crazyManager = this.plugin.getCrazyManager(); + + public CommandReload() { + super("reload", "Reloads the plugin.", "/crazyauctions:reload", Collections.emptyList()); + } + + @Override + protected void perform(CommandContext context, String[] args) { + this.crazyManager.reload(); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventory.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventory.java new file mode 100644 index 0000000..a96c988 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventory.java @@ -0,0 +1,23 @@ +package com.badbones69.crazyauctions.commands.inventories; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +public class AuctionInventory implements InventoryHolder { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private final Inventory inventory; + + public AuctionInventory() { + this.inventory = plugin.getServer().createInventory(this, 9); + } + + @Override + public @NotNull Inventory getInventory() { + return this.inventory; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventoryClick.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventoryClick.java new file mode 100644 index 0000000..fb49a6c --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventoryClick.java @@ -0,0 +1,35 @@ +package com.badbones69.crazyauctions.commands.inventories; + +import com.badbones69.crazyauctions.api.frame.items.ItemBuilder; +import com.badbones69.crazyauctions.frame.utils.AdventureUtils; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +public class AuctionInventoryClick implements Listener { + + @EventHandler + public void onAuctionClick(InventoryClickEvent event) { + Inventory inventory = event.getClickedInventory(); + + if (inventory == null || (!(inventory.getHolder() instanceof AuctionInventory auctionInventory))) return; + + event.setCancelled(true); + + ItemStack clicked = event.getCurrentItem(); + + if (clicked != null) { + event.getWhoClicked().sendMessage("Beep Boo Boo Beep!"); + + ItemBuilder builder = ItemBuilder.setStack(new ItemStack(Material.DIAMOND_SWORD)); + + builder.setAmount(3); + builder.setDisplayName(AdventureUtils.parse("This is a test")); + + auctionInventory.getInventory().addItem(builder.build()); + } + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/events/DataListener.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/events/DataListener.java new file mode 100644 index 0000000..5d230ae --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/events/DataListener.java @@ -0,0 +1,27 @@ +package com.badbones69.crazyauctions.events; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.storage.interfaces.UserManager; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public class DataListener implements Listener { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private final UserManager userManager = this.plugin.getCrazyManager().getStorageManager().getUserManager(); + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerJoin(PlayerJoinEvent event) { + this.userManager.load(event.getPlayer().getUniqueId()); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerQuit(PlayerQuitEvent event) { + this.userManager.saveSingular(event.getPlayer().getUniqueId(), true); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/interfaces/UserManager.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/interfaces/UserManager.java new file mode 100644 index 0000000..fd76a9a --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/interfaces/UserManager.java @@ -0,0 +1,28 @@ +package com.badbones69.crazyauctions.storage.interfaces; + +import com.badbones69.crazyauctions.frame.storage.enums.StorageType; +import com.badbones69.crazyauctions.storage.objects.UserData; +import java.io.File; +import java.nio.file.Path; +import java.util.Map; +import java.util.UUID; + +public interface UserManager { + + void load(UUID uuid); + + void saveSingular(UUID uuid, boolean serverExit); + + void save(boolean serverExit); + + void convert(File file, UUID uuid, StorageType storageType); + + void addAuction(UUID uuid); + + File getFile(Path path, UUID uuid); + + UserData getUser(UUID uuid); + + Map getUsers(); + +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/objects/UserData.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/objects/UserData.java new file mode 100644 index 0000000..e39dc32 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/objects/UserData.java @@ -0,0 +1,24 @@ +package com.badbones69.crazyauctions.storage.objects; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +public class UserData { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private final UUID uuid; + + private ConcurrentHashMap auctionData = new ConcurrentHashMap<>(); + + public UserData(UUID uuid) { + this.uuid = uuid; + } + + public Player getPlayer() { + return this.plugin.getServer().getPlayer(this.uuid); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/StorageManager.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/StorageManager.java new file mode 100644 index 0000000..c978530 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/StorageManager.java @@ -0,0 +1,17 @@ +package com.badbones69.crazyauctions.storage.types; + +import com.badbones69.crazyauctions.storage.interfaces.UserManager; +import com.badbones69.crazyauctions.storage.types.file.yaml.YamlUserManager; + +public class StorageManager { + + private UserManager userManager; + + public void init() { + this.userManager = new YamlUserManager(); + } + + public UserManager getUserManager() { + return this.userManager; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/file/yaml/YamlUserManager.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/file/yaml/YamlUserManager.java new file mode 100644 index 0000000..5fc8f73 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/file/yaml/YamlUserManager.java @@ -0,0 +1,110 @@ +package com.badbones69.crazyauctions.storage.types.file.yaml; + +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.frame.storage.enums.StorageType; +import com.badbones69.crazyauctions.storage.interfaces.UserManager; +import com.badbones69.crazyauctions.storage.objects.UserData; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Collections; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +public class YamlUserManager extends YamlConfiguration implements UserManager { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private final ConcurrentHashMap userData = new ConcurrentHashMap<>(); + + public YamlUserManager() { + + } + + @Override + public void load(UUID uuid) { + try { + File file = new File(this.plugin.getDataFolder() + "/users/" + uuid + ".yml"); + + if (!file.exists()) file.createNewFile(); + + load(file); + } catch (IOException | InvalidConfigurationException e) { + e.printStackTrace(); + } + } + + @Override + public void saveSingular(UUID uuid, boolean serverExit) { + // If user data empty return. + if (this.userData.isEmpty()) return; + + // Check if user data contains keys. + if (this.userData.containsKey(uuid)) { + // Remove user when done. + this.userData.remove(uuid); + + // Save the file then load the changes back in. + reload(uuid, serverExit); + } + } + + private void reload(UUID uuid, boolean serverExit) { + try { + File file = new File(this.plugin.getDataFolder() + "/users/" + uuid + ".yml"); + + save(file); + + if (!serverExit) load(uuid); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void save(boolean serverExit) { + // If user data empty return. + if (this.userData.isEmpty()) return; + + // If the player is not leaving, continue here as we are stopping the server or doing periodic save. + this.userData.forEach((id, user) -> { + //user.getKeys().forEach((crateMap, keys) -> set("users." + id + "." + crateMap, keys)); + + // Save the file then load the changes back in. + reload(id, serverExit); + }); + } + + @Override + public void convert(File file, UUID uuid, StorageType storageType) { + + } + + @Override + public void addAuction(UUID uuid) { + Player player = this.plugin.getServer().getPlayer(uuid); + } + + @Override + public File getFile(Path path, UUID uuid) { + return new File(this.plugin.getDataFolder() + "/users/" + uuid + ".yml"); + } + + @Override + public UserData getUser(UUID uuid) { + Player player = this.plugin.getServer().getPlayer(uuid); + + // Return with their user data. + return this.userData.get(uuid); + } + + @Override + public Map getUsers() { + return Collections.unmodifiableMap(this.userData); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/PlaceholderSupport.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/PlaceholderSupport.java new file mode 100644 index 0000000..3aef78e --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/PlaceholderSupport.java @@ -0,0 +1,17 @@ +package com.badbones69.crazyauctions.support; + +import com.badbones69.crazyauctions.ApiManager; +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.config.types.PluginConfig; +import org.bukkit.plugin.java.JavaPlugin; + +public class PlaceholderSupport { + + private static final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + public static String setPlaceholders(String placeholder) { + placeholder = placeholder.replaceAll("\\{prefix}", ApiManager.getPluginConfig().getProperty(PluginConfig.COMMAND_PREFIX)); + + return placeholder; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/Currency.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/Currency.java new file mode 100644 index 0000000..046c464 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/Currency.java @@ -0,0 +1,51 @@ +package com.badbones69.crazyauctions.support.economy; + +/** + * Description: This event is fired when an item is added to an auction house. + */ +public enum Currency { + + VAULT("Vault"), + XP_LEVEL("XP_Level"), + XP_TOTAL("XP_Total"); + + private final String name; + + Currency(String name) { + this.name = name; + } + + /** + * Checks if it is a compatible currency. + * @param currency The currency name you are checking. + * @return True if it is supported and false if not. + */ + public static boolean isCurrency(String currency) { + for (Currency value : Currency.values()) { + if (currency.equalsIgnoreCase(value.getName())) return true; + } + + return false; + } + + /** + * Get a currency enum. + * @param currency The currency you want. + * @return The currency enum. + */ + public static Currency getCurrency(String currency) { + for (Currency value : Currency.values()) { + if (currency.equalsIgnoreCase(value.getName())) return value; + } + + return null; + } + + /** + * Get the name of the currency. + * @return The name of the currency. + */ + public String getName() { + return name; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/CurrencyAPI.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/CurrencyAPI.java new file mode 100644 index 0000000..ab92b20 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/CurrencyAPI.java @@ -0,0 +1,131 @@ +package com.badbones69.crazyauctions.support.economy; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import java.util.UUID; + +/** + * Description: Defines what currency to use. + */ +public class CurrencyAPI { + + // TODO() Add item support as a currency. + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + /** + * Get the amount that a player has from a specific currency. + * + * @param uuid - The uuid of the player. + * @param currency - The currency you wish to get from. + * @return amount that the player has of that currency. + */ + public int getCurrency(UUID uuid, Currency currency) { + try { + OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(uuid); + Player player = plugin.getServer().getPlayer(uuid); + + switch (currency) { + case VAULT: //if (player != null) return (int) plugin.getVaultSupport().getVault().getBalance(player); + + case XP_LEVEL: if (player != null) return player.getLevel(); + + case XP_TOTAL: if (player != null) return getTotalExperience(player); + } + } catch (Exception | NoClassDefFoundError ignored) {} + return 0; + } + + /** + * Take an amount from a player's currency. + * + * @param uuid - The uuid of the player. + * @param currency - The currency you wish to use. + * @param amount - The amount you want to take. + */ + public void takeCurrency(UUID uuid, Currency currency, int amount) { + try { + Player player = plugin.getServer().getPlayer(uuid); + + switch (currency) { + //case VAULT: if (player != null) plugin.getVaultSupport().getVault().withdrawPlayer(player, amount); + case XP_LEVEL: if (player != null) player.setLevel(player.getLevel() - amount); + case XP_TOTAL: if (player != null) takeTotalExperience(player, amount); + } + } catch (Exception | NoClassDefFoundError ignored) {} + } + + /** + * Give an amount to a player's currency. + * + * @param uuid - The uuid of the player. + * @param currency - The currency you want to use. + * @param amount - The amount you are giving to the player. + */ + public void giveCurrency(UUID uuid, Currency currency, int amount) { + try { + Player player = plugin.getServer().getPlayer(uuid); + + switch (currency) { + //case VAULT: if (player != null) plugin.getVaultSupport().getVault().depositPlayer(player, amount); + case XP_LEVEL: if (player != null) player.setLevel(player.getLevel() + amount); + case XP_TOTAL: if (player != null) takeTotalExperience(player, -amount); + } + } catch (Exception | NoClassDefFoundError ignored) {} + } + + /** + * Checks if the player has enough of a currency. + * + * @param uuid - The uuid of the player. + * @param currency The currency you wish to check. + * @param cost The cost of the item you are checking. + * @return true if they have enough to buy it or false if they don't. + */ + public boolean canBuy(UUID uuid, Currency currency, int cost) { + return getCurrency(uuid, currency) >= cost; + } + + private void takeTotalExperience(Player player, int amount) { + int total = getTotalExperience(player) - amount; + player.setTotalExperience(0); + player.setTotalExperience(total); + player.setLevel(0); + player.setExp(0); + + while (total > player.getExpToLevel()) { + total -= player.getExpToLevel(); + player.setLevel(player.getLevel() + 1); + } + + float xp = (float) total / (float) player.getExpToLevel(); + player.setExp(xp); + } + + private int getTotalExperience(Player player) { // https://www.spigotmc.org/threads/72804 + int experience; + int level = player.getLevel(); + + if (level >= 0 && level <= 15) { + experience = (int) Math.ceil(Math.pow(level, 2) + (6 * level)); + int requiredExperience = 2 * level + 7; + double currentExp = Double.parseDouble(Float.toString(player.getExp())); + experience += Math.ceil(currentExp * requiredExperience); + return experience; + } else if (level > 15 && level <= 30) { + experience = (int) Math.ceil((2.5 * Math.pow(level, 2) - (40.5 * level) + 360)); + int requiredExperience = 5 * level - 38; + double currentExp = Double.parseDouble(Float.toString(player.getExp())); + experience += Math.ceil(currentExp * requiredExperience); + return experience; + } else { + experience = (int) Math.ceil((4.5 * Math.pow(level, 2) - (162.5 * level) + 2220)); + int requiredExperience = 9 * level - 158; + double currentExp = Double.parseDouble(Float.toString(player.getExp())); + experience += Math.ceil(currentExp * requiredExperience); + return experience; + } + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/vault/VaultSupport.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/vault/VaultSupport.java new file mode 100644 index 0000000..3051a51 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/vault/VaultSupport.java @@ -0,0 +1,26 @@ +package com.badbones69.crazyauctions.support.economy.vault; + +import com.badbones69.crazyauctions.CrazyAuctions; +import net.milkbowl.vault.economy.Economy; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; + +/** + * Description: Vault support related code. + */ +public class VaultSupport { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + private Economy vault = null; + + public Economy getVault() { + return vault; + } + + public void loadVault() { + RegisteredServiceProvider serviceProvider = plugin.getServer().getServicesManager().getRegistration(Economy.class); + + if (serviceProvider != null) vault = serviceProvider.getProvider(); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/ItemUtils.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/ItemUtils.java new file mode 100644 index 0000000..70219f4 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/ItemUtils.java @@ -0,0 +1,10 @@ +package com.badbones69.crazyauctions.utils; + +import com.badbones69.crazyauctions.CrazyAuctions; +import org.bukkit.plugin.java.JavaPlugin; + +public class ItemUtils { + + private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/misc/ColorUtils.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/misc/ColorUtils.java new file mode 100644 index 0000000..cd7a27f --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/misc/ColorUtils.java @@ -0,0 +1,15 @@ +package com.badbones69.crazyauctions.utils.misc; + +import com.badbones69.crazyauctions.ApiManager; +import com.badbones69.crazyauctions.CrazyAuctions; +import com.badbones69.crazyauctions.config.types.PluginConfig; +import org.bukkit.plugin.java.JavaPlugin; + +public class ColorUtils { + + private static final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); + + public static String getPrefix() { + return ApiManager.getPluginConfig().getProperty(PluginConfig.COMMAND_PREFIX); + } +} \ No newline at end of file diff --git a/src/main/resources/config1.12.2-Down.yml b/paper/src/main/resources/config1.12.2-Down.yml similarity index 100% rename from src/main/resources/config1.12.2-Down.yml rename to paper/src/main/resources/config1.12.2-Down.yml diff --git a/src/main/resources/config1.13-Up.yml b/paper/src/main/resources/config1.13-Up.yml similarity index 100% rename from src/main/resources/config1.13-Up.yml rename to paper/src/main/resources/config1.13-Up.yml diff --git a/src/main/resources/data.yml b/paper/src/main/resources/data.yml similarity index 100% rename from src/main/resources/data.yml rename to paper/src/main/resources/data.yml diff --git a/src/main/resources/messages.yml b/paper/src/main/resources/messages.yml similarity index 100% rename from src/main/resources/messages.yml rename to paper/src/main/resources/messages.yml diff --git a/src/main/resources/plugin.yml b/paper/src/main/resources/plugin.yml similarity index 100% rename from src/main/resources/plugin.yml rename to paper/src/main/resources/plugin.yml diff --git a/src/main/resources/test-file.yml b/paper/src/main/resources/test-file.yml similarity index 100% rename from src/main/resources/test-file.yml rename to paper/src/main/resources/test-file.yml diff --git a/pom.xml b/pom.xml deleted file mode 100644 index d3a603e..0000000 --- a/pom.xml +++ /dev/null @@ -1,116 +0,0 @@ - - - 4.0.0 - - com.badbones69 - crazyauctions - 1.2.19 - Crazy-Auctions - - - UTF-8 - - - - - - - crazycrew-repo-releases - CrazyCrew Team - https://repo.badbones69.com/releases - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - vault-repo - http://nexus.hc.to/content/repositories/pub_releases - - - codemc-repo - https://repo.codemc.io/repository/maven-public/ - - - - - - org.spigotmc - spigot-api - 1.19.3-R0.1-SNAPSHOT - provided - - - net.milkbowl.vault - VaultAPI - 1.7 - provided - - - bukkit - org.bukkit - - - - - net.tnemc - Reserve - 0.1.5.0 - provided - - - org.bstats - bstats-bukkit - 3.0.0 - provided - - - - - ${project.name}-[v${project.version}] - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.1.0 - - - - org.bstats - - com.badbones69.crazyauctions.libraries - - - - - - package - - shade - - - - - - - \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..2a6847f --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,17 @@ +pluginManagement { + repositories { + maven("https://repo.papermc.io/repository/maven-public/") + + gradlePluginPortal() + mavenCentral() + } +} + +rootProject.name = "CrazyAuctions" + +listOf( + "paper", + "common" +).forEach { + include(it) +} \ No newline at end of file From ac2edcda0834f4c6b89bdab8f92fef5140f392ee Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Sat, 11 Nov 2023 12:55:17 -0500 Subject: [PATCH 4/7] Bump version --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4f7595f..41446ab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,9 +7,9 @@ website = https://modrinth.com/plugin/crazycrates sources = https://github.com/Crazy-Crew/CrazyCrates issues = https://github.com/Crazy-Crew/CrazyCrates/issues -group = us.crazycrew.crazycrates -description = Add unlimited crates to your server with 10 different crate types to choose from! -version = 1.18 +group = com.badbones69.crazyauctions +description = A simple auctions plugin where you can sell your items and bid on other items! +version = 1.3 apiVersion = 1.20 minecraftVersion=1.20.2 \ No newline at end of file From 689a5170f456996291fa9863a5cc4d54675f71d6 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Sun, 26 Nov 2023 22:48:37 -0500 Subject: [PATCH 5/7] Revert "Bump version" This reverts commit ac2edcda0834f4c6b89bdab8f92fef5140f392ee. --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 41446ab..4f7595f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,9 +7,9 @@ website = https://modrinth.com/plugin/crazycrates sources = https://github.com/Crazy-Crew/CrazyCrates issues = https://github.com/Crazy-Crew/CrazyCrates/issues -group = com.badbones69.crazyauctions -description = A simple auctions plugin where you can sell your items and bid on other items! -version = 1.3 +group = us.crazycrew.crazycrates +description = Add unlimited crates to your server with 10 different crate types to choose from! +version = 1.18 apiVersion = 1.20 minecraftVersion=1.20.2 \ No newline at end of file From 2b1110f03cf355979a9730859f3a54e29ca68523 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Sun, 26 Nov 2023 22:57:48 -0500 Subject: [PATCH 6/7] update files --- .gitignore | 2 +- common/build.gradle.kts | 14 - .../common/CrazyAuctionsPlugin.java | 81 --- .../common/config/ConfigBuilder.java | 30 - .../common/config/types/Config.java | 43 -- .../common/config/types/Messages.java | 47 -- .../common/config/types/PluginConfig.java | 33 - .../crazyauctions/common/data/UserCache.java | 39 - gradle.properties | 8 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../crazyauctions/v2/CrazyAuctions.java | 55 -- .../crazyauctions/v2/CrazyStarter.java | 30 - .../crazyauctions/v2/api/CrazyManager.java | 34 - .../v2/api/enums/Permissions.java | 38 - .../v2/api/enums/support/DataSupport.java | 19 - .../v2/api/events/AuctionAddEvent.java | 62 -- .../v2/api/events/AuctionBidEvent.java | 65 -- .../v2/api/events/AuctionBuyEvent.java | 65 -- .../v2/api/events/AuctionCancelEvent.java | 82 --- .../v2/api/events/AuctionExpireEvent.java | 55 -- .../v2/api/events/AuctionListEvent.java | 65 -- .../v2/api/events/AuctionWinEvent.java | 65 -- .../crazyauctions/v2/api/frame/ItemUtils.java | 27 - .../crazyauctions/v2/api/frame/PaperCore.java | 140 ---- .../v2/api/frame/PaperUtils.java | 25 - .../frame/adapters/LocationTypeAdapter.java | 52 -- .../v2/api/frame/command/CommandContext.java | 268 ------- .../v2/api/frame/command/CommandEngine.java | 164 ----- .../v2/api/frame/command/CommandFlow.java | 30 - .../v2/api/frame/command/CommandManager.java | 123 ---- .../frame/command/builders/CommandActor.java | 48 -- .../command/builders/CommandDataEntry.java | 14 - .../command/builders/CommandHelpEntry.java | 156 ---- .../command/builders/annotations/Hidden.java | 7 - .../frame/command/builders/args/Argument.java | 3 - .../command/builders/args/ArgumentType.java | 9 - .../command/builders/args/CommandArgs.java | 22 - .../args/builder/BooleanArgument.java | 12 - .../builders/args/builder/DoubleArgument.java | 34 - .../builders/args/builder/FloatArgument.java | 34 - .../builders/args/builder/IntArgument.java | 28 - .../args/builder/custom/PlayerArgument.java | 15 - .../builders/other/ComponentBuilder.java | 94 --- .../builders/reqs/CommandRequirements.java | 57 -- .../reqs/CommandRequirementsBuilder.java | 33 - .../v2/api/frame/items/BaseItemBuilder.java | 673 ------------------ .../v2/api/frame/items/ItemBuilder.java | 23 - .../v2/api/frame/items/ItemNbt.java | 57 -- .../v2/api/manager/enums/AuctionType.java | 28 - .../api/manager/interfaces/AuctionItem.java | 25 - .../api/manager/objects/AuctionButtons.java | 88 --- .../api/manager/objects/AuctionCategory.java | 44 -- .../v2/api/manager/objects/AuctionHouse.java | 91 --- .../manager/objects/InventorySettings.java | 30 - .../objects/auctiontype/BiddingAuction.java | 74 -- .../objects/auctiontype/SellingAuction.java | 54 -- .../v2/commands/AuctionCommand.java | 21 - .../v2/commands/admin/CommandReload.java | 23 - .../inventories/AuctionInventory.java | 23 - .../inventories/AuctionInventoryClick.java | 35 - .../crazyauctions/v2/events/DataListener.java | 27 - .../v2/storage/interfaces/UserManager.java | 28 - .../v2/storage/objects/UserData.java | 24 - .../v2/storage/types/StorageManager.java | 17 - .../types/file/yaml/YamlUserManager.java | 110 --- .../v2/support/PlaceholderSupport.java | 17 - .../v2/support/economy/Currency.java | 51 -- .../v2/support/economy/CurrencyAPI.java | 131 ---- .../support/economy/vault/VaultSupport.java | 26 - .../crazyauctions/v2/utils/ItemUtils.java | 10 - .../v2/utils/misc/ColorUtils.java | 15 - .../src/main/resources/config1.12.2-Down.yml | 306 -------- settings.gradle.kts | 8 +- 73 files changed, 8 insertions(+), 4380 deletions(-) delete mode 100644 common/build.gradle.kts delete mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/CrazyAuctionsPlugin.java delete mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/config/ConfigBuilder.java delete mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/config/types/Config.java delete mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/config/types/Messages.java delete mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/config/types/PluginConfig.java delete mode 100644 common/src/main/java/com/badbones69/crazyauctions/common/data/UserCache.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyAuctions.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyStarter.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/CrazyManager.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/Permissions.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/support/DataSupport.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionAddEvent.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBidEvent.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBuyEvent.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionCancelEvent.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionExpireEvent.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionListEvent.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionWinEvent.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/ItemUtils.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperCore.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperUtils.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/adapters/LocationTypeAdapter.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandContext.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandEngine.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandFlow.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandManager.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandActor.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandDataEntry.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandHelpEntry.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/annotations/Hidden.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/Argument.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/ArgumentType.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/CommandArgs.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/BooleanArgument.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/DoubleArgument.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/FloatArgument.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/IntArgument.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/custom/PlayerArgument.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/other/ComponentBuilder.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirements.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirementsBuilder.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/BaseItemBuilder.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemBuilder.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemNbt.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/enums/AuctionType.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/interfaces/AuctionItem.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionButtons.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionCategory.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionHouse.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/InventorySettings.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/BiddingAuction.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/SellingAuction.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/commands/AuctionCommand.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/commands/admin/CommandReload.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventory.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventoryClick.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/events/DataListener.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/storage/interfaces/UserManager.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/storage/objects/UserData.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/StorageManager.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/file/yaml/YamlUserManager.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/support/PlaceholderSupport.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/Currency.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/CurrencyAPI.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/vault/VaultSupport.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/utils/ItemUtils.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/v2/utils/misc/ColorUtils.java delete mode 100644 paper/src/main/resources/config1.12.2-Down.yml diff --git a/.gitignore b/.gitignore index a4bf8ff..6850f28 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ jars paper/build paper/.gradle -run +paper/run !paper/run/config !paper/run/spigot.yml !paper/run/bukkit.yml diff --git a/common/build.gradle.kts b/common/build.gradle.kts deleted file mode 100644 index 89b9b31..0000000 --- a/common/build.gradle.kts +++ /dev/null @@ -1,14 +0,0 @@ -plugins { - id("root-plugin") -} - -project.group = "${rootProject.group}.common" -project.version = "${rootProject.version}" - -dependencies { - api(libs.configme) { - exclude("org.yaml", "snakeyaml") - } - - compileOnly(libs.annotations) -} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/CrazyAuctionsPlugin.java b/common/src/main/java/com/badbones69/crazyauctions/common/CrazyAuctionsPlugin.java deleted file mode 100644 index 019f2ee..0000000 --- a/common/src/main/java/com/badbones69/crazyauctions/common/CrazyAuctionsPlugin.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.badbones69.crazyauctions.common; - -import ch.jalu.configme.SettingsManager; -import ch.jalu.configme.SettingsManagerBuilder; -import com.badbones69.crazyauctions.common.config.ConfigBuilder; -import com.badbones69.crazyauctions.common.config.types.PluginConfig; -import java.io.File; -import java.nio.file.Path; - -public class CrazyAuctionsPlugin { - - private final Path path; - - public CrazyAuctionsPlugin(Path path) { - this.path = path; - } - - private static SettingsManager locale; - private static SettingsManager config; - private static SettingsManager pluginConfig; - - public void load() { - File pluginConfigFile = new File(this.path.toFile(), "plugin-config.yml"); - - pluginConfig = SettingsManagerBuilder - .withYamlFile(pluginConfigFile) - .useDefaultMigrationService() - .configurationData(ConfigBuilder.buildPluginConfig()) - .create(); - - File localeDir = new File(this.path.toFile(), "locale"); - //FileUtils.extract("/locale/", this.path, false); - - File localeFile = new File(localeDir, pluginConfig.getProperty(PluginConfig.LOCALE_FILE) + ".yml"); - - locale = SettingsManagerBuilder - .withYamlFile(localeFile) - .useDefaultMigrationService() - .configurationData(ConfigBuilder.buildLocale()) - .create(); - - // Create config.yml - File configFile = new File(this.path.toFile(), "config.yml"); - - config = SettingsManagerBuilder - .withYamlFile(configFile) - .useDefaultMigrationService() - .configurationData(ConfigBuilder.buildConfig()) - .create(); - - } - - public void reload() { - // Reload configs. - pluginConfig.reload(); - config.reload(); - - locale.reload(); - - File localeDir = new File(this.path.toFile(), "locale"); - File localeFile = new File(localeDir, pluginConfig.getProperty(PluginConfig.LOCALE_FILE) + ".yml"); - - locale = SettingsManagerBuilder - .withYamlFile(localeFile) - .useDefaultMigrationService() - .configurationData(ConfigBuilder.buildLocale()) - .create(); - } - - public static SettingsManager getPluginConfig() { - return pluginConfig; - } - - public static SettingsManager getLocale() { - return locale; - } - - public static SettingsManager getConfig() { - return config; - } -} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/config/ConfigBuilder.java b/common/src/main/java/com/badbones69/crazyauctions/common/config/ConfigBuilder.java deleted file mode 100644 index a3eb53b..0000000 --- a/common/src/main/java/com/badbones69/crazyauctions/common/config/ConfigBuilder.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.badbones69.crazyauctions.common.config; - -import ch.jalu.configme.configurationdata.ConfigurationData; -import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; -import com.badbones69.crazyauctions.common.config.types.Config; -import com.badbones69.crazyauctions.common.config.types.Messages; -import com.badbones69.crazyauctions.common.config.types.PluginConfig; - -public class ConfigBuilder { - - private ConfigBuilder() {} - - public static ConfigurationData buildPluginConfig() { - return ConfigurationDataBuilder.createConfiguration( - PluginConfig.class - ); - } - - public static ConfigurationData buildConfig() { - return ConfigurationDataBuilder.createConfiguration( - Config.class - ); - } - - public static ConfigurationData buildLocale() { - return ConfigurationDataBuilder.createConfiguration( - Messages.class - ); - } -} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Config.java b/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Config.java deleted file mode 100644 index 0e66d3d..0000000 --- a/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Config.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.badbones69.crazyauctions.common.config.types; - -import ch.jalu.configme.Comment; -import ch.jalu.configme.SettingsHolder; -import ch.jalu.configme.configurationdata.CommentsConfiguration; -import ch.jalu.configme.properties.Property; -import static ch.jalu.configme.properties.PropertyInitializer.newProperty; - -public class Config implements SettingsHolder { - - public Config() {} - - @Override - public void registerComments(CommentsConfiguration conf) { - String[] header = { - "Github: https://github.com/Crazy-Crew", - "", - "Issues: https://github.com/Crazy-Crew/CrazyAuctions/issues", - "Features: https://github.com/Crazy-Crew/CrazyAuctions//discussions/categories/features", - "", - "Legacy color codes such as &7,&c no longer work. You must use MiniMessage", - "https://docs.advntr.dev/minimessage/format.html#color" - }; - - String[] deprecation = { - "", - "Warning: This section is subject to change so it is considered deprecated.", - "This is your warning before the change happens.", - "" - }; - - conf.setComment("misc", header); - } - - @Comment("Allow damage items to be auctioned off.") - public static final Property damaged_items = newProperty("misc.allow-damaged-items", false); - - @Comment("Whether or not to allow `ah sell` or not.") - public static final Property selling_module = newProperty("modules.selling-module", true); - - @Comment("Whether or not to allow `ah buy` or not.") - public static final Property bidding_module = newProperty("modules.bidding-module", true); -} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Messages.java b/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Messages.java deleted file mode 100644 index 31670d2..0000000 --- a/common/src/main/java/com/badbones69/crazyauctions/common/config/types/Messages.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.badbones69.crazyauctions.common.config.types; - -import ch.jalu.configme.SettingsHolder; -import ch.jalu.configme.configurationdata.CommentsConfiguration; -import ch.jalu.configme.properties.Property; -import ch.jalu.configme.properties.PropertyInitializer; - -public class Messages implements SettingsHolder { - - public Messages() {} - - @Override - public void registerComments(CommentsConfiguration conf) { - String[] header = { - "Submit your translations here: https://github.com/Crazy-Crew/CrazyAuctions/discussions/categories/translations", - "", - "Legacy color codes such as &7,&c no longer work. You must use MiniMessage", - "https://docs.advntr.dev/minimessage/format.html#color" - }; - - String[] deprecation = { - "", - "Warning: This section is subject to change so it is considered deprecated.", - "This is your warning before the change happens.", - "" - }; - - conf.setComment("general", header); - } - - public static final Property unknown_command = PropertyInitializer.newProperty("general.unknown-command", "{prefix}The command {command} is not known."); - - public static final Property INVALID_SYNTAX = PropertyInitializer.newProperty("general.invalid-syntax", "{prefix}{value} is an invalid {action}."); - - public static final Property NO_PERMISSION = PropertyInitializer.newProperty("general.no-permission", "{prefix}You do not have permission to use that command!"); - - public static final Property REQUIRED_ARGUMENT = PropertyInitializer.newProperty("general.checks.required-argument", "{prefix}This argument is not optional"); - - public static final Property OPTIONAL_ARGUMENT = PropertyInitializer.newProperty("general.checks.optional-argument", "{prefix}This argument is optional"); - - public static final Property NOT_ENOUGH_ARGS = PropertyInitializer.newProperty("general.checks.not-enough-args", "{prefix}You did not supply enough arguments."); - - public static final Property TOO_MANY_ARGS = PropertyInitializer.newProperty("general.checks.too-many-args", "{prefix}You put more arguments then I can handle."); - - public static final Property MUST_BE_PLAYER = PropertyInitializer.newProperty("general.player-checks.must-be-player", "{prefix}You must be a player to use this command."); - -} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/config/types/PluginConfig.java b/common/src/main/java/com/badbones69/crazyauctions/common/config/types/PluginConfig.java deleted file mode 100644 index 7bc2f51..0000000 --- a/common/src/main/java/com/badbones69/crazyauctions/common/config/types/PluginConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.badbones69.crazyauctions.common.config.types; - -import ch.jalu.configme.Comment; -import ch.jalu.configme.SettingsHolder; -import ch.jalu.configme.properties.Property; -import ch.jalu.configme.properties.PropertyInitializer; -import static ch.jalu.configme.properties.PropertyInitializer.newProperty; - -/** - * Description: The plugin-settings.yml options. - */ -public class PluginConfig implements SettingsHolder { - - // Empty constructor required by SettingsHolder - protected PluginConfig() {} - - @Comment({ - "Choose what language you want the plugin to be in.", - "", - "Available Languages: en-US" - }) - public static final Property LOCALE_FILE = PropertyInitializer.newProperty("language", "en-US"); - - @Comment("Whether you want CrazyAuctions to shut up or not, This option is ignored by errors.") - public static final Property verbose_logging = newProperty("verbose_logging", true); - - @Comment({ - "Sends anonymous statistics about how the plugin is used to bstats.org.", - "bstats is a service for plugin developers to find out how the plugin being used,", - "This information helps us figure out how to better improve the plugin." - }) - public static final Property toggle_metrics = newProperty("toggle_metrics", true); -} \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazyauctions/common/data/UserCache.java b/common/src/main/java/com/badbones69/crazyauctions/common/data/UserCache.java deleted file mode 100644 index 6fae776..0000000 --- a/common/src/main/java/com/badbones69/crazyauctions/common/data/UserCache.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.badbones69.crazyauctions.common.data; - -import java.nio.file.Path; -import java.util.UUID; - -public interface UserCache { - - /** - * Add a player to the hashmap if absent. - * - * @param uuid player uuid - */ - void addPlayer(final UUID uuid); - - /** - * Remove the player from the hashmap. - * - * @param uuid player uuid - */ - void removePlayer(final UUID uuid); - - /** - * Fetch the player if online or offline. - * - * @param uuid player uuid - * @return player object - */ - String getPlayerName(final UUID uuid); - - /** - * Fetch the uuid file of the player. - * - * @param path the path i.e. 'CrazyAuctions/userdata/random-uuid.' - * @param uuid the player uuid - * @return the complete path - */ - Path getFile(final Path path, UUID uuid); - -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 4f7595f..81a249e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,9 +7,9 @@ website = https://modrinth.com/plugin/crazycrates sources = https://github.com/Crazy-Crew/CrazyCrates issues = https://github.com/Crazy-Crew/CrazyCrates/issues -group = us.crazycrew.crazycrates -description = Add unlimited crates to your server with 10 different crate types to choose from! -version = 1.18 +group = com.badbones69.com +description = Auction off items in style! +version = 1.3 apiVersion = 1.20 -minecraftVersion=1.20.2 \ No newline at end of file +minecraftVersion = 1.20.2 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3fa8f86..870dc35 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -4,4 +4,4 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyAuctions.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyAuctions.java deleted file mode 100644 index de1e841..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyAuctions.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.badbones69.crazyauctions; - -import com.badbones69.crazyauctions.api.CrazyManager; -import com.badbones69.crazyauctions.api.frame.PaperCore; -import com.badbones69.crazyauctions.api.frame.command.CommandManager; -import com.badbones69.crazyauctions.commands.inventories.AuctionInventoryClick; -import com.badbones69.crazyauctions.events.DataListener; -import org.bukkit.plugin.java.JavaPlugin; - -public class CrazyAuctions extends JavaPlugin { - - private final ApiManager apiManager; - private final PaperCore paperCore; - private CommandManager commandManager; - - private CrazyManager crazyManager; - - public CrazyAuctions(ApiManager apiManager, PaperCore paperCore) { - this.apiManager = apiManager; - this.paperCore = paperCore; - } - - @Override - public void onEnable() { - this.commandManager = CommandManager.create(); - - this.crazyManager = new CrazyManager(); - this.crazyManager.load(true); - - getServer().getPluginManager().registerEvents(new DataListener(), this); - getServer().getPluginManager().registerEvents(new AuctionInventoryClick(), this); - - } - - @Override - public void onDisable() { - if (this.crazyManager != null) this.crazyManager.stop(); - } - - public ApiManager getApiManager() { - return this.apiManager; - } - - public PaperCore getPaperCore() { - return this.paperCore; - } - - public CommandManager getCommandManager() { - return this.commandManager; - } - - public CrazyManager getCrazyManager() { - return this.crazyManager; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyStarter.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyStarter.java deleted file mode 100644 index 700825f..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/CrazyStarter.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.badbones69.crazyauctions; - -import com.badbones69.crazyauctions.api.frame.PaperCore; -import io.papermc.paper.plugin.bootstrap.BootstrapContext; -import io.papermc.paper.plugin.bootstrap.PluginBootstrap; -import io.papermc.paper.plugin.bootstrap.PluginProviderContext; -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import com.badbones69.crazyauctions.config.types.PluginConfig; - -@SuppressWarnings("ALL") -public class CrazyStarter implements PluginBootstrap { - - private ApiManager apiManager; - - @Override - public void bootstrap(@NotNull BootstrapContext context) { - this.apiManager = new ApiManager(context.getDataDirectory()); - this.apiManager.load(); - } - - @Override - public @NotNull JavaPlugin createPlugin(@NotNull PluginProviderContext context) { - PaperCore paperCore = new PaperCore(context.getDataDirectory(), Bukkit.getConsoleSender(), ApiManager.getPluginConfig().getProperty(PluginConfig.COMMAND_PREFIX), ApiManager.getPluginConfig().getProperty(PluginConfig.CONSOLE_PREFIX)); - paperCore.enable(); - - return new CrazyAuctions(this.apiManager, paperCore); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/CrazyManager.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/CrazyManager.java deleted file mode 100644 index 884856d..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/CrazyManager.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.badbones69.crazyauctions.api; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.storage.types.StorageManager; -import org.bukkit.plugin.java.JavaPlugin; - -public class CrazyManager { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private StorageManager storageManager; - - public void load(boolean serverStart) { - if (serverStart) { - this.storageManager = new StorageManager(); - - this.storageManager.init(); - } - } - - public void reload() { - if (this.plugin.getApiManager() != null) this.plugin.getApiManager().reload(); - - if (this.storageManager.getUserManager() != null) this.storageManager.getUserManager().save(false); - } - - public void stop() { - - } - - public StorageManager getStorageManager() { - return this.storageManager; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/Permissions.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/Permissions.java deleted file mode 100644 index 7f2b613..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/Permissions.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.badbones69.crazyauctions.api.enums; - -import org.bukkit.permissions.PermissionDefault; - -public enum Permissions { - - PLAYER_HELP("player.help", "Gives access to the help command.", PermissionDefault.TRUE); - - private final String node; - private final String description; - private final PermissionDefault permissionDefault; - - Permissions(String node, String description, PermissionDefault permissionDefault) { - this.node = node; - this.description = description; - this.permissionDefault = permissionDefault; - } - - public String getNode() { - return this.node; - } - - public String getDescription() { - return this.description; - } - - public PermissionDefault getPermissionDefault() { - return this.permissionDefault; - } - - public String getBuiltPermission(String action) { - return "crazyauctions." + action + "." + this.node; - } - - public String getBuiltPermission() { - return "crazyauctions.command." + this.node; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/support/DataSupport.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/support/DataSupport.java deleted file mode 100644 index affcc65..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/enums/support/DataSupport.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.badbones69.crazyauctions.api.enums.support; - -import com.badbones69.crazyauctions.storage.interfaces.UserManager; -import com.badbones69.crazyauctions.storage.types.file.yaml.YamlUserManager; - -public enum DataSupport { - - yaml(YamlUserManager.class); - - private final Class classObject; - - DataSupport(Class classObject) { - this.classObject = classObject; - } - - public Class getClassObject() { - return this.classObject; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionAddEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionAddEvent.java deleted file mode 100644 index ca70dfc..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionAddEvent.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.api.manager.interfaces.AuctionItem; -import com.badbones69.crazyauctions.api.manager.objects.AuctionHouse; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import java.util.UUID; - -/** - * Description: This event is fired when an item is added to an auction house. - */ -public class AuctionAddEvent extends Event { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private static final HandlerList handlerList = new HandlerList(); - - private final UUID uuid; - private final Player player; - private final AuctionItem auctionItem; - private final AuctionHouse auctionHouse; - - /** - * A constructor to include values for a bid event. - * - * @param uuid the uuid of the player who placed the bid. - * @param auctionHouse the auction house the item is being added to. - * @param auctionItem the auction item being added. - */ - public AuctionAddEvent(UUID uuid, AuctionHouse auctionHouse, AuctionItem auctionItem) { - this.uuid = uuid; - this.player = this.plugin.getServer().getPlayer(uuid); - this.auctionHouse = auctionHouse; - this.auctionItem = auctionItem; - } - - public AuctionItem getAuctionItem() { - return auctionItem; - } - - public AuctionHouse getAuctionHouse() { - return auctionHouse; - } - - public Player getPlayer() { - return this.player; - } - - public UUID getUUID() { - return this.uuid; - } - - @Override - public @NotNull HandlerList getHandlers() { - return handlerList; - } - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBidEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBidEvent.java deleted file mode 100644 index c928dbd..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBidEvent.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import java.util.UUID; - -/** - * Description: This event is fired when a player bids on an auction. - */ -public class AuctionBidEvent extends Event { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private static final HandlerList handlerList = new HandlerList(); - - private final UUID uuid; - private final Player player; - - private final ItemStack item; - - private final long bidPrice; - - /** - * A constructor to include values for a bid event. - * - * @param uuid the uuid of the player who placed the bid. - * @param item the item that was bid on. - * @param bidPrice the amount of money that was bid. - */ - public AuctionBidEvent(UUID uuid, ItemStack item, long bidPrice) { - this.uuid = uuid; - - this.player = this.plugin.getServer().getPlayer(uuid); - - this.item = item; - - this.bidPrice = bidPrice; - } - - public ItemStack getBidItem() { - return this.item; - } - - public long getBidPrice() { - return this.bidPrice; - } - - public Player getPlayer() { - return this.player; - } - - public UUID getUUID() { - return this.uuid; - } - - @Override - public @NotNull HandlerList getHandlers() { - return handlerList; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBuyEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBuyEvent.java deleted file mode 100644 index 3a37ddb..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionBuyEvent.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import java.util.UUID; - -/** - * Description: This event is fired when a player buys an item. - */ -public class AuctionBuyEvent extends Event { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private static final HandlerList handlerList = new HandlerList(); - - private final UUID uuid; - private final Player player; - - private final ItemStack item; - - private final long price; - - /** - * A constructor to include values for a buy event. - * - * @param uuid the uuid of the player who purchased the item. - * @param item the item that was purchased. - * @param price the amount of money used to buy. - */ - public AuctionBuyEvent(UUID uuid, ItemStack item, long price) { - this.uuid = uuid; - - this.player = this.plugin.getServer().getPlayer(uuid); - - this.item = item; - - this.price = price; - } - - public ItemStack getWinningItem() { - return this.item; - } - - public long getBuyPrice() { - return this.price; - } - - public Player getPlayer() { - return this.player; - } - - public UUID getUUID() { - return this.uuid; - } - - @Override - public @NotNull HandlerList getHandlers() { - return handlerList; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionCancelEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionCancelEvent.java deleted file mode 100644 index 8b3e87d..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionCancelEvent.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import java.util.UUID; - -/** - * Description: This event is fired when an auction is cancelled. - */ -public class AuctionCancelEvent extends Event { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private static final HandlerList handlerList = new HandlerList(); - - private final UUID uuid; - private final Player player; - private final OfflinePlayer offlinePlayer; - - private final ItemStack item; - - /** - * A constructor to include values for when an item is cancelled. - * - * @param uuid the uuid of the player whose item cancelled. - */ - public AuctionCancelEvent(UUID uuid, ItemStack item) { - this.uuid = uuid; - - this.player = this.plugin.getServer().getPlayer(uuid); - - this.offlinePlayer = this.plugin.getServer().getOfflinePlayer(uuid); - - this.item = item; - } - - /** - * @return the expired item. - */ - public ItemStack getExpiredItem() { - return this.item; - } - - /** - * Only use this when the player is online. - * - * @return the online player. - */ - public Player getPlayer() { - return this.player; - } - - /** - * Only use this when the player is offline. - * - * @return the offline player. - */ - public OfflinePlayer getOfflinePlayer() { - return this.offlinePlayer; - } - - /** - * @return the player's uuid. - */ - public UUID getUUID() { - return this.uuid; - } - - /** - * @return the handler list. - */ - @Override - public @NotNull HandlerList getHandlers() { - return handlerList; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionExpireEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionExpireEvent.java deleted file mode 100644 index 62e1cd2..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionExpireEvent.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import java.util.UUID; - -/** - * Description: This event is fired when an auction expires. - */ -public class AuctionExpireEvent extends Event { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private static final HandlerList handlerList = new HandlerList(); - - private final UUID uuid; - private final Player player; - - private final ItemStack item; - - /** - * A constructor to include values for when an item expired. - * - * @param uuid the uuid of the player whose auction expired. - */ - public AuctionExpireEvent(UUID uuid, ItemStack item) { - this.uuid = uuid; - - this.player = this.plugin.getServer().getPlayer(uuid); - - this.item = item; - } - - public ItemStack getExpiredItem() { - return this.item; - } - - public Player getPlayer() { - return this.player; - } - - public UUID getUUID() { - return this.uuid; - } - - @Override - public @NotNull HandlerList getHandlers() { - return handlerList; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionListEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionListEvent.java deleted file mode 100644 index 43a747c..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionListEvent.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import java.util.UUID; - -/** - * Description: This event is fired when a player lists an item. - */ -public class AuctionListEvent extends Event { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private static final HandlerList handlerList = new HandlerList(); - - private final UUID uuid; - private final Player player; - - private final ItemStack item; - - private final long bidPrice; - - /** - * A constructor to include values for a bid event. - * - * @param uuid the uuid of the player who placed the bid. - * @param item the item that was bid on. - * @param bidPrice the amount of money that was bid. - */ - public AuctionListEvent(UUID uuid, ItemStack item, long bidPrice) { - this.uuid = uuid; - - this.player = this.plugin.getServer().getPlayer(uuid); - - this.item = item; - - this.bidPrice = bidPrice; - } - - public ItemStack getBidItem() { - return this.item; - } - - public long getBidPrice() { - return this.bidPrice; - } - - public Player getPlayer() { - return this.player; - } - - public UUID getUUID() { - return this.uuid; - } - - @Override - public @NotNull HandlerList getHandlers() { - return handlerList; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionWinEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionWinEvent.java deleted file mode 100644 index 8dd2ba3..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/events/AuctionWinEvent.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import java.util.UUID; - -/** - * Description: This event is fired when an auction has a winner. - */ -public class AuctionWinEvent extends Event { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private static final HandlerList handlerList = new HandlerList(); - - private final UUID uuid; - private final Player player; - - private final ItemStack item; - - private final long price; - - /** - * A constructor to include values for a win event. - * - * @param uuid the uuid of the player who won the bid. - * @param item the item that was won. - * @param price the amount of money that was bid. - */ - public AuctionWinEvent(UUID uuid, ItemStack item, long price) { - this.uuid = uuid; - - this.player = this.plugin.getServer().getPlayer(uuid); - - this.item = item; - - this.price = price; - } - - public ItemStack getWinningItem() { - return this.item; - } - - public long getWinningPrice() { - return this.price; - } - - public Player getPlayer() { - return this.player; - } - - public UUID getUUID() { - return this.uuid; - } - - @Override - public @NotNull HandlerList getHandlers() { - return handlerList; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/ItemUtils.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/ItemUtils.java deleted file mode 100644 index 98e128e..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/ItemUtils.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.badbones69.crazyauctions.api.frame; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -public class ItemUtils { - - private final Material skull = Material.PLAYER_HEAD; - - public ItemStack skull() { - return new ItemStack(skull); - } - - public boolean isPlayerSkull(Material itemStack) { - return itemStack != skull; - } - - private String getVersion() { - String version = Bukkit.getServer().getClass().getPackage().getName(); - return version.substring(version.lastIndexOf('.') + 1); - } - - public Class craftClass(String name) throws ClassNotFoundException { - return Class.forName("org.bukkit.craftbukkit." + getVersion() + "." + name); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperCore.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperCore.java deleted file mode 100644 index bf43192..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperCore.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.badbones69.crazyauctions.api.frame; - -import com.badbones69.crazyauctions.ApiManager; -import com.badbones69.crazyauctions.config.types.Locale; -import com.badbones69.crazyauctions.config.types.PluginConfig; -import com.badbones69.crazyauctions.frame.CrazyCore; -import com.badbones69.crazyauctions.frame.storage.FileHandler; -import net.kyori.adventure.audience.Audience; -import java.nio.file.Path; - -public class PaperCore extends CrazyCore { - - private final Path path; - private final Audience audience; - private final FileHandler fileHandler; - private final String prefix; - private final String consolePrefix; - - public PaperCore(Path path, Audience audience, String prefix, String consolePrefix) { - // Create directory. - this.path = path; - this.path.toFile().mkdir(); - - this.audience = audience; - this.prefix = prefix; - this.consolePrefix = consolePrefix; - - this.fileHandler = new FileHandler(); - } - - @Override - public void enable() { - super.enable(); - } - - @Override - public void disable() { - super.disable(); - } - - @Override - public Path getDirectory() { - return this.path; - } - - @Override - public String getPrefix() { - return this.prefix; - } - - @Override - public String getConsolePrefix() { - return this.consolePrefix; - } - - @Override - public FileHandler getFileHandler() { - return this.fileHandler; - } - - @Override - public Audience adventure() { - return this.audience; - } - - @Override - public String commandTooFewArgs() { - return ApiManager.getLocale().getProperty(Locale.NOT_ENOUGH_ARGS); - } - - @Override - public String commandTooManyArgs() { - return ApiManager.getLocale().getProperty(Locale.TOO_MANY_ARGS); - } - - @Override - public String commandOptionalMsg() { - return ApiManager.getLocale().getProperty(Locale.OPTIONAL_ARGUMENT); - } - - @Override - public String commandRequiredMsg() { - return ApiManager.getLocale().getProperty(Locale.REQUIRED_ARGUMENT); - } - - @Override - public String commandRequirementNotPlayer() { - return ApiManager.getLocale().getProperty(Locale.MUST_BE_PLAYER); - } - - @Override - public String commandRequirementNoPermission() { - return ApiManager.getLocale().getProperty(Locale.NO_PERMISSION); - } - - @Override - public String commandHelpHeader() { - return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_HEADER); - } - - @Override - public String commandHelpFooter() { - return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_FOOTER); - } - - @Override - public String commandInvalidPage() { - return ApiManager.getPluginConfig().getProperty(PluginConfig.INVALID_HELP_PAGE); - } - - @Override - public String commandPageFormat() { - return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_FORMAT); - } - - @Override - public String commandHoverFormat() { - return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_HOVER_FORMAT); - } - - @Override - public String commandHoverAction() { - return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_HOVER_ACTION); - } - - @Override - public String commandNavigationText() { - return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_GO_TO_PAGE); - } - - @Override - public String commandNavigationNextButton() { - return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_NEXT); - } - - @Override - public String commandNavigationBackButton() { - return ApiManager.getPluginConfig().getProperty(PluginConfig.HELP_PAGE_BACK); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperUtils.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperUtils.java deleted file mode 100644 index 43e1bf3..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/PaperUtils.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.badbones69.crazyauctions.api.frame; - -public class PaperUtils { - - private static boolean hasClass(String className) { - try { - Class.forName(className); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } - - public static boolean isSpigot() { - return hasClass("org.spigotmc.SpigotConfig") && !hasClass("io.papermc.paper.configuration.Configuration") || !hasClass("com.destroystokyo.paper.PaperConfig"); - } - - public static boolean isPaper() { - return hasClass("io.papermc.paper.configuration.Configuration") || hasClass("com.destroystokyo.paper.PaperConfig"); - } - - public static boolean isFolia() { - return hasClass("io.papermc.paper.threadedregions.RegionizedServer"); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/adapters/LocationTypeAdapter.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/adapters/LocationTypeAdapter.java deleted file mode 100644 index da9219f..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/adapters/LocationTypeAdapter.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.adapters; - -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import org.bukkit.Bukkit; -import org.bukkit.Location; - -import java.io.IOException; - -public class LocationTypeAdapter extends TypeAdapter { - - @Override - public void write(JsonWriter out, Location location) throws IOException { - out.beginObject(); - out.name("world").value(location.getWorld().getName()); - out.name("x").value(location.getX()); - out.name("y").value(location.getY()); - out.name("z").value(location.getZ()); - out.name("yaw").value(location.getYaw()); - out.name("pitch").value(location.getPitch()); - out.endObject(); - } - - @Override - public Location read(JsonReader reader) throws IOException { - reader.beginObject(); - - String worldName = null; - double x = 0, y = 0, z = 0; - float yaw = 0, pitch = 0; - - while (reader.hasNext()) { - String name = reader.nextName(); - - switch (name) { - case "world" -> worldName = reader.nextString(); - case "x" -> x = reader.nextDouble(); - case "y" -> y = reader.nextDouble(); - case "z" -> z = reader.nextDouble(); - case "yaw" -> yaw = (float) reader.nextDouble(); - case "pitch" -> pitch = (float) reader.nextDouble(); - default -> reader.skipValue(); - } - } - - reader.endObject(); - - assert worldName != null; - return new Location(Bukkit.getWorld(worldName), x, y, z, yaw, pitch); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandContext.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandContext.java deleted file mode 100644 index a5dd49d..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandContext.java +++ /dev/null @@ -1,268 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command; - -import com.badbones69.crazyauctions.ApiManager; -import com.badbones69.crazyauctions.api.frame.command.builders.CommandActor; -import com.badbones69.crazyauctions.api.frame.command.builders.args.CommandArgs; -import com.badbones69.crazyauctions.config.types.Locale; -import com.badbones69.crazyauctions.frame.utils.AdventureUtils; -import com.badbones69.crazyauctions.support.PlaceholderSupport; -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.text.Component; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; -import java.util.Collections; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; - -public class CommandContext implements CommandActor, CommandArgs { - - private final Audience audience; - private final List args; - private String label; - - private Player player; - - public CommandContext(Audience audience, String label, List args) { - this.audience = audience; - - if (audience instanceof Player) { - this.player = (Player) audience; - } - - this.label = label; - this.args = args; - } - - @Override - public void reply(String message) { - if (message.isBlank() || message.isEmpty()) return; - - Component component = AdventureUtils.parse(message); - - this.audience.sendMessage(component); - } - - @Override - public void reply(boolean hasPrefix, String prefix, String message) { - if (message.isBlank() || message.isEmpty()) return; - - if (hasPrefix) { - Component component = AdventureUtils.parse(prefix).append(AdventureUtils.parse(prefix)); - - this.audience.sendMessage(component); - - return; - } - - Component component = AdventureUtils.parse(message); - - this.audience.sendMessage(component); - } - - @Override - public void reply(boolean hasPrefix, String prefix, Component component) { - if (hasPrefix) { - this.audience.sendMessage(AdventureUtils.parse(prefix).append(component)); - return; - } - - this.audience.sendMessage(component); - } - - @Override - public void reply(Component component) { - this.audience.sendMessage(component); - } - - @Override - public void send(Audience audience, String message) { - if (message.isBlank() || message.isEmpty()) return; - - Component component = AdventureUtils.parse(message); - - audience.sendMessage(component); - } - - @Override - public void send(Audience audience, Component component) { - audience.sendMessage(component); - } - - @Override - public void send(Audience audience, String message, String prefix, boolean hasPrefix) { - if (hasPrefix) { - audience.sendMessage(AdventureUtils.parse(prefix).append(AdventureUtils.parse(message))); - return; - } - - send(audience, message); - } - - @Override - public void send(Audience audience, Component message, String prefix, boolean hasPrefix) { - if (hasPrefix) { - audience.sendMessage(AdventureUtils.parse(prefix).append(message)); - return; - } - - send(audience, message); - } - - @Override - public Audience getSender() { - return this.audience; - } - - @Override - public boolean isPlayer() { - return getPlayer() != null; - } - - @Override - public Player getPlayer() { - return this.player; - } - - @Override - public boolean hasPermission(Permission permission) { - return this.player.hasPermission(permission); - } - - @Override - public boolean hasPermission(String rawPermission) { - return this.player.hasPermission(rawPermission); - } - - @Override - public void setLabel(String label) { - this.label = label; - } - - @Override - public String getLabel() { - return this.label; - } - - public List getArgs() { - return Collections.unmodifiableList(this.args); - } - - @Override - public void removeArgs(int arg) { - this.args.remove(arg); - } - - @Override - public int getArgAsInt(int index, boolean notifySender) { - Integer value = null; - - try { - value = Integer.parseInt(this.args.get(index)); - } catch (NumberFormatException exception) { - if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) - .replaceAll("\\{value}", this.args.get(index)) - .replaceAll("\\{action}", "number"))); - } - - if (value != null) return value; - - return 1; - } - - @Override - public long getArgAsLong(int index, boolean notifySender) { - Long value = null; - - try { - value = Long.parseLong(this.args.get(index)); - } catch (NumberFormatException exception) { - if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) - .replaceAll("\\{value}", this.args.get(index)) - .replaceAll("\\{action}", "number"))); - } - - if (value != null) return value; - - return 1L; - } - - @Override - public double getArgAsDouble(int index, boolean notifySender) { - Double value = null; - - try { - value = Double.parseDouble(this.args.get(index)); - } catch (NumberFormatException exception) { - if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) - .replaceAll("\\{value}", this.args.get(index)) - .replaceAll("\\{action}", "number"))); - } - - if (value != null) return value; - - return 0.1; - } - - @Override - public boolean getArgAsBoolean(int index, boolean notifySender) { - String lowercase = this.args.get(index).toLowerCase(); - - switch (lowercase) { - case "true", "on", "1" -> { - return true; - } - case "false", "off", "0" -> { - return false; - } - default -> { - if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) - .replaceAll("\\{value}", this.args.get(index).toLowerCase()) - .replaceAll("\\{action}", "boolean"))); - - return false; - } - } - } - - @Override - public float getArgAsFloat(int index, boolean notifySender) { - Float value = null; - - try { - value = Float.parseFloat(this.args.get(index)); - } catch (NumberFormatException exception) { - if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) - .replaceAll("\\{value}", this.args.get(index)) - .replaceAll("\\{action}", "number"))); - } - - if (value != null) return value; - - return 1F; - } - - @Override - public Player getArgAsPlayer(int index, boolean notifySender) { - Player player = Bukkit.getServer().getPlayer(this.args.get(index)); - - if (player == null) { - if (notifySender) reply(PlaceholderSupport.setPlaceholders(ApiManager.getLocale().getProperty(Locale.INVALID_SYNTAX) - .replaceAll("\\{value}", this.args.get(index)) - .replaceAll("\\{action}", "player"))); - - return null; - } - - return player; - } - - @Override - public OfflinePlayer getArgAsOfflinePlayer(int index) { - CompletableFuture future = CompletableFuture.supplyAsync(() -> Bukkit.getServer().getOfflinePlayer(this.args.get(index))).thenApply(OfflinePlayer::getUniqueId); - - return Bukkit.getServer().getOfflinePlayer(future.join()); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandEngine.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandEngine.java deleted file mode 100644 index b5a8fee..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandEngine.java +++ /dev/null @@ -1,164 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.api.frame.command.builders.CommandDataEntry; -import com.badbones69.crazyauctions.api.frame.command.builders.args.Argument; -import com.badbones69.crazyauctions.frame.CrazyCore; -import com.badbones69.crazyauctions.frame.utils.AdventureUtils; -import com.badbones69.crazyauctions.support.PlaceholderSupport; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.event.ClickEvent; -import net.kyori.adventure.text.event.HoverEvent; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import java.util.*; - -public abstract class CommandEngine extends Command { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private final LinkedList labels = new LinkedList<>(); - public final LinkedList requiredArgs = new LinkedList<>(); - public final LinkedList optionalArgs = new LinkedList<>(); - - private final HashMap commandData = new HashMap<>(); - - protected CommandEngine(@NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List aliases) { - super(name, description, usageMessage, aliases); - } - - public void execute(CommandContext context, String[] args) { - perform(context, args); - } - - public void execute(CommandContext context) { - StringBuilder label = new StringBuilder(context.getLabel()); - - if (!context.getArgs().isEmpty()) { - for (CommandEngine engine : this.plugin.getCommandManager().getClasses()) { - boolean isPresent = context.getArgs().stream().findFirst().isPresent(); - - if (isPresent) { - label.append(" ").append(context.getArgs().get(0)); - - context.removeArgs(0); - context.setLabel(label.toString()); - - engine.execute(context); - return; - } - } - } - - if (!validate(context)) return; - - perform(context, new String[0]); - } - - @Override - public boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) { - List arguments = Arrays.asList(args); - - CommandContext context = new CommandContext( - sender, - label, - arguments - ); - - if (arguments.isEmpty()) { - execute(context); - return true; - } - - execute(context, args); - - return true; - } - - protected abstract void perform(CommandContext context, String[] args); - - private boolean validate(CommandContext context) { - if (context.getArgs().size() < this.requiredArgs.size()) { - context.reply(CrazyCore.api().commandTooFewArgs()); - sendValidFormat(context); - return false; - } - - if (context.getArgs().size() > this.requiredArgs.size() + this.optionalArgs.size()) { - context.reply(CrazyCore.api().commandTooManyArgs()); - sendValidFormat(context); - return false; - } - - return true; - } - - private void sendValidFormat(CommandContext context) { - ArrayList arguments = new ArrayList<>(); - - arguments.addAll(this.requiredArgs); - arguments.addAll(this.optionalArgs); - - this.requiredArgs.sort(Comparator.comparing(Argument::order)); - - if (context.isPlayer()) { - StringBuilder format = new StringBuilder("/" + "crazycrates:" + getLabel()); - - TextComponent.@NotNull Builder emptyComponent = Component.text(); - - StringBuilder types = new StringBuilder(); - - for (Argument arg : arguments) { - String value = this.optionalArgs.contains(arg) ? " (" + arg.name() + ") " : " <" + arg.name() + ">"; - - String msg = this.optionalArgs.contains(arg) ? CrazyCore.api().commandOptionalMsg() : CrazyCore.api().commandRequiredMsg(); - - Component argComponent = AdventureUtils.parse(value).hoverEvent(HoverEvent.showText(AdventureUtils.parse(PlaceholderSupport.setPlaceholders(msg)))).asComponent(); - - emptyComponent.append(argComponent); - - boolean isPresent = arg.argumentType().getPossibleValues().stream().findFirst().isPresent(); - - if (isPresent) types.append(" ").append(arg.argumentType().getPossibleValues().stream().findFirst().get()); - } - - TextComponent.@NotNull Builder finalComponent = emptyComponent - .hoverEvent(HoverEvent.showText(AdventureUtils.parse("Click me to insert into chat"))) - .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, format.append(types).toString())) - .append(emptyComponent.build()); - - context.reply(finalComponent.build()); - - return; - } - - StringBuilder format = new StringBuilder("/" + "crazycrates:" + getLabel()); - - for (Argument arg : arguments) { - String value = this.optionalArgs.contains(arg) ? "(" + arg.name() + ") " : "<" + arg.name() + "> "; - - format.append(value); - } - - context.reply(format.toString()); - } - - public List getLabels() { - return Collections.unmodifiableList(this.labels); - } - - public Map getCommandData() { - return Collections.unmodifiableMap(this.commandData); - } - - public List getRequiredArgs() { - return Collections.unmodifiableList(this.requiredArgs); - } - - public List getOptionalArgs() { - return Collections.unmodifiableList(this.optionalArgs); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandFlow.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandFlow.java deleted file mode 100644 index d8f80cd..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandFlow.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command; - -import com.badbones69.crazyauctions.api.frame.command.builders.CommandActor; -import com.badbones69.crazyauctions.api.frame.command.builders.CommandDataEntry; -import com.badbones69.crazyauctions.api.frame.command.builders.CommandHelpEntry; -import java.util.List; -import java.util.Map; - -public interface CommandFlow { - - void addCommand(CommandEngine engine); - - boolean hasCommand(String label); - - CommandHelpEntry generateCommandHelp(CommandActor actor); - - int defaultHelpPerPage(); - - void updateHelpPerPage(int newAmount); - - CommandDataEntry getCommand(String label); - - void removeCommand(String label); - - Map getCommands(); - - List getClasses(); - - List handleTabComplete(String[] args, CommandEngine engine); -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandManager.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandManager.java deleted file mode 100644 index 1618ac3..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/CommandManager.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command; - -import com.badbones69.crazyauctions.api.frame.command.builders.CommandActor; -import com.badbones69.crazyauctions.api.frame.command.builders.CommandDataEntry; -import com.badbones69.crazyauctions.api.frame.command.builders.CommandHelpEntry; -import com.badbones69.crazyauctions.api.frame.command.builders.annotations.Hidden; -import com.badbones69.crazyauctions.api.frame.command.builders.args.Argument; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import java.util.*; - -public class CommandManager implements CommandFlow { - - private final HashMap commands = new HashMap<>(); - - private final LinkedList classes = new LinkedList<>(); - - private int defaultHelpPerPage = 10; - - public static CommandManager create() { - return new CommandManager(); - } - - @Override - public void addCommand(CommandEngine engine) { - // If the label already exists. We return! - if (hasCommand(engine.getLabel())) return; - - // Create data entry. - CommandDataEntry entry = new CommandDataEntry(); - - // Set visibility if annotation is present. - entry.setHidden(engine.getClass().isAnnotationPresent(Hidden.class)); - - if (entry.isHidden()) return; - - // Add to the hash-map & linked list! - this.commands.put(engine.getLabel(), entry); - this.classes.add(engine); - - // Add command to the server map! - Bukkit.getServer().getCommandMap().register("crazycrates", engine); - } - - @Override - public boolean hasCommand(String label) { - return this.commands.containsKey(label); - } - - @Override - public CommandHelpEntry generateCommandHelp(CommandActor actor) { - return new CommandHelpEntry(this, actor); - } - - @Override - public int defaultHelpPerPage() { - return this.defaultHelpPerPage; - } - - @Override - public void updateHelpPerPage(int newAmount) { - this.defaultHelpPerPage = newAmount; - } - - @Override - public CommandDataEntry getCommand(String label) { - if (hasCommand(label)) return this.commands.get(label); - - return null; - } - - @Override - public void removeCommand(String label) { - if (!hasCommand(label)) return; - - Command value = Bukkit.getServer().getCommandMap().getCommand(label); - - if (value != null && value.isRegistered()) value.unregister(Bukkit.getServer().getCommandMap()); - - this.commands.remove(label); - } - - @Override - public Map getCommands() { - return Collections.unmodifiableMap(this.commands); - } - - @Override - public List getClasses() { - return Collections.unmodifiableList(this.classes); - } - - @Override - public List handleTabComplete(String[] args, CommandEngine engine) { - List completions = Arrays.asList(args); - - if (completions.size() >= 1) { - int relativeIndex = this.classes.size(); - int argToComplete = completions.size() + 1 - relativeIndex; - if (engine.requiredArgs.size() >= argToComplete) { - ArrayList arguments = new ArrayList<>(); - - arguments.addAll(engine.requiredArgs); - arguments.addAll(engine.optionalArgs); - - ArrayList possibleValues = new ArrayList<>(); - - for (Argument argument : arguments) { - if (argument.order() == argToComplete) { - List possibleValuesArgs = argument.argumentType().getPossibleValues(); - - possibleValues = new ArrayList<>(possibleValuesArgs); - break; - } - } - - return possibleValues; - } - } - - return Collections.emptyList(); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandActor.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandActor.java deleted file mode 100644 index 2b88bab..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandActor.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders; - -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.text.Component; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; - -import java.util.List; - -public interface CommandActor { - - void reply(String message); - - void reply(boolean hasPrefix, String prefix, String message); - - void reply(boolean hasPrefix, String prefix, Component component); - - void reply(Component component); - - void send(Audience audience, String message); - - void send(Audience audience, Component component); - - void send(Audience audience, String message, String prefix, boolean hasPrefix); - - void send(Audience audience, Component message, String prefix, boolean hasPrefix); - - Audience getSender(); - - boolean isPlayer(); - - Player getPlayer(); - - boolean hasPermission(Permission permission); - - boolean hasPermission(String rawPermission); - - void setLabel(String alias); - - String getLabel(); - - List getArgs(); - - void removeArgs(int arg); - - //CommandHelpEntry getHelpEntry(); - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandDataEntry.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandDataEntry.java deleted file mode 100644 index 1d9d28c..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandDataEntry.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders; - -public class CommandDataEntry { - - private boolean isHidden = false; - - public void setHidden(boolean value) { - this.isHidden = value; - } - - public boolean isHidden() { - return this.isHidden; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandHelpEntry.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandHelpEntry.java deleted file mode 100644 index 8a33077..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/CommandHelpEntry.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders; - -import com.badbones69.crazyauctions.ApiManager; -import com.badbones69.crazyauctions.api.frame.command.CommandEngine; -import com.badbones69.crazyauctions.api.frame.command.CommandManager; -import com.badbones69.crazyauctions.api.frame.command.builders.args.Argument; -import com.badbones69.crazyauctions.api.frame.command.builders.other.ComponentBuilder; -import com.badbones69.crazyauctions.config.types.PluginConfig; -import com.badbones69.crazyauctions.frame.CrazyCore; -import com.badbones69.crazyauctions.support.PlaceholderSupport; -import net.kyori.adventure.text.event.ClickEvent; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Map; -import static com.badbones69.crazyauctions.frame.utils.AdventureUtils.hover; -import static com.badbones69.crazyauctions.frame.utils.AdventureUtils.send; - -public class CommandHelpEntry { - - private final CommandManager manager; - private final CommandActor actor; - - private int page = 1; - private int perPage; - private int totalPages; - private int totalResults; - private boolean lastPage; - - public CommandHelpEntry(CommandManager manager, CommandActor actor) { - this.manager = manager; - this.actor = actor; - - this.perPage = manager.defaultHelpPerPage(); - } - - public void showHelp() { - this.showHelp(this.actor); - } - - public void showHelp(CommandActor actor) { - int min = this.perPage * (this.page - 1); - int max = min + this.perPage; - - this.totalResults = this.manager.getCommands().size(); - - this.totalPages = this.totalResults / this.perPage; - - if (min >= this.totalResults) { - actor.reply(ApiManager.getPluginConfig().getProperty(PluginConfig.INVALID_HELP_PAGE).replaceAll("\\{page}", String.valueOf(page))); - return; - } - - Map entries = this.manager.getCommands(); - - for (int value = min; value < max; value++) { - if (this.totalResults - 1 < value) continue; - - CommandEngine command = this.manager.getClasses().get(value); - - CommandDataEntry dataEntry = entries.get(command.getLabel()); - - boolean isHidden = dataEntry.isHidden(); - - StringBuilder baseFormat = new StringBuilder("/" + command.getLabel()); - - String format = CrazyCore.api().commandPageFormat() - .replaceAll("\\{command}", baseFormat.toString()) - .replaceAll("\\{description}", command.getDescription()); - - // Only add aliases if the list isn't empty. - if (!command.getAliases().isEmpty()) baseFormat.append(" ").append(command.getLabels().get(0)); - - ArrayList arguments = new ArrayList<>(); - - arguments.addAll(command.getOptionalArgs()); - arguments.addAll(command.getRequiredArgs()); - - arguments.sort(Comparator.comparingInt(Argument::order)); - - if (actor.isPlayer()) { - StringBuilder types = new StringBuilder(); - - ComponentBuilder builder = new ComponentBuilder(); - - for (Argument arg : arguments) { - String argValue = command.optionalArgs.contains(arg) ? " (" + arg.name() + ") " : " <" + arg.name() + ">"; - - types.append(argValue); - } - - builder.setMessage(format.replaceAll("\\{args}", String.valueOf(types))); - - String hoverShit = baseFormat.append(types).toString(); - - String hoverFormat = CrazyCore.api().commandHoverFormat(); - - builder.hover(PlaceholderSupport.setPlaceholders(hoverFormat).replaceAll("\\{commands}", hoverShit)).click(hoverShit, ClickEvent.Action.valueOf(CrazyCore.api().commandHoverAction().toUpperCase())); - - actor.reply(builder.build()); - } - - String footer = CrazyCore.api().commandHelpFooter(); - - if (actor.isPlayer()) { - String text = CrazyCore.api().commandNavigationText(); - - if (page > 1) { - int number = page-1; - - hover(actor.getPlayer(), footer.replaceAll("\\{page}", String.valueOf(page)), text.replaceAll("\\{page}", String.valueOf(number)), CrazyCore.api().commandNavigationBackButton(), "/crazycrates help " + number, ClickEvent.Action.RUN_COMMAND); - } else if (page < this.manager.getClasses().size()) { - int number = page+1; - - hover(actor.getPlayer(), footer.replaceAll("\\{page}", String.valueOf(page)), text.replaceAll("\\{page}", String.valueOf(number)), CrazyCore.api().commandNavigationNextButton(), "/crazycrates help " + number, ClickEvent.Action.RUN_COMMAND); - } - } else { - send(actor.getSender(), footer.replaceAll("\\{page}", String.valueOf(page)), false, ""); - } - } - - this.lastPage = max >= this.totalResults; - } - - public void setPage(int page) { - this.page = page; - } - - public void setPerPage(int perPage) { - this.perPage = perPage; - } - - public void setPage(int page, int perPage) { - this.setPage(page); - this.setPerPage(perPage); - } - - public int getPage() { - return this.page; - } - - public int getPerPage() { - return this.perPage; - } - - public int getTotalResults() { - return this.totalResults; - } - - public int getTotalPages() { - return this.totalPages; - } - - public boolean isLastPage() { - return this.lastPage; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/annotations/Hidden.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/annotations/Hidden.java deleted file mode 100644 index 10fe620..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/annotations/Hidden.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.annotations; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Retention(RetentionPolicy.RUNTIME) -public @interface Hidden {} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/Argument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/Argument.java deleted file mode 100644 index b8e8dd3..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/Argument.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.args; - -public record Argument(String name, int order, ArgumentType argumentType) {} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/ArgumentType.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/ArgumentType.java deleted file mode 100644 index 3de171b..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/ArgumentType.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.args; - -import java.util.List; - -public abstract class ArgumentType { - - public abstract List getPossibleValues(); - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/CommandArgs.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/CommandArgs.java deleted file mode 100644 index b769c88..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/CommandArgs.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.args; - -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -public interface CommandArgs { - - int getArgAsInt(int index, boolean notifySender); - - long getArgAsLong(int index, boolean notifySender); - - double getArgAsDouble(int index, boolean notifySender); - - boolean getArgAsBoolean(int index, boolean notifySender); - - float getArgAsFloat(int index, boolean notifySender); - - Player getArgAsPlayer(int index, boolean notifySender); - - OfflinePlayer getArgAsOfflinePlayer(int index); - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/BooleanArgument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/BooleanArgument.java deleted file mode 100644 index 7311812..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/BooleanArgument.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.args.builder; - -import com.badbones69.crazyauctions.api.frame.command.builders.args.ArgumentType; -import java.util.List; - -public class BooleanArgument extends ArgumentType { - - @Override - public List getPossibleValues() { - return List.of("true", "false"); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/DoubleArgument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/DoubleArgument.java deleted file mode 100644 index dbc4007..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/DoubleArgument.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.args.builder; - -import com.badbones69.crazyauctions.api.frame.command.builders.args.ArgumentType; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; - -public class DoubleArgument extends ArgumentType { - - private final int numberCap; - - public DoubleArgument(Integer numberCap) { - if (numberCap == null) { - this.numberCap = 100; - return; - } - - this.numberCap = numberCap; - } - - @Override - public List getPossibleValues() { - List numbers = new ArrayList<>(); - - DecimalFormat decimalFormat = new DecimalFormat("0.0"); - - for (double value = 0.1; value <= this.numberCap; value += 0.1) { - String formattedNumber = decimalFormat.format(value); - numbers.add(formattedNumber); - } - - return numbers; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/FloatArgument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/FloatArgument.java deleted file mode 100644 index 751a92e..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/FloatArgument.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.args.builder; - -import com.badbones69.crazyauctions.api.frame.command.builders.args.ArgumentType; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; - -public class FloatArgument extends ArgumentType { - - private final int numberCap; - - public FloatArgument(Integer numberCap) { - if (numberCap == null) { - this.numberCap = 100; - return; - } - - this.numberCap = numberCap; - } - - @Override - public List getPossibleValues() { - List numbers = new ArrayList<>(); - - DecimalFormat decimalFormat = new DecimalFormat("0.0f"); - - for (float value = 0.1f; value <= this.numberCap; value += 0.1f) { - String formattedValue = decimalFormat.format(value); - numbers.add(formattedValue); - } - - return numbers; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/IntArgument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/IntArgument.java deleted file mode 100644 index be72dc9..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/IntArgument.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.args.builder; - -import com.badbones69.crazyauctions.api.frame.command.builders.args.ArgumentType; -import java.util.ArrayList; -import java.util.List; - -public class IntArgument extends ArgumentType { - - private final int numberCap; - - public IntArgument(Integer numberCap) { - if (numberCap == null) { - this.numberCap = 100; - return; - } - - this.numberCap = numberCap; - } - - @Override - public List getPossibleValues() { - List numbers = new ArrayList<>(); - - for (int value = 1; value <= this.numberCap; value += 1) numbers.add(String.valueOf(value)); - - return numbers; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/custom/PlayerArgument.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/custom/PlayerArgument.java deleted file mode 100644 index 418a102..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/args/builder/custom/PlayerArgument.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.args.builder.custom; - -import com.badbones69.crazyauctions.api.frame.command.builders.args.ArgumentType; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import java.util.List; -import java.util.stream.Collectors; - -public class PlayerArgument extends ArgumentType { - - @Override - public List getPossibleValues() { - return Bukkit.getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/other/ComponentBuilder.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/other/ComponentBuilder.java deleted file mode 100644 index 8de7164..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/other/ComponentBuilder.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.other; - -import com.badbones69.crazyauctions.frame.utils.AdventureUtils; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.event.ClickEvent; -import net.kyori.adventure.text.event.HoverEvent; -import org.jetbrains.annotations.NotNull; - -public class ComponentBuilder { - - private String message; - - private final TextComponent.@NotNull Builder builder = Component.text(); - - private final PreciseComponentBuilder preciseBuilder; - - public ComponentBuilder() { - this.preciseBuilder = new PreciseComponentBuilder(); - } - - public void setMessage(String message) { - this.message = message; - } - - public ComponentBuilder append(Component component) { - this.builder.append(component); - - return this; - } - - public Component parse(String value) { - return AdventureUtils.parse(value); - } - - public ComponentBuilder hover(String hoverText) { - this.builder.hoverEvent(HoverEvent.showText(parse(hoverText))); - - return this; - } - - public ComponentBuilder click(String clickText, ClickEvent.Action action) { - this.builder.clickEvent(ClickEvent.clickEvent(action, clickText)); - - return this; - } - - public class PreciseComponentBuilder { - private final TextComponent.@NotNull Builder preciseBuilder = Component.text(); - - public PreciseComponentBuilder text(String text) { - this.preciseBuilder.append(parse(text)); - - return this; - } - - public PreciseComponentBuilder hoverText(String text, String hoverText) { - this.preciseBuilder.append(parse(text)); - this.preciseBuilder.hoverEvent(HoverEvent.showText(parse(hoverText))); - - return this; - } - - public PreciseComponentBuilder hoverText(String hoverText) { - this.preciseBuilder.hoverEvent(HoverEvent.showText(parse(hoverText))); - - return this; - } - - public PreciseComponentBuilder click(String clickText, ClickEvent.Action action) { - this.preciseBuilder.clickEvent(ClickEvent.clickEvent(action, clickText)); - - return this; - } - - public @NotNull TextComponent getPreciseBuilder() { - return this.preciseBuilder.build(); - } - } - - public PreciseComponentBuilder getPreciseComponent() { - return this.preciseBuilder; - } - - public @NotNull TextComponent build() { - Component message = AdventureUtils.parse(this.message); - - if (getPreciseComponent() != null) { - return this.builder.append(message).append(getPreciseComponent().getPreciseBuilder()).build(); - } - - return this.builder.append(message).build(); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirements.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirements.java deleted file mode 100644 index 209154c..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirements.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.reqs; - -import com.badbones69.crazyauctions.api.frame.command.CommandContext; -import com.badbones69.crazyauctions.frame.CrazyCore; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.permissions.Permission; - -public class CommandRequirements { - - private final boolean asPlayer; - private Permission permission; - private String rawPermission; - - public CommandRequirements(boolean asPlayer, Permission permission, String rawPermission) { - this.asPlayer = asPlayer; - - if (permission != null) this.permission = permission; - - if (!rawPermission.isEmpty() || !rawPermission.isBlank()) this.rawPermission = rawPermission; - } - - public boolean checkRequirements(boolean notifySender, CommandContext context) { - if (asPlayer && !context.isPlayer()) { - if (notifySender) context.reply(CrazyCore.api().commandRequirementNotPlayer()); - - // The command is not valid. - return false; - } - - // The sender is console sender so automatically valid. - if (context.getSender() instanceof ConsoleCommandSender) return true; - - if (this.permission != null && !context.hasPermission(this.permission) || this.rawPermission != null && !context.hasPermission(this.rawPermission)) { - String value = this.permission != null ? this.permission.getName() : this.rawPermission; - - if (notifySender) context.reply(CrazyCore.api().commandRequirementNoPermission().replaceAll("\\{permission}", value)); - - // The command is not valid. - return false; - } - - // The command is valid. - return true; - } - - public Permission getPermission() { - return this.permission; - } - - public String getRawPermission() { - return this.rawPermission; - } - - public boolean isPlayer() { - return this.asPlayer; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirementsBuilder.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirementsBuilder.java deleted file mode 100644 index 7e76844..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/command/builders/reqs/CommandRequirementsBuilder.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.command.builders.reqs; - -import org.bukkit.permissions.Permission; - -public class CommandRequirementsBuilder { - - private boolean asPlayer = false; - private Permission permission = null; - private String rawPermission = ""; - - public CommandRequirementsBuilder asPlayer(boolean value) { - this.asPlayer = value; - return this; - } - - public CommandRequirementsBuilder withPermission(Permission permission) { - this.permission = permission; - return this; - } - - public CommandRequirementsBuilder withOutPermission(Permission permission) { - return this; - } - - public CommandRequirementsBuilder withRawPermission(String rawPermission) { - this.rawPermission = rawPermission; - return this; - } - - public CommandRequirements build() { - return new CommandRequirements(asPlayer, permission, rawPermission); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/BaseItemBuilder.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/BaseItemBuilder.java deleted file mode 100644 index 5b4956c..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/BaseItemBuilder.java +++ /dev/null @@ -1,673 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.items; - -import com.badbones69.crazyauctions.api.frame.ItemUtils; -import com.badbones69.crazyauctions.frame.CrazyLogger; -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.TextDecoration; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.DyeColor; -import org.bukkit.FireworkEffect; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; -import org.bukkit.block.Banner; -import org.bukkit.block.banner.Pattern; -import org.bukkit.block.banner.PatternType; -import org.bukkit.enchantments.Enchantment; -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.FireworkEffectMeta; -import org.bukkit.inventory.meta.FireworkMeta; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.LeatherArmorMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.inventory.meta.SkullMeta; -import org.bukkit.inventory.meta.trim.ArmorTrim; -import org.bukkit.inventory.meta.trim.TrimMaterial; -import org.bukkit.inventory.meta.trim.TrimPattern; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionType; -import org.bukkit.util.Consumer; -import java.lang.reflect.Field; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Base64; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Objects; -import java.util.UUID; -import java.util.stream.Collectors; - -public class BaseItemBuilder> { - - private final ItemUtils SKULL_CHECKER = new ItemUtils(); - - private final GsonComponentSerializer gson = GsonComponentSerializer.gson(); - - // Core. - private ItemStack itemStack; - private ItemMeta itemMeta; - - private Material material; - - // Custom Lore. - private Field LORE_FIELD; - - // Custom Model Data. - private boolean isCustomModelData; - - private int customModelData; - - // Custom Heads. - private boolean isHead; - private Field profile; - private String texture; - - // Potions - private boolean isPotion; - private boolean isTippedArrow; - private Color potionColor; - private PotionType potionType; - - // Leather. - private boolean isLeather; - private boolean isArmor; - private TrimMaterial trimMaterial; - private TrimPattern trimPattern; - private Color armorColor; - - // Banners. - private boolean isBanner; - private List patterns; - - // Shields. - private boolean isShield; - - // Firework. - private boolean isFirework; - private boolean isFireworkStar; - - // Enchantments/Flags - private boolean isDurable; - private boolean hideFlags; - private boolean isGlowing; - - protected BaseItemBuilder() { - this.itemStack = null; - this.itemMeta = null; - this.material = Material.AIR; - this.LORE_FIELD = null; - this.isCustomModelData = false; - this.customModelData = 0; - this.isHead = false; - this.profile = null; - this.texture = ""; - this.isPotion = false; - this.isTippedArrow = false; - this.potionColor = Color.WHITE; - this.potionType = PotionType.MUNDANE; - this.isLeather = false; - this.armorColor = Color.WHITE; - this.isBanner = false; - this.patterns = Collections.emptyList(); - this.isShield = false; - this.isFirework = false; - this.isFireworkStar = false; - this.isDurable = false; - this.hideFlags = false; - this.isGlowing = false; - } - - protected BaseItemBuilder(ItemStack itemStack) { - this.itemStack = itemStack; - - try { - Class metaClass = SKULL_CHECKER.craftClass("inventory.CraftMetaItem"); - - LORE_FIELD = metaClass.getDeclaredField("lore"); - LORE_FIELD.setAccessible(true); - } catch (NoSuchFieldException | ClassNotFoundException exception) { - CrazyLogger.warn("Failed to make the lore field accessible as it was not found. Perhaps an invalid item was supplied?"); - } - - this.material = itemStack.getType(); - - switch (this.material) { - case PLAYER_HEAD -> this.isHead = true; - case POTION, SPLASH_POTION -> this.isPotion = true; - case TIPPED_ARROW -> this.isTippedArrow = true; - case LEATHER_HELMET, LEATHER_CHESTPLATE, LEATHER_LEGGINGS, LEATHER_BOOTS, LEATHER_HORSE_ARMOR -> this.isLeather = true; - case SHIELD -> this.isShield = true; - case FIREWORK_ROCKET -> this.isFirework = true; - case FIREWORK_STAR -> this.isFireworkStar = true; - } - - String name = this.material.name(); - - this.isArmor = name.endsWith("_HELMET") || name.endsWith("_CHESTPLATE") || name.endsWith("_LEGGINGS") || name.endsWith("_BOOTS"); - - // Accounts for all banners. - if (this.material.name().contains("BANNER")) this.isBanner = true; - - // if (this.material.name().contains("SPAWN_EGG")) this.isEgg = true; - - this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta() : Bukkit.getServer().getItemFactory().getItemMeta(material); - } - - public Base setDisplayName(Component displayName) { - this.itemMeta.displayName(displayName.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE)); - return (Base) this; - } - - public Base setLore(Component ... lore) { - return setLore(Arrays.asList(lore)); - } - - public Base setLore(List lore) { - List jsonLore = lore.stream().filter(Objects::nonNull).map(this.gson::serialize).toList(); - - try { - LORE_FIELD.set(this.itemMeta, jsonLore); - } catch (IllegalAccessException exception) { - exception.printStackTrace(); - } - - return (Base) this; - } - - public Base addLore(Consumer> lore) { - List components; - - try { - List jsonLore = (List) LORE_FIELD.get(this.itemMeta); - - components = (jsonLore == null) ? new ArrayList<>() : jsonLore.stream().map(this.gson::deserialize).collect(Collectors.toList()); - } catch (Exception exception) { - components = new ArrayList<>(); - exception.printStackTrace(); - } - - lore.accept(components); - return (Base) this; - } - - public Base setAmount(int amount) { - this.itemStack.setAmount(amount); - return (Base) this; - } - - public Base addEnchantment(Enchantment enchantment, int level, boolean ignoreLevelRestriction) { - this.itemMeta.addEnchant(enchantment, level, ignoreLevelRestriction); - return (Base) this; - } - - public Base removeEnchantment(Enchantment enchantment) { - this.itemMeta.removeEnchant(enchantment); - return (Base) this; - } - - public Base setEnchantments(HashMap enchantments, boolean ignoreLevelRestriction) { - enchantments.forEach((enchantment, integer) -> this.itemMeta.addEnchant(enchantment, integer, ignoreLevelRestriction)); - return (Base) this; - } - - public Base addPatterns(List patterns) { - patterns.forEach(this::addPatterns); - return (Base) this; - } - - public Base addPattern(Pattern pattern) { - this.patterns.add(pattern); - return (Base) this; - } - - public Base setPattern(List patterns) { - this.patterns = patterns; - return (Base) this; - } - - public Base addItemFlags(List flags) { - flags.forEach(flag -> { - try { - ItemFlag itemFlag = ItemFlag.valueOf(flag.toUpperCase()); - - addItemFlag(itemFlag); - } catch (Exception exception) { - CrazyLogger.warn("Failed to add item flag: " + flag + ". The flag is invalid!"); - } - }); - - return (Base) this; - } - - public Base setTexture(String texture) { - this.texture = texture; - - return (Base) this; - } - - public Base setValue(String material) { - if (material == null || material.isEmpty()) { - CrazyLogger.warn("Material cannot be null or empty, Output: " + material + "."); - CrazyLogger.warn("Please take a screenshot of this before asking for support."); - - return (Base) this; - } - - String metaData; - - if (isPotion || isTippedArrow) { - if (material.contains(";")) { - String[] section = material.split(";"); - - String[] sectionOne = section[0].split(":"); - String[] sectionTwo = section[1].split(":"); - - try { - this.potionType = PotionType.valueOf(sectionOne[1]); - } catch (Exception exception) { - CrazyLogger.warn("Failed to set potion type " + sectionOne[1] + ". The potion type inputted is invalid."); - } - - this.potionColor = getColor(sectionTwo[1]); - } - - return (Base) this; - } - - if (material.contains(":")) { // Sets the durability or another value option. - String[] materialSplit = material.split(":"); - - material = materialSplit[0]; - metaData = materialSplit[1]; - - if (metaData.contains("#")) { // :# - String modelData = metaData.split("#")[1]; - - if (isValidInteger(modelData)) { - this.isCustomModelData = true; - this.customModelData = Integer.parseInt(modelData); - } - } - - metaData = metaData.replace("#" + customModelData, ""); - - if (isValidInteger(metaData)) { // Value is durability. - int damage = Integer.parseInt(metaData); - - if (this.itemMeta instanceof Damageable) ((Damageable) this.itemMeta).setDamage(damage); - } else { // Value is something else. - if (isPotion) { - this.potionType = PotionType.valueOf(metaData); - - if (getColor(metaData) != null) this.potionColor = getColor(metaData); - } - - if (isLeather) this.armorColor = getColor(metaData); - } - } else if (material.contains("#")) { - String[] materialSplit = material.split("#"); - material = materialSplit[0]; - - if (isValidInteger(materialSplit[1])) { // Value is a number. - this.isCustomModelData = true; - this.customModelData = Integer.parseInt(materialSplit[1]); - } - } - - Material matchedMaterial = Material.matchMaterial(material); - - if (matchedMaterial != null) this.material = matchedMaterial; - - if (this.isArmor) ((ArmorMeta) itemMeta).setTrim(new ArmorTrim(this.trimMaterial, this.trimPattern)); - - this.itemStack.setType(this.material); - - setItemMeta(this.itemStack.getItemMeta()); - - return (Base) this; - } - - public Base hideFlags(boolean hideFlags) { - this.hideFlags = hideFlags; - return (Base) this; - } - - public Base setGlow(boolean isGlowing) { - this.isGlowing = isGlowing; - return (Base) this; - } - - public Base setTrim(TrimMaterial trimMaterial, TrimPattern trimPattern) { - this.trimMaterial = trimMaterial; - this.trimPattern = trimPattern; - - return (Base) this; - } - - public Base setDurable(boolean isDurable) { - this.isDurable = isDurable; - return (Base) this; - } - - public Base setEffect(FireworkEffect... effects) { - return setEffect(Arrays.asList(effects)); - } - - public Base setEffect(List effects) { - if (effects.isEmpty()) return (Base) this; - - if (this.isFireworkStar) { - FireworkEffectMeta effectMeta = (FireworkEffectMeta) this.getItemMeta(); - - effectMeta.setEffect(effects.get(0)); - this.setItemMeta(effectMeta); - } - - if (this.isFirework) { - FireworkMeta fireworkMeta = (FireworkMeta) this.getItemMeta(); - - fireworkMeta.addEffects(effects); - this.setItemMeta(fireworkMeta); - } - - return (Base) this; - } - - public Base setPower(int power) { - if (this.isFirework) { - FireworkMeta fireworkMeta = (FireworkMeta) this.getItemMeta(); - - fireworkMeta.setPower(power); - - this.setItemMeta(fireworkMeta); - } - - return (Base) this; - } - - public ItemStack build() { - if (this.material != Material.AIR) { - if (this.isHead) { - // Set the field to accessible. - exposeField(); - - setPlayerTexture(this.texture); - } - - if (this.isPotion || this.isTippedArrow && (this.potionType != null || this.potionColor != null)) { - PotionMeta potionMeta = (PotionMeta) this.itemMeta; - - if (this.potionType != null) potionMeta.setBasePotionData(new PotionData(this.potionType)); - - if (this.potionColor != null) potionMeta.setColor(this.potionColor); - - this.setItemMeta(potionMeta); - } - - if (this.isLeather && this.armorColor != null) { - LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) this.itemMeta; - leatherArmorMeta.setColor(this.armorColor); - } - - if (this.isBanner && !this.patterns.isEmpty()) { - BannerMeta bannerMeta = (BannerMeta) this.itemMeta; - bannerMeta.setPatterns(this.patterns); - } - - if (this.isShield && !this.patterns.isEmpty()) { - BlockStateMeta shieldMeta = (BlockStateMeta) this.itemMeta; - Banner banner = (Banner) shieldMeta.getBlockState(); - - banner.setPatterns(this.patterns); - banner.update(); - - shieldMeta.setBlockState(banner); - } - - if (this.isCustomModelData) this.itemMeta.setCustomModelData(this.customModelData); - - if (this.hideFlags) this.itemMeta.addItemFlags(ItemFlag.values()); - - this.itemMeta.setUnbreakable(this.isDurable); - - this.addGlow(); - } else { - CrazyLogger.warn("Material cannot be AIR."); - } - - this.itemStack.setItemMeta(this.itemMeta); - - return this.itemStack; - } - - private void addItemFlag(ItemFlag itemFlag) { - this.itemMeta.addItemFlags(itemFlag); - } - - private void setPlayerTexture(String texture) { - this.texture = texture; - - Player player = Bukkit.getServer().getPlayer(this.texture); - - if (player != null) { - setOwner(player); - return; - } - - if (this.texture.startsWith("http")) { - setTexture(convert(this.texture), UUID.randomUUID()); - return; - } - - setTexture(this.texture, UUID.randomUUID()); - } - - private void setOwner(OfflinePlayer player) { - if (this.SKULL_CHECKER.isPlayerSkull(this.material)) return; - - SkullMeta skullMeta = (SkullMeta) this.getItemMeta(); - - skullMeta.setOwningPlayer(player); - - this.setItemMeta(skullMeta); - } - - private void addGlow() { - if (this.isGlowing) { - if (this.itemMeta.hasEnchants()) return; - - this.itemMeta.addEnchant(Enchantment.LUCK, 1, false); - - this.setItemMeta(this.itemMeta); - } - } - - private void exposeField() { - if (this.SKULL_CHECKER.isPlayerSkull(this.material)) return; - - Field field; - - try { - SkullMeta skullMeta = (SkullMeta) this.SKULL_CHECKER.skull().getItemMeta(); - field = skullMeta.getClass().getDeclaredField("profile"); - - field.setAccessible(true); - } catch (NoSuchFieldException exception) { - CrazyLogger.warn("Failed to make the meta field for profile accessible as it was not found. Perhaps an invalid item meta or field supplied?"); - - field = null; - } - - this.profile = field; - } - - private boolean isValidInteger(String value) { - try { - Integer.parseInt(value); - } catch (NumberFormatException exception) { - return false; - } - - return true; - } - - private Color getColor(String color) { - if (color != null) { - switch (color.toUpperCase()) { - case "AQUA" -> { - return Color.AQUA; - } - case "BLACK" -> { - return Color.BLACK; - } - case "BLUE" -> { - return Color.BLUE; - } - case "FUCHSIA" -> { - return Color.FUCHSIA; - } - case "GRAY" -> { - return Color.GRAY; - } - case "GREEN" -> { - return Color.GREEN; - } - case "LIME" -> { - return Color.LIME; - } - case "MAROON" -> { - return Color.MAROON; - } - case "NAVY" -> { - return Color.NAVY; - } - case "OLIVE" -> { - return Color.OLIVE; - } - case "ORANGE" -> { - return Color.ORANGE; - } - case "PURPLE" -> { - return Color.PURPLE; - } - case "RED" -> { - return Color.RED; - } - case "SILVER" -> { - return Color.SILVER; - } - case "TEAL" -> { - return Color.TEAL; - } - case "WHITE" -> { - return Color.WHITE; - } - case "YELLOW" -> { - return Color.YELLOW; - } - } - - try { - String[] rgb = color.split(","); - return Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2])); - } catch (Exception ignore) {} - } - - return null; - } - - 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 = getDyeColor(split[1]); - - if (color != null) this.addPattern(new Pattern(color, pattern)); - - break; - } - } - } catch (Exception ignored) {} - } - - public DyeColor getDyeColor(String color) { - if (color != null) { - try { - return DyeColor.valueOf(color.toUpperCase()); - } catch (Exception exception) { - try { - String[] rgb = color.split(","); - return DyeColor.getByColor(Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]))); - } catch (Exception ignore) {} - } - } - - return null; - } - - private void setTexture(String texture, UUID uuid) { - if (this.SKULL_CHECKER.isPlayerSkull(this.material)) return; - - if (this.profile == null) return; - - SkullMeta skullMeta = (SkullMeta) this.itemMeta; - GameProfile gameProfile = new GameProfile(uuid, null); - - gameProfile.getProperties().put("textures", new Property("textures", texture)); - - try { - this.profile.set(skullMeta, gameProfile); - } catch (Exception exception) { - CrazyLogger.warn("Failed to set the meta & game profile. Perhaps an invalid texture?"); - CrazyLogger.warn("Your Input: " + texture + "."); - } - - setItemMeta(skullMeta); - } - - private String convert(String url) { - URL actualLink; - - try { - actualLink = new URL(url); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - - String encode = "{\"textures\":{\"SKIN\":{\"url\":\"" + actualLink + "\"}}}"; - - return Base64.getEncoder().encodeToString(encode.getBytes()); - } - - // Protected getters for extended builders. - protected ItemStack getItemStack() { - return this.itemStack; - } - - protected void setItemStack(ItemStack itemStack) { - this.itemStack = itemStack; - } - - protected ItemMeta getItemMeta() { - return this.itemMeta; - } - - protected void setItemMeta(ItemMeta itemMeta) { - this.itemMeta = itemMeta; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemBuilder.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemBuilder.java deleted file mode 100644 index 4c6d422..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemBuilder.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.items; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -public class ItemBuilder extends BaseItemBuilder { - - public ItemBuilder() { - super(); - } - - public ItemBuilder(ItemStack itemStack) { - super(itemStack); - } - - public static ItemBuilder setStack(ItemStack itemStack) { - return new ItemBuilder(itemStack); - } - - public static ItemBuilder setMaterial(Material material) { - return new ItemBuilder(new ItemStack(material)); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemNbt.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemNbt.java deleted file mode 100644 index f4ce10f..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/frame/items/ItemNbt.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.badbones69.crazyauctions.api.frame.items; - -import org.bukkit.NamespacedKey; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataType; -import org.bukkit.plugin.java.JavaPlugin; - -public class ItemNbt { - - private final JavaPlugin plugin; - - public ItemNbt(JavaPlugin plugin) { - this.plugin = plugin; - } - - public ItemStack setString(ItemStack itemStack, String key, String value) { - ItemMeta meta = itemStack.getItemMeta(); - - if (meta == null) return null; - - meta.getPersistentDataContainer().set(new NamespacedKey(this.plugin, key), PersistentDataType.STRING, value); - itemStack.setItemMeta(meta); - - return itemStack; - } - - public String getString(ItemStack itemStack, String key) { - ItemMeta meta = itemStack.getItemMeta(); - - if (meta == null) return null; - - return meta.getPersistentDataContainer().get(new NamespacedKey(this.plugin, key), PersistentDataType.STRING); - } - - public ItemStack setBoolean(ItemStack itemStack, String key, boolean value) { - ItemMeta meta = itemStack.getItemMeta(); - - if (meta == null) return null; - - meta.getPersistentDataContainer().set(new NamespacedKey(this.plugin, key), PersistentDataType.BOOLEAN, value); - itemStack.setItemMeta(meta); - - return itemStack; - } - - public ItemStack removeTag(ItemStack itemStack, String key) { - ItemMeta meta = itemStack.getItemMeta(); - - if (meta == null) return null; - - meta.getPersistentDataContainer().remove(new NamespacedKey(this.plugin, key)); - itemStack.setItemMeta(meta); - - return itemStack; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/enums/AuctionType.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/enums/AuctionType.java deleted file mode 100644 index ada77c8..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/enums/AuctionType.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.badbones69.crazyauctions.api.manager.enums; - -/** - * Description: Defines the auction type to use - */ -public enum AuctionType { - - BID("Bid"), - SELL("Sell"); - - private final String name; - - AuctionType(String name) { - this.name = name; - } - - public static AuctionType getTypeFromName(String name) { - for (AuctionType type : AuctionType.values()) { - if (type.getName().equalsIgnoreCase(name)) return type; - } - - return null; - } - - public String getName() { - return this.name; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/interfaces/AuctionItem.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/interfaces/AuctionItem.java deleted file mode 100644 index d365f3f..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/interfaces/AuctionItem.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.badbones69.crazyauctions.api.manager.interfaces; - -import com.badbones69.crazyauctions.api.manager.enums.AuctionType; -import org.bukkit.inventory.ItemStack; -import java.util.UUID; - -public interface AuctionItem { - - UUID auctionID = UUID.randomUUID(); - - default UUID getAuctionID() { - return auctionID; - } - - AuctionType getAuctionType(); - - UUID getSeller(); - - long getPrice(); - - long getExpireTime(); - - ItemStack getSellingItem(); - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionButtons.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionButtons.java deleted file mode 100644 index 761622f..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionButtons.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.badbones69.crazyauctions.api.manager.objects; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.plugin.java.JavaPlugin; - -public class AuctionButtons { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - /* - private final ItemBuilder sellingItemsButton; - private final ItemBuilder sellingInfoButton; - private final ItemBuilder biddingInfoButton; - private final ItemBuilder currentListingsInfoButton; - private final ItemBuilder expiredItemsButton; - private final ItemBuilder expiredInfoButton; - private final ItemBuilder categoriesButton; - private final ItemBuilder categoriesInfoButton; - private final ItemBuilder nextPageButton; - private final ItemBuilder refreshPageButton; - private final ItemBuilder backPageButton; - private final ItemBuilder switchModeButton; - - public AuctionButtons(FileConfiguration file) { - String path = "auction-house.settings.buttons."; - sellingItemsButton = ItemUtils.convertString(file.getString(path + "selling-items")); - sellingInfoButton = ItemUtils.convertString(file.getString(path + "info.selling-items")); - biddingInfoButton = ItemUtils.convertString(file.getString(path + "info.bidding")); - currentListingsInfoButton = ItemUtils.convertString(file.getString(path + "info.current-listings")); - expiredItemsButton = ItemUtils.convertString(file.getString(path + "expired-items")); - expiredInfoButton = ItemUtils.convertString(file.getString(path + "info.expired-items")); - categoriesButton = ItemUtils.convertString(file.getString(path + "categories")); - categoriesInfoButton = ItemUtils.convertString(file.getString(path + "info.categories")); - nextPageButton = ItemUtils.convertString(file.getString(path + "next-page")); - refreshPageButton = ItemUtils.convertString(file.getString(path + "refresh-page")); - backPageButton = ItemUtils.convertString(file.getString(path + "back-page")); - switchModeButton = ItemUtils.convertString(file.getString(path + "switch-mode")); - } - - - public ItemBuilder getSellingItemsButton() { - return sellingItemsButton; - } - - public ItemBuilder getSellingInfoButton() { - return sellingInfoButton; - } - - public ItemBuilder getBiddingInfoButton() { - return biddingInfoButton; - } - - public ItemBuilder getCurrentListingsInfoButton() { - return currentListingsInfoButton; - } - - public ItemBuilder getExpiredItemsButton() { - return expiredItemsButton; - } - - public ItemBuilder getExpiredInfoButton() { - return expiredInfoButton; - } - - public ItemBuilder getCategoriesButton() { - return categoriesButton; - } - - public ItemBuilder getCategoriesInfoButton() { - return categoriesInfoButton; - } - - public ItemBuilder getNextPageButton() { - return nextPageButton; - } - - public ItemBuilder getRefreshPageButton() { - return refreshPageButton; - } - - public ItemBuilder getBackPageButton() { - return backPageButton; - } - - public ItemBuilder getSwitchModeButton() { - return switchModeButton; - }*/ -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionCategory.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionCategory.java deleted file mode 100644 index 5b63411..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionCategory.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.badbones69.crazyauctions.api.manager.objects; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.api.frame.items.ItemBuilder; -import org.bukkit.Material; -import org.bukkit.plugin.java.JavaPlugin; -import java.util.List; - -/** - * Description: Creates the auction categories - */ -public class AuctionCategory { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private String name; - private int slot; - //private ItemBuilder displayItem; - private List categoryItemList; - - //TODO make it so each AH can have their own categories and the default ones should be able to be disabled. - public AuctionCategory(String name, int slot, ItemBuilder displayItem, List categoryItemList) { - this.name = name; - this.slot = slot; - //this.displayItem = displayItem; - this.categoryItemList = categoryItemList; - } - - public String getName() { - return name; - } - - public int getSlot() { - return slot; - } - - //public ItemBuilder getDisplayItem() { - // return displayItem; - //} - - public List getCategoryItemList() { - return categoryItemList; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionHouse.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionHouse.java deleted file mode 100644 index e0b3727..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/AuctionHouse.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.badbones69.crazyauctions.api.manager.objects; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.api.manager.enums.AuctionType; -import com.badbones69.crazyauctions.api.manager.interfaces.AuctionItem; -import com.badbones69.crazyauctions.api.manager.objects.auctiontype.BiddingAuction; -import com.badbones69.crazyauctions.api.manager.objects.auctiontype.SellingAuction; -import com.badbones69.crazyauctions.api.events.AuctionAddEvent; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.plugin.java.JavaPlugin; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -/** - * Description: Creates the main auction house menu - */ -public class AuctionHouse { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private String name; - private FileConfiguration auctionFile; - private InventorySettings inventorySettings; - private List auctionItems = new ArrayList<>(); - private List auctionCategories = new ArrayList<>(); - - public AuctionHouse(FileConfiguration file) { - this.name = file.getString("auction-house.settings.name"); - this.auctionFile = file; - this.inventorySettings = new InventorySettings(file); - //Loads the auction house listings into the auction house. - //TODO this needs to be moved to a seperated data file that doesnt hold all the auction house settings. - for (String auctionID : file.getConfigurationSection("auction-house.item-on-auction").getKeys(false)) { - String path = "auction-house.item-on-auction" + auctionID + "."; - AuctionType auctionType = AuctionType.getTypeFromName(file.getString(path + "auction-type")); - if (auctionType == AuctionType.SELL) { - auctionItems.add(new SellingAuction( - UUID.fromString(file.getString(path + "seller-uuid")), - file.getLong(path + "price"), - file.getLong(path + "expire-time"), - file.getItemStack(path + "selling-item"))); - } else { - auctionItems.add(new BiddingAuction( - UUID.fromString(file.getString(path + "seller-uuid")), - UUID.fromString(file.getString(path + "highest-bidder-uuid")), - file.getLong(path + "price"), - file.getLong(path + "current-bid"), - file.getLong(path + "expire-time"), - file.getItemStack(path + "selling-item"))); - } - } - //Loads the category items into the auction house. - //TODO Need to add the default categories like isPotion, isArmor, isFood, Ect... - //for (String category : file.getConfigurationSection("auction-house.categories").getKeys(false)) { - // String path = "auction-house.categories." + category + "."; - // auctionCategories.add(new AuctionCategory( - // category, - // file.getInt(path + "slot"), - //ItemUtils.convertString(file.getString(path + "item")), - //file.getStringList(path + "items").stream().map(Material :: matchMaterial).collect(Collectors.toList()))); - //} - } - - public String getName() { - return name; - } - - public FileConfiguration getAuctionFile() { - return auctionFile; - } - - public InventorySettings getInventorySettings() { - return inventorySettings; - } - - public List getAuctionItems() { - return auctionItems; - } - - public long getAuctionCount(AuctionType auctionType) { - return auctionItems.stream().filter(auctionItem -> auctionType == auctionItem.getAuctionType()).count(); - } - - public void addAuctionItem(AuctionItem auctionItem) { - auctionItems.add(auctionItem); - AuctionAddEvent event = new AuctionAddEvent(auctionItem.getSeller(), this, auctionItem); - Bukkit.getServer().getPluginManager().callEvent(event); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/InventorySettings.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/InventorySettings.java deleted file mode 100644 index 3170b66..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/InventorySettings.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.badbones69.crazyauctions.api.manager.objects; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.plugin.java.JavaPlugin; - -/** - * Description: Creates the auction house inventory settings - */ -public class InventorySettings { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private final String title; - private final AuctionButtons auctionButtons = null; - - public InventorySettings(FileConfiguration file) { - String path = "auction-house.settings."; - this.title = file.getString(path + "inventory-title"); - //this.auctionButtons = new AuctionButtons(file); - } - - public String getTitle() { - return title; - } - - public AuctionButtons getAuctionButtons() { - return auctionButtons; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/BiddingAuction.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/BiddingAuction.java deleted file mode 100644 index 14ede86..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/BiddingAuction.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.badbones69.crazyauctions.api.manager.objects.auctiontype; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.api.manager.enums.AuctionType; -import com.badbones69.crazyauctions.api.manager.interfaces.AuctionItem; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; -import java.util.UUID; - -/** - * Description: Creates the bidding auction type - */ -public class BiddingAuction implements AuctionItem { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - AuctionType auctionType = AuctionType.BID; - UUID seller; - UUID highestBidder; - long price; - long currentBid; - long expireTime; - ItemStack sellingItem; - - public BiddingAuction(UUID seller, UUID highestBidder, long price, long currentBid, long expireTime, ItemStack sellingItem) { - this.seller = seller; - this.highestBidder = highestBidder; - this.price = price; - this.currentBid = 0; - this.expireTime = expireTime; - this.sellingItem = sellingItem; - } - - @Override - public AuctionType getAuctionType() { - return auctionType; - } - - @Override - public UUID getSeller() { - return seller; - } - - public UUID getHighestBidder() { - return highestBidder; - } - - public void setHighestBidder(UUID highestBidder) { - this.highestBidder = highestBidder; - } - - @Override - public long getPrice() { - return price; - } - - public long getCurrentBid() { - return currentBid; - } - - public void setCurrentBid(long currentBid) { - this.currentBid = currentBid; - } - - @Override - public long getExpireTime() { - return expireTime; - } - - @Override - public ItemStack getSellingItem() { - return sellingItem; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/SellingAuction.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/SellingAuction.java deleted file mode 100644 index 12a2578..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/api/manager/objects/auctiontype/SellingAuction.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.badbones69.crazyauctions.api.manager.objects.auctiontype; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.api.manager.enums.AuctionType; -import com.badbones69.crazyauctions.api.manager.interfaces.AuctionItem; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; -import java.util.UUID; - -/** - * Description: Creates the selling auction type - */ -public class SellingAuction implements AuctionItem { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - AuctionType auctionType = AuctionType.SELL; - UUID seller; - long price; - long expireTime; - ItemStack sellingItem; - - public SellingAuction(UUID seller, long price, long expireTime, ItemStack sellingItem) { - this.seller = seller; - this.price = price; - this.expireTime = expireTime; - this.sellingItem = sellingItem; - } - - @Override - public AuctionType getAuctionType() { - return auctionType; - } - - @Override - public UUID getSeller() { - return seller; - } - - @Override - public long getPrice() { - return price; - } - - @Override - public long getExpireTime() { - return expireTime; - } - - @Override - public ItemStack getSellingItem() { - return sellingItem; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/AuctionCommand.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/AuctionCommand.java deleted file mode 100644 index 68135c4..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/AuctionCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.badbones69.crazyauctions.commands; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.api.frame.command.CommandContext; -import com.badbones69.crazyauctions.api.frame.command.CommandEngine; -import org.bukkit.plugin.java.JavaPlugin; -import java.util.Collections; - -public class AuctionCommand extends CommandEngine { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - protected AuctionCommand() { - super("auctions", "Opens the auction house", "/crazyauctions:auctions", Collections.emptyList()); - } - - @Override - protected void perform(CommandContext context, String[] args) { - - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/admin/CommandReload.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/admin/CommandReload.java deleted file mode 100644 index bd2479d..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/admin/CommandReload.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.badbones69.crazyauctions.commands.admin; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.api.CrazyManager; -import com.badbones69.crazyauctions.api.frame.command.CommandContext; -import com.badbones69.crazyauctions.api.frame.command.CommandEngine; -import org.bukkit.plugin.java.JavaPlugin; -import java.util.Collections; - -public class CommandReload extends CommandEngine { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - private final CrazyManager crazyManager = this.plugin.getCrazyManager(); - - public CommandReload() { - super("reload", "Reloads the plugin.", "/crazyauctions:reload", Collections.emptyList()); - } - - @Override - protected void perform(CommandContext context, String[] args) { - this.crazyManager.reload(); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventory.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventory.java deleted file mode 100644 index a96c988..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventory.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.badbones69.crazyauctions.commands.inventories; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; - -public class AuctionInventory implements InventoryHolder { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private final Inventory inventory; - - public AuctionInventory() { - this.inventory = plugin.getServer().createInventory(this, 9); - } - - @Override - public @NotNull Inventory getInventory() { - return this.inventory; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventoryClick.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventoryClick.java deleted file mode 100644 index fb49a6c..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/commands/inventories/AuctionInventoryClick.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.badbones69.crazyauctions.commands.inventories; - -import com.badbones69.crazyauctions.api.frame.items.ItemBuilder; -import com.badbones69.crazyauctions.frame.utils.AdventureUtils; -import org.bukkit.Material; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -public class AuctionInventoryClick implements Listener { - - @EventHandler - public void onAuctionClick(InventoryClickEvent event) { - Inventory inventory = event.getClickedInventory(); - - if (inventory == null || (!(inventory.getHolder() instanceof AuctionInventory auctionInventory))) return; - - event.setCancelled(true); - - ItemStack clicked = event.getCurrentItem(); - - if (clicked != null) { - event.getWhoClicked().sendMessage("Beep Boo Boo Beep!"); - - ItemBuilder builder = ItemBuilder.setStack(new ItemStack(Material.DIAMOND_SWORD)); - - builder.setAmount(3); - builder.setDisplayName(AdventureUtils.parse("This is a test")); - - auctionInventory.getInventory().addItem(builder.build()); - } - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/events/DataListener.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/events/DataListener.java deleted file mode 100644 index 5d230ae..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/events/DataListener.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.badbones69.crazyauctions.events; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.storage.interfaces.UserManager; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.plugin.java.JavaPlugin; - -public class DataListener implements Listener { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private final UserManager userManager = this.plugin.getCrazyManager().getStorageManager().getUserManager(); - - @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) - public void onPlayerJoin(PlayerJoinEvent event) { - this.userManager.load(event.getPlayer().getUniqueId()); - } - - @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) - public void onPlayerQuit(PlayerQuitEvent event) { - this.userManager.saveSingular(event.getPlayer().getUniqueId(), true); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/interfaces/UserManager.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/interfaces/UserManager.java deleted file mode 100644 index fd76a9a..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/interfaces/UserManager.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.badbones69.crazyauctions.storage.interfaces; - -import com.badbones69.crazyauctions.frame.storage.enums.StorageType; -import com.badbones69.crazyauctions.storage.objects.UserData; -import java.io.File; -import java.nio.file.Path; -import java.util.Map; -import java.util.UUID; - -public interface UserManager { - - void load(UUID uuid); - - void saveSingular(UUID uuid, boolean serverExit); - - void save(boolean serverExit); - - void convert(File file, UUID uuid, StorageType storageType); - - void addAuction(UUID uuid); - - File getFile(Path path, UUID uuid); - - UserData getUser(UUID uuid); - - Map getUsers(); - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/objects/UserData.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/objects/UserData.java deleted file mode 100644 index e39dc32..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/objects/UserData.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.badbones69.crazyauctions.storage.objects; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -public class UserData { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private final UUID uuid; - - private ConcurrentHashMap auctionData = new ConcurrentHashMap<>(); - - public UserData(UUID uuid) { - this.uuid = uuid; - } - - public Player getPlayer() { - return this.plugin.getServer().getPlayer(this.uuid); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/StorageManager.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/StorageManager.java deleted file mode 100644 index c978530..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/StorageManager.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.badbones69.crazyauctions.storage.types; - -import com.badbones69.crazyauctions.storage.interfaces.UserManager; -import com.badbones69.crazyauctions.storage.types.file.yaml.YamlUserManager; - -public class StorageManager { - - private UserManager userManager; - - public void init() { - this.userManager = new YamlUserManager(); - } - - public UserManager getUserManager() { - return this.userManager; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/file/yaml/YamlUserManager.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/file/yaml/YamlUserManager.java deleted file mode 100644 index 5fc8f73..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/storage/types/file/yaml/YamlUserManager.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.badbones69.crazyauctions.storage.types.file.yaml; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.frame.storage.enums.StorageType; -import com.badbones69.crazyauctions.storage.interfaces.UserManager; -import com.badbones69.crazyauctions.storage.objects.UserData; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collections; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -public class YamlUserManager extends YamlConfiguration implements UserManager { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private final ConcurrentHashMap userData = new ConcurrentHashMap<>(); - - public YamlUserManager() { - - } - - @Override - public void load(UUID uuid) { - try { - File file = new File(this.plugin.getDataFolder() + "/users/" + uuid + ".yml"); - - if (!file.exists()) file.createNewFile(); - - load(file); - } catch (IOException | InvalidConfigurationException e) { - e.printStackTrace(); - } - } - - @Override - public void saveSingular(UUID uuid, boolean serverExit) { - // If user data empty return. - if (this.userData.isEmpty()) return; - - // Check if user data contains keys. - if (this.userData.containsKey(uuid)) { - // Remove user when done. - this.userData.remove(uuid); - - // Save the file then load the changes back in. - reload(uuid, serverExit); - } - } - - private void reload(UUID uuid, boolean serverExit) { - try { - File file = new File(this.plugin.getDataFolder() + "/users/" + uuid + ".yml"); - - save(file); - - if (!serverExit) load(uuid); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void save(boolean serverExit) { - // If user data empty return. - if (this.userData.isEmpty()) return; - - // If the player is not leaving, continue here as we are stopping the server or doing periodic save. - this.userData.forEach((id, user) -> { - //user.getKeys().forEach((crateMap, keys) -> set("users." + id + "." + crateMap, keys)); - - // Save the file then load the changes back in. - reload(id, serverExit); - }); - } - - @Override - public void convert(File file, UUID uuid, StorageType storageType) { - - } - - @Override - public void addAuction(UUID uuid) { - Player player = this.plugin.getServer().getPlayer(uuid); - } - - @Override - public File getFile(Path path, UUID uuid) { - return new File(this.plugin.getDataFolder() + "/users/" + uuid + ".yml"); - } - - @Override - public UserData getUser(UUID uuid) { - Player player = this.plugin.getServer().getPlayer(uuid); - - // Return with their user data. - return this.userData.get(uuid); - } - - @Override - public Map getUsers() { - return Collections.unmodifiableMap(this.userData); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/PlaceholderSupport.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/PlaceholderSupport.java deleted file mode 100644 index 3aef78e..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/PlaceholderSupport.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.badbones69.crazyauctions.support; - -import com.badbones69.crazyauctions.ApiManager; -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.config.types.PluginConfig; -import org.bukkit.plugin.java.JavaPlugin; - -public class PlaceholderSupport { - - private static final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - public static String setPlaceholders(String placeholder) { - placeholder = placeholder.replaceAll("\\{prefix}", ApiManager.getPluginConfig().getProperty(PluginConfig.COMMAND_PREFIX)); - - return placeholder; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/Currency.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/Currency.java deleted file mode 100644 index 046c464..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/Currency.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.badbones69.crazyauctions.support.economy; - -/** - * Description: This event is fired when an item is added to an auction house. - */ -public enum Currency { - - VAULT("Vault"), - XP_LEVEL("XP_Level"), - XP_TOTAL("XP_Total"); - - private final String name; - - Currency(String name) { - this.name = name; - } - - /** - * Checks if it is a compatible currency. - * @param currency The currency name you are checking. - * @return True if it is supported and false if not. - */ - public static boolean isCurrency(String currency) { - for (Currency value : Currency.values()) { - if (currency.equalsIgnoreCase(value.getName())) return true; - } - - return false; - } - - /** - * Get a currency enum. - * @param currency The currency you want. - * @return The currency enum. - */ - public static Currency getCurrency(String currency) { - for (Currency value : Currency.values()) { - if (currency.equalsIgnoreCase(value.getName())) return value; - } - - return null; - } - - /** - * Get the name of the currency. - * @return The name of the currency. - */ - public String getName() { - return name; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/CurrencyAPI.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/CurrencyAPI.java deleted file mode 100644 index ab92b20..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/CurrencyAPI.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.badbones69.crazyauctions.support.economy; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import java.util.UUID; - -/** - * Description: Defines what currency to use. - */ -public class CurrencyAPI { - - // TODO() Add item support as a currency. - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - /** - * Get the amount that a player has from a specific currency. - * - * @param uuid - The uuid of the player. - * @param currency - The currency you wish to get from. - * @return amount that the player has of that currency. - */ - public int getCurrency(UUID uuid, Currency currency) { - try { - OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(uuid); - Player player = plugin.getServer().getPlayer(uuid); - - switch (currency) { - case VAULT: //if (player != null) return (int) plugin.getVaultSupport().getVault().getBalance(player); - - case XP_LEVEL: if (player != null) return player.getLevel(); - - case XP_TOTAL: if (player != null) return getTotalExperience(player); - } - } catch (Exception | NoClassDefFoundError ignored) {} - return 0; - } - - /** - * Take an amount from a player's currency. - * - * @param uuid - The uuid of the player. - * @param currency - The currency you wish to use. - * @param amount - The amount you want to take. - */ - public void takeCurrency(UUID uuid, Currency currency, int amount) { - try { - Player player = plugin.getServer().getPlayer(uuid); - - switch (currency) { - //case VAULT: if (player != null) plugin.getVaultSupport().getVault().withdrawPlayer(player, amount); - case XP_LEVEL: if (player != null) player.setLevel(player.getLevel() - amount); - case XP_TOTAL: if (player != null) takeTotalExperience(player, amount); - } - } catch (Exception | NoClassDefFoundError ignored) {} - } - - /** - * Give an amount to a player's currency. - * - * @param uuid - The uuid of the player. - * @param currency - The currency you want to use. - * @param amount - The amount you are giving to the player. - */ - public void giveCurrency(UUID uuid, Currency currency, int amount) { - try { - Player player = plugin.getServer().getPlayer(uuid); - - switch (currency) { - //case VAULT: if (player != null) plugin.getVaultSupport().getVault().depositPlayer(player, amount); - case XP_LEVEL: if (player != null) player.setLevel(player.getLevel() + amount); - case XP_TOTAL: if (player != null) takeTotalExperience(player, -amount); - } - } catch (Exception | NoClassDefFoundError ignored) {} - } - - /** - * Checks if the player has enough of a currency. - * - * @param uuid - The uuid of the player. - * @param currency The currency you wish to check. - * @param cost The cost of the item you are checking. - * @return true if they have enough to buy it or false if they don't. - */ - public boolean canBuy(UUID uuid, Currency currency, int cost) { - return getCurrency(uuid, currency) >= cost; - } - - private void takeTotalExperience(Player player, int amount) { - int total = getTotalExperience(player) - amount; - player.setTotalExperience(0); - player.setTotalExperience(total); - player.setLevel(0); - player.setExp(0); - - while (total > player.getExpToLevel()) { - total -= player.getExpToLevel(); - player.setLevel(player.getLevel() + 1); - } - - float xp = (float) total / (float) player.getExpToLevel(); - player.setExp(xp); - } - - private int getTotalExperience(Player player) { // https://www.spigotmc.org/threads/72804 - int experience; - int level = player.getLevel(); - - if (level >= 0 && level <= 15) { - experience = (int) Math.ceil(Math.pow(level, 2) + (6 * level)); - int requiredExperience = 2 * level + 7; - double currentExp = Double.parseDouble(Float.toString(player.getExp())); - experience += Math.ceil(currentExp * requiredExperience); - return experience; - } else if (level > 15 && level <= 30) { - experience = (int) Math.ceil((2.5 * Math.pow(level, 2) - (40.5 * level) + 360)); - int requiredExperience = 5 * level - 38; - double currentExp = Double.parseDouble(Float.toString(player.getExp())); - experience += Math.ceil(currentExp * requiredExperience); - return experience; - } else { - experience = (int) Math.ceil((4.5 * Math.pow(level, 2) - (162.5 * level) + 2220)); - int requiredExperience = 9 * level - 158; - double currentExp = Double.parseDouble(Float.toString(player.getExp())); - experience += Math.ceil(currentExp * requiredExperience); - return experience; - } - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/vault/VaultSupport.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/vault/VaultSupport.java deleted file mode 100644 index 3051a51..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/support/economy/vault/VaultSupport.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.badbones69.crazyauctions.support.economy.vault; - -import com.badbones69.crazyauctions.CrazyAuctions; -import net.milkbowl.vault.economy.Economy; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; - -/** - * Description: Vault support related code. - */ -public class VaultSupport { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - private Economy vault = null; - - public Economy getVault() { - return vault; - } - - public void loadVault() { - RegisteredServiceProvider serviceProvider = plugin.getServer().getServicesManager().getRegistration(Economy.class); - - if (serviceProvider != null) vault = serviceProvider.getProvider(); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/ItemUtils.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/ItemUtils.java deleted file mode 100644 index 70219f4..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/ItemUtils.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.badbones69.crazyauctions.utils; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.plugin.java.JavaPlugin; - -public class ItemUtils { - - private final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/misc/ColorUtils.java b/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/misc/ColorUtils.java deleted file mode 100644 index cd7a27f..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/v2/utils/misc/ColorUtils.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.badbones69.crazyauctions.utils.misc; - -import com.badbones69.crazyauctions.ApiManager; -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.config.types.PluginConfig; -import org.bukkit.plugin.java.JavaPlugin; - -public class ColorUtils { - - private static final CrazyAuctions plugin = JavaPlugin.getPlugin(CrazyAuctions.class); - - public static String getPrefix() { - return ApiManager.getPluginConfig().getProperty(PluginConfig.COMMAND_PREFIX); - } -} \ No newline at end of file diff --git a/paper/src/main/resources/config1.12.2-Down.yml b/paper/src/main/resources/config1.12.2-Down.yml deleted file mode 100644 index c181ef7..0000000 --- a/paper/src/main/resources/config1.12.2-Down.yml +++ /dev/null @@ -1,306 +0,0 @@ -Settings: - Prefix: '&7[&4Crazy &bAuctions&7]: ' #Prefix of when you get Crazy Auctions Messages. - GUIName: '&4Crazy &bAuctions&8' #Name of the Main GUI. - Players-Current-Items: '&8Your Current Listings' #The Name of the Player Current Items GUI. - Cancelled/Expired-Items: '&8Cancelled/Expired Listings' #Name of the Canceled/Expired GUI. - Buying-Item: '&8Purchase Item: Are You Sure?' #Name of the Buying GUI. - Bidding-On-Item: '&8You Are Bidding On This Item.' #Name of the Bidding GUI. - Categories: '&8Categories' #Name of the Category GUI. - Sell-Time: 2d #The time that each item will sell for. - Bid-Time: 2m 30s #Time for each item that is biddable. - Full-Expire-Time: 10d #The full time the item is in the crazy auctions. - Bid-Winner-Time: 20d #The time the winner of a bid has to claim their prize. - Minimum-Sell-Price: 10 #Minimum amount you can sell an item for. - Max-Beginning-Sell-Price: 1000000 #Max amount you can sell an item for. - Minimum-Bid-Price: 100 #Minimum starting bid. - Max-Beginning-Bid-Price: 1000000 #Maximum starting bid. - Allow-Damaged-Items: False #Allow items that have been damaged. - Category-Page-Opens-First: False #If set to true the categories' page will open when they do /CA. - Feature-Toggle: #Toggle if a feature is on or off. - Selling: true #Able to use the selling part of the auction house. - Bidding: true #Able to use the bidding part of the auction house. - Patches: - Macro-Dupe: true #Turn to false if you have an issue, but it should patch the bug. - Sounds: - Toggle: False #Disable the clicking sound. - Sound: 'CLICK' #Make sure if you use 1.8 or lower you use the 1.8 sound and 1.9 and up use 1.9 sounds. The default sound is 1.8. - #1.8 sounds are found here: http://badbones69.com/javadocs/1.8.8/org/bukkit/Sound.html - #1.9 sounds are found here: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html - GUISettings: #Settings for things in the gui. - SellingItemLore: #The lore on items that are being sold. - - '&7-------------------------' - - '&aClick here to purchase.' - - '' - - '&9Price: &e$%price%' - - '&9Seller: &e%seller%' - - '&7-------------------------' - CurrentLore: #Lore on items that are in your current items GUI. - - '&7-------------------------' - - '&aClick here to cancel.' - - '' - - '&9Price: &e$%price%' - - '&9Expire: &e%time%' - - '&7-------------------------' - Cancelled/ExpiredLore: #Lore on items that are in your canceled/expired GUI. - - '&7-------------------------' - - '&aClick here to return to you.' - - '' - - '&9Full Expire: &e%time%' - - '&7-------------------------' - Bidding: #Lore on Bidding Items. - - '&7-------------------------' - - '&aClick here to bid.' - - '' - - '&9Seller: &e%seller%' - - '&9Current Bid: &e$%topbid%' - - '&9Top Bidder: &e%topbidder%' - - '&9Time Left: &e%time%' - - '&7-------------------------' - Category-Settings: - Armor: - Item: '315' - Toggle: true - Slot: 11 - Name: '&6&lArmor' - Lore: - - '&7This category contains all' - - '&7armor that is currently being sold.' - Weapons: - Item: '283' - Toggle: true - Slot: 12 - Name: '&6&lWeapons' - Lore: - - '&7This category contains all' - - '&7weapons that are currently being sold.' - Tools: - Item: '285' - Toggle: true - Slot: 13 - Name: '&6&lTools' - Lore: - - '&7This category contains all' - - '&7tools that are currently being sold.' - Food: - Item: '322' - Toggle: true - Slot: 14 - Name: '&6&lFood' - Lore: - - '&7This category contains all' - - '&7food that is currently being sold.' - Potions: - Item: '373:8227' - Toggle: true - Slot: 15 - Name: '&6&lPotions' - Lore: - - '&7This category contains all' - - '&7potions that are currently being sold.' - Blocks: - Item: '2' - Toggle: true - Slot: 16 - Name: '&6&lBlocks' - Lore: - - '&7This category contains all' - - '&7blocks that are currently being sold.' - Other: - Item: '371' - Toggle: true - Slot: 17 - Name: '&6&lOthers' - Lore: - - '&7This category contains all the' - - '&7other items currently being sold.' - None: - Item: '166' - Toggle: true - Slot: 23 - Name: '&6&lNone' - Lore: - - '&7This category contains all' - - '&7items currently being sold.' - OtherSettings: #Other Settings for the GUIs. - SellingItems: #The button for your current items. - Item: '264' #The item that this button is. - Toggle: true #If the item is in the gui or not. - Slot: 46 #The slot it is in. I recommend not changing these. If you do make sure they are still in the bottom row. - Name: '&6Items You are Selling' #Name of the item. - Lore: #Lore of the item. - - '&aClick here to view all the items you' - - '&aare currently selling on the auction.' - Cancelled/ExpiredItems: #The button for Canceled/Expired Items. - Item: '394' - Toggle: true - Slot: 47 - Name: '&6Collect Expired / Canceled Items' - Lore: - - '&aClick here to view and collect all of the' - - '&aitems you have canceled or has expired.' - PreviousPage: #The button for Previous Page. - Item: '339' - Toggle: true - Slot: 49 - Name: '&6Previous Page' - Lore: { } - Refesh: #The button for Refresh Page. - Item: '175' - Toggle: true - Slot: 50 - Name: '&6Refresh Page' - Lore: { } - NextPage: #The button for Next Page. - Item: '339' - Toggle: true - Slot: 51 - Name: '&6Next Page' - Lore: { } - Category1: #The button for Next Page. - Item: '54' - Toggle: true - Slot: 52 - Name: '&6Categories' - Lore: - - '&bCurrent Category: &6%category%' - - '&aWant to see items in specific categories?' - - '&aClick here to see all categories of items.' - Category2: #The button for Next Page. - Item: '54' - Toggle: true - Slot: 48 - Name: '&6Categories' - Lore: - - '&bCurrent Category: &6%category%' - - '&aWant to see items in specific categories?' - - '&aClick here to see all categories of items.' - Bidding/Selling: #Switch between Bidding and Selling. - Selling: - Item: '341' - Toggle: true - Slot: 53 - Name: '&6Currently looking at items being sold.' - Lore: - - '&7&l(&6&l!&7&l) &7Click here to see items' - - '&7that you can bid on.' - Bidding: - Item: '378' - Toggle: true - Slot: 53 - Name: '&6Currently looking at items that can be bid on.' - Lore: - - '&7&l(&6&l!&7&l) &7Click here to see items' - - '&7that you can buy at a price.' - WhatIsThis: #The info on all the Books buttons. - SellingShop: #The Book in the main shop. - Item: '340' - Toggle: true - Slot: 54 - Name: '&6What Is This Page?' - Lore: - - '&aThis is the crazy auctions, here you can' - - '&aput items for sale, and buy items' - - '&athat others have put for sale.' - - '' - - '&aThe auction is also a great place to make' - - '&amoney by selling items that others' - - '&amay be interested in buying.' - BiddingShop: #The Book in the main shop. - Item: '340' - Toggle: true - Slot: 54 - Name: '&6What Is This Page?' - Lore: - - '&aThis is the crazy auctions, here you can' - - '&aput items for sale, and bid on items' - - '&athat others have put for sale.' - - '' - - '&aThe bidding auction is also a great place to' - - '&amake money by bidding off items that others' - - '&amay be interested in bidding on.' - CurrentItems: #The Book in the Current items GUI. - Item: '340' - Toggle: true - Slot: 54 - Name: '&6What Is This Page?' - Lore: - - '&aThese are your current listings, all of' - - '&athe items you currenty have listed on' - - '&acrazy auctions are displayed here.' - - '' - - '&aYou can cancel and view your listings' - - '&aexpire time here.' - Cancelled/ExpiredItems: #The Book in the Canceled/Expired Items GUI. - Item: '340' - Toggle: true - Slot: 54 - Name: '&6What Is This Page?' - Lore: - - '&aThis page houses all of your cancelled and' - - '&aexpired items, when a listings is cancelled' - - '&aor expires you will be able to return that' - - '&aitem back to you from this menu.' - - '' - - '&aJust click on the item and if you have enough' - - '&ainventory space you will receive that item.' - Viewing: #The Book in the Viewing Items GUI. - Item: '340' - Toggle: true - Slot: 50 - Name: '&6What Is This Page?' - Lore: - - '&aThis page shows all the items that' - - '&aa player has currently on the bidding' - - '&aand selling market. You can quickly see' - - '&awhat a specific player is selling.' - Categories: #The Book in the Viewing Items GUI. - Item: '340' - Toggle: true - Slot: 54 - Name: '&6What Is This Page?' - Lore: - - '&aThis page shows all the categories' - - '&athat you can choose from. When you click' - - '&aa category it will open the gui with only' - - '&aitems that belong to that category.' - Back: #The Back Buttons. - Item: '339' - Slot: 46 - Name: '&6Back' - Return: #The Return Buttons. - Item: '390' - Slot: 50 - Name: '&6Return All' - Lore: - - '&aClick here to return all cancelled' - - '&aand expired items to your inventory.' - Confirm: #The Confirm Buttons. - Item: '160:5' - Name: '&aConfirm' - Cancel: #The Cancel Buttons. - Item: '160:14' - Name: '&cCancel' - Your-Item: #The item that shows when you try to buy/bid on your item. - Item: '166' - Name: '&cYou Can''t Purchase Your Own Item.' - Cant-Afford: #The item that shows when you can't afford this item. - Item: '166' - Name: '&cYou Can''t Afford This Item.' - Top-Bidder: #The item for when a player is already the top bidder. - Item: '166' - Name: '&cYou are already the top bidder.' - Bidding: #The item in the middle when bidding on an item. - Item: '160:15' - Name: '&7Bidding' - Lore: - - '&7<--&aAdd &cRemove&7-->' - - '&9Your Current Bid: &e$%bid%' - - '&9Current Top Bid: &e$%topbid%' - Bid: #The button for when you want to confirm your bid. - Item: '160:3' - Name: '&bBid Now' - Lore: - - '&7Click here to Bid Now.' - BlackList: - - '7' - - '120' \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 2a6847f..ca51714 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,9 +9,5 @@ pluginManagement { rootProject.name = "CrazyAuctions" -listOf( - "paper", - "common" -).forEach { - include(it) -} \ No newline at end of file +include("common") +include("paper") \ No newline at end of file From 24757083a90075238267aa68dae19b63499c7683 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Mon, 27 Nov 2023 01:17:59 -0500 Subject: [PATCH 7/7] update everything --- CONTRIBUTING.md | 2 +- build.gradle | 151 +++++ build.gradle.kts | 29 - buildSrc/build.gradle.kts | 11 - buildSrc/settings.gradle.kts | 14 - .../src/main/kotlin/paper-plugin.gradle.kts | 23 - .../src/main/kotlin/root-plugin.gradle.kts | 46 -- gradle.properties | 10 +- gradle/libs.versions.toml | 37 +- gradlew.bat | 92 --- paper/build.gradle | 64 +++ paper/build.gradle.kts | 125 ----- .../com/badbones69/crazyauctions/Main.java | 479 ---------------- .../crazyauctions/api/CrazyAuctions.java | 76 --- .../crazyauctions/api/FileManager.java | 501 ----------------- .../badbones69/crazyauctions/api/Version.java | 128 ----- .../currency/CurrencyManager.java | 119 ---- .../crazyauctions/currency/Vault.java | 57 -- .../crazyauctions/paper/CrazyAuctions.java | 111 ++++ .../crazyauctions/{ => paper}/Methods.java | 166 +++--- .../crazyauctions/paper/api/CrazyManager.java | 55 ++ .../crazyauctions/paper/api/FileManager.java | 505 +++++++++++++++++ .../{api => paper/api/enums}/Category.java | 105 ++-- .../{api => paper/api/enums}/Messages.java | 15 +- .../api/enums/Reaons.java} | 4 +- .../{api => paper/api/enums}/ShopType.java | 2 +- .../api/events/AuctionBuyEvent.java | 9 +- .../api/events/AuctionCancelledEvent.java | 18 +- .../api/events/AuctionExpireEvent.java | 8 +- .../api/events/AuctionListEvent.java | 12 +- .../api/events/AuctionNewBidEvent.java | 8 +- .../api/events/AuctionWinBidEvent.java | 8 +- .../paper/api/support/PluginSupport.java | 32 ++ .../api/support/metrics/MetricsWrapper.java | 36 ++ .../paper/commands/AuctionCommand.java | 524 ++++++++++++++++++ .../paper/commands/AuctionTab.java | 56 ++ .../controllers/GuiListener.java} | 395 ++++++++----- .../controllers/MarcoListener.java} | 8 +- .../paper/currency/VaultSupport.java | 45 ++ .../{config1.13-Up.yml => config.yml} | 0 paper/src/main/resources/plugin.yml | 55 +- settings.gradle | 13 + settings.gradle.kts | 13 - 43 files changed, 2076 insertions(+), 2091 deletions(-) create mode 100644 build.gradle delete mode 100644 build.gradle.kts delete mode 100644 buildSrc/build.gradle.kts delete mode 100644 buildSrc/settings.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/paper-plugin.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/root-plugin.gradle.kts delete mode 100644 gradlew.bat create mode 100644 paper/build.gradle delete mode 100644 paper/build.gradle.kts delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/Main.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/api/FileManager.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/api/Version.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java delete mode 100644 paper/src/main/java/com/badbones69/crazyauctions/currency/Vault.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/paper/CrazyAuctions.java rename paper/src/main/java/com/badbones69/crazyauctions/{ => paper}/Methods.java (81%) create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/paper/api/CrazyManager.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/paper/api/FileManager.java rename paper/src/main/java/com/badbones69/crazyauctions/{api => paper/api/enums}/Category.java (53%) rename paper/src/main/java/com/badbones69/crazyauctions/{api => paper/api/enums}/Messages.java (95%) rename paper/src/main/java/com/badbones69/crazyauctions/{api/enums/CancelledReason.java => paper/api/enums/Reaons.java} (69%) rename paper/src/main/java/com/badbones69/crazyauctions/{api => paper/api/enums}/ShopType.java (92%) rename paper/src/main/java/com/badbones69/crazyauctions/{ => paper}/api/events/AuctionBuyEvent.java (87%) rename paper/src/main/java/com/badbones69/crazyauctions/{ => paper}/api/events/AuctionCancelledEvent.java (83%) rename paper/src/main/java/com/badbones69/crazyauctions/{ => paper}/api/events/AuctionExpireEvent.java (92%) rename paper/src/main/java/com/badbones69/crazyauctions/{ => paper}/api/events/AuctionListEvent.java (83%) rename paper/src/main/java/com/badbones69/crazyauctions/{ => paper}/api/events/AuctionNewBidEvent.java (87%) rename paper/src/main/java/com/badbones69/crazyauctions/{ => paper}/api/events/AuctionWinBidEvent.java (87%) create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/paper/api/support/PluginSupport.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/paper/api/support/metrics/MetricsWrapper.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/paper/commands/AuctionCommand.java create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/paper/commands/AuctionTab.java rename paper/src/main/java/com/badbones69/crazyauctions/{controllers/GUI.java => paper/controllers/GuiListener.java} (86%) rename paper/src/main/java/com/badbones69/crazyauctions/{controllers/DupePatch.java => paper/controllers/MarcoListener.java} (65%) create mode 100644 paper/src/main/java/com/badbones69/crazyauctions/paper/currency/VaultSupport.java rename paper/src/main/resources/{config1.13-Up.yml => config.yml} (100%) create mode 100644 settings.gradle delete mode 100644 settings.gradle.kts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7ae017d..bfdceae 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ Contributions to the project are always welcome, Pull Requests do have some guidelines before being approved. ## You should always create the fork as a personal repository not in an organization. -Any pull request made by a fork in an organization prevents modifications. Everyone has their own way of doing things and rather asking you to change that. A personal fork lets us change the things +Any pull request made by a fork in an organization prevents modifications. Everyone has their own way of doing things and rather asking you to change that. A personal fork lets com change the things that we have a tick about. If you do not use a personal fork, We have to manually merge your pull request which means it's marked as closed instead of merged. diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..afa2d50 --- /dev/null +++ b/build.gradle @@ -0,0 +1,151 @@ +import io.papermc.hangarpublishplugin.model.Platforms + +plugins { + alias(libs.plugins.hangar) + alias(libs.plugins.modrinth) + + id 'java-library' +} + +defaultTasks 'build' + +def combineJars = tasks.register("combineJars", org.gradle.jvm.tasks.Jar) { + mustRunAfter build + + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + + from(files(subprojects.findAll { it.name != 'webmap' }.collect { + it.layout.buildDirectory.file("libs/${rootProject.name}-${it.name}-${it.version}.jar").get() + }).filter { it.name != 'MANIFEST.MF' }.collect { if (it.isDirectory()) it else zipTree(it) }) + + doLast { + File dir = new File(rootDir, "jars") + + if (dir.exists()) dir.delete() + + dir.mkdirs() + + copy { + from(layout.buildDirectory.file("libs/${rootProject.name}-${rootProject.version}.jar")) + into(dir) + } + } +} + +assemble { + subprojects.forEach { project -> dependsOn ":${project.name}:build" } + + finalizedBy combineJars +} + +subprojects { + apply plugin: 'java-library' + + repositories { + maven { url = 'https://repo.crazycrew.us/releases' } + + maven { url = 'https://jitpack.io' } + + mavenCentral() + } + + if (name == "paper") { + repositories { + maven { url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/' } + } + } + + compileJava { + options.encoding = 'UTF-8' + options.release.set(17) + } + + java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } + } + + javadoc { + options.encoding = 'UTF-8' + } + + processResources { + filteringCharset = 'UTF-8' + } +} + +boolean isBeta = true +String modrinthType = isBeta ? "beta" : "release" +String hangarType = isBeta ? "Beta" : "Release" + +String description = """ +# Please take backups and report any bugs you find! + +## Breaking Changes: + * Permissions have changed, You can view the updated permissions @ https://github.com/Crazy-Crew/CrazyAuctions/blob/main/paper/src/main/resources/plugin.yml + +## Changes: + * Re-organized and cleaned up a large portion of the code, Functionality shouldn't change + * Added proper tab completion + * Added proper permissions to plugin.yml + +## Optimizations: + * Only use uuid for hashmap's / arrays as god intended. + +## Warning: + * Data is still stored only using name's which is terrible but at the moment it's annoying to remove, It will change in the next few versions after some more clean up is made. + +## Developers: + * Do not rely on any methods in CrazyAuctions as an API, it will constantly be refactored and moved around until told otherwise. + +## Other: + * [Feature Requests](https://github.com/Crazy-Crew/${rootProject.name}/issues) + * [Bug Reports](https://github.com/Crazy-Crew/${rootProject.name}/issues) +""" + +File file = layout.buildDirectory.file("libs/${rootProject.name}-${rootProject.version}.jar").get().asFile + +modrinth { + setAutoAddDependsOn(false) + + token.set(System.getenv("modrinth_token")) + + projectId.set(rootProject.name.toLowerCase()) + + versionName.set("${rootProject.name} ${rootProject.version}") + + versionNumber.set("${rootProject.version}") + + versionType.set(modrinthType) + + uploadFile.set(file) + + gameVersions.add(minecraftVersion) + + changelog.set(description) + + loaders.addAll("paper", "purpur") +} + +hangarPublish { + publications.register("plugin") { + version.set("$rootProject.version") + + id.set(rootProject.name) + + channel.set(hangarType) + + changelog.set(description) + + apiKey.set(System.getenv("hangar_key")) + + platforms { + register(Platforms.PAPER) { + jar.set(file) + + platformVersions.set(["$minecraftVersion"]) + } + } + } +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index c088781..0000000 --- a/build.gradle.kts +++ /dev/null @@ -1,29 +0,0 @@ -plugins { - id("root-plugin") -} - -defaultTasks("build") - -tasks { - assemble { - val jarsDir = File("$rootDir/jars") - if (jarsDir.exists()) jarsDir.delete() - - subprojects.forEach { project -> - dependsOn(":${project.name}:build") - - doLast { - if (!jarsDir.exists()) jarsDir.mkdirs() - - if (project.name == "core") return@doLast - - val file = file("${project.layout.buildDirectory.get()}/libs/${rootProject.name}-${rootProject.version}.jar") - - copy { - from(file) - into(jarsDir) - } - } - } - } -} \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts deleted file mode 100644 index 742a7b8..0000000 --- a/buildSrc/build.gradle.kts +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - `kotlin-dsl` -} - -dependencies { - implementation(libs.paperweight.plugin) - - implementation(libs.jpenilla.plugin) - - implementation(libs.shadow.plugin) -} \ No newline at end of file diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts deleted file mode 100644 index 4720f82..0000000 --- a/buildSrc/settings.gradle.kts +++ /dev/null @@ -1,14 +0,0 @@ -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 diff --git a/buildSrc/src/main/kotlin/paper-plugin.gradle.kts b/buildSrc/src/main/kotlin/paper-plugin.gradle.kts deleted file mode 100644 index 24d0097..0000000 --- a/buildSrc/src/main/kotlin/paper-plugin.gradle.kts +++ /dev/null @@ -1,23 +0,0 @@ -plugins { - id("io.papermc.paperweight.userdev") - - id("root-plugin") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") -} - -dependencies { - paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT") -} - -tasks { - assemble { - dependsOn(reobfJar) - } - - reobfJar { - outputJar.set(file("${project.layout.buildDirectory.get()}/libs/${rootProject.name}-${rootProject.version}.jar")) - } -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/root-plugin.gradle.kts b/buildSrc/src/main/kotlin/root-plugin.gradle.kts deleted file mode 100644 index 57bb9dc..0000000 --- a/buildSrc/src/main/kotlin/root-plugin.gradle.kts +++ /dev/null @@ -1,46 +0,0 @@ -plugins { - id("com.github.johnrengelman.shadow") - - `maven-publish` - `java-library` -} - -repositories { - maven("https://repo.triumphteam.dev/snapshots/") - - maven("https://repo.crazycrew.us/releases/") - - maven("https://jitpack.io") - - mavenCentral() -} - -java { - toolchain.languageVersion.set(JavaLanguageVersion.of("17")) -} - -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() - options.release.set(17) - } - - shadowJar { - mergeServiceFiles() - - exclude("META-INF/**") - } -} - -publishing { - repositories { - maven { - credentials { - this.username = System.getenv("gradle_username") - this.password = System.getenv("gradle_password") - } - - url = uri("https://repo.crazycrew.us/releases/") - } - } -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 81a249e..257e0a2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.parallel = false org.gradle.warning.mode = all authors = ["Ryderbelserion, Badbones69"] -website = https://modrinth.com/plugin/crazycrates -sources = https://github.com/Crazy-Crew/CrazyCrates -issues = https://github.com/Crazy-Crew/CrazyCrates/issues +website = https://modrinth.com/plugin/crazyauctions +sources = https://github.com/Crazy-Crew/CrazyAuctions +issues = https://github.com/Crazy-Crew/CrazyAuctions/issues -group = com.badbones69.com -description = Auction off items in style! +group = com.badbones69.crazyauctions +description = Auction off items in style. version = 1.3 apiVersion = 1.20 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f8deb82..700f14e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,46 +1,35 @@ [versions] -paperweight_version = "1.5.8" -run_paper_version = "2.2.0" -shadow_version = "8.1.1" - -jetbrains_kotlin = "1.9.10" - -cluster_version = "2.4" kyori_version = "4.14.0" +cluster_version = "3.1" + [plugins] hangar = { id = "io.papermc.hangar-publish-plugin", version = "0.1.0" } modrinth = { id = "com.modrinth.minotaur", version = "2.8.4" } -[libraries] -cluster_paper = { module = "com.ryderbelserion.cluster:cluster-paper", version.ref = "cluster_version" } -cluster_api = { module = "com.ryderbelserion.cluster:cluster-api", version.ref = "cluster_version" } +paperweight = { id = "io.papermc.paperweight.userdev", version = "1.5.9" } +runpaper = { id = "xyz.jpenilla.run-paper", version = "2.2.2" } +shadowjar = { id = "com.github.johnrengelman.shadow", version = "8.1.1" } +[libraries] adventure = { module = "net.kyori:adventure-api", version.ref = "kyori_version" } minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "kyori_version" } -nbtapi = { module = "de.tr7zw:item-nbt-api", version = "2.12.0" } +cluster_paper = { module = "com.ryderbelserion.cluster.paper:cluster-paper", version.ref = "cluster_version" } +cluster_api = { module = "com.ryderbelserion.cluster.api:cluster-api", version.ref = "cluster_version" } -annotations = { module = "org.jetbrains:annotations", version = "24.0.1" } -kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "jetbrains_kotlin" } +vault = { module = "com.github.MilkBowl:VaultAPI", version = "1.7.1" } -triumphcmds = { module = "dev.triumphteam:triumph-cmd-bukkit", version = "2.0.0-SNAPSHOT" } +triumph_cmds = { module = "dev.triumphteam:triumph-cmd-bukkit", version = "2.0.0-SNAPSHOT" } -configme = { module = "ch.jalu:configme", version = "1.4.1" } +config_me = { module = "ch.jalu:configme", version = "1.4.1" } metrics = { module = "org.bstats:bstats-bukkit", version = "3.0.2" } itemsadder = { module = "com.github.LoneDev6:api-itemsadder", version = "3.6.1" } -oraxen = { module = "com.github.oraxen:oraxen", version = "1.162.0" } +oraxen = { module = "io.th0rgal:oraxen", version = "1.164.0" } holographicdisplays = { module = "me.filoghost.holographicdisplays:holographicdisplays-api", version = "3.0.0" } decentholograms = { module = "com.github.decentsoftware-eu:decentholograms", version = "2.8.4" } -placeholderapi = { module = "me.clip:placeholderapi", version = "2.11.4" } - -# Plugins -paperweight_plugin = { module = "io.papermc.paperweight:paperweight-userdev", version.ref = "paperweight_version" } -jpenilla_plugin = { module = "xyz.jpenilla:run-task", version.ref = "run_paper_version" } -shadow_plugin = { module = "com.github.johnrengelman:shadow", version.ref = "shadow_version" } - -kotlin_plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "jetbrains_kotlin" } \ No newline at end of file +placeholderapi = { module = "me.clip:placeholderapi", version = "2.11.4" } \ No newline at end of file diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index 93e3f59..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,92 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/paper/build.gradle b/paper/build.gradle new file mode 100644 index 0000000..efb5e47 --- /dev/null +++ b/paper/build.gradle @@ -0,0 +1,64 @@ +plugins { + alias(libs.plugins.paperweight) + alias(libs.plugins.shadowjar) + + alias(libs.plugins.runpaper) +} + +project.group = "${rootProject.group}.paper" +project.version = rootProject.version + +base { + archivesName = "${rootProject.name}-${project.name}" +} + +dependencies { + implementation(libs.metrics) + + compileOnly(libs.vault) + + paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:$minecraftVersion-R0.1-SNAPSHOT") +} + +tasks { + runServer { + jvmArgs("-Dnet.kyori.ansi.colorLevel=truecolor") + + minecraftVersion(minecraftVersion) + } + + assemble { + dependsOn(reobfJar) + } + + shadowJar { + mergeServiceFiles() + + exclude("META-INF/**") + + List.of( + "org.bstats" + ).forEach { + relocate(it, "libs.$it") + } + } + + processResources { + Map props = new HashMap<>() + + props.put("name", rootProject.name) + props.put("version", "$rootProject.version") + props.put("group", "$project.group") + props.put("description", rootProject.description) + + props.put("apiVersion", apiVersion) + props.put("authors", authors) + props.put("website", website) + + inputs.properties(props) + + filesMatching("plugin.yml") { + expand(props) + } + } +} \ No newline at end of file diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts deleted file mode 100644 index be8b59b..0000000 --- a/paper/build.gradle.kts +++ /dev/null @@ -1,125 +0,0 @@ -import io.papermc.hangarpublishplugin.model.Platforms - -plugins { - alias(libs.plugins.modrinth) - alias(libs.plugins.hangar) - - id("xyz.jpenilla.run-paper") - - id("paper-plugin") -} - -project.group = "${rootProject.group}.paper" - -repositories { - maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") - - maven("https://repo.codemc.org/repository/maven-public/") - - maven("https://repo.crazycrew.us/first-party/") - - maven("https://repo.crazycrew.us/third-party/") - - flatDir { dirs("libs") } -} - -dependencies { - -} - -tasks { - runServer { - jvmArgs("-Dnet.kyori.ansi.colorLevel=truecolor") - - minecraftVersion("1.20.2") - } - - shadowJar { - listOf( - "de.tr7zw.changeme.nbtapi", - "org.bstats", - "ch.jalu" - ).forEach { - relocate(it, "libs.$it") - } - } - - processResources { - val props = mapOf( - "name" to rootProject.name, - "group" to project.group.toString(), - "version" to rootProject.version, - "description" to rootProject.description, - "authors" to rootProject.properties["authors"], - "apiVersion" to "1.20", - "website" to "https://modrinth.com/plugin/${rootProject.name.lowercase()}" - ) - - filesMatching("plugin.yml") { - expand(props) - } - } -} - -val isSnapshot = true -val type = if (isSnapshot) "beta" else "release" -val other = if (isSnapshot) "Beta" else "Release" - -val file = file("${rootProject.rootDir}/jars/${rootProject.name}-${rootProject.version}.jar") - -val description = """ -## Fixes: - * Fix not crates being wrongly labeled as virtual crates if they are quadcrate, quickcrate or ones that need to be in the physical world. - -## Other: - * [Feature Requests](https://github.com/Crazy-Crew/${rootProject.name}/issues) - * [Bug Reports](https://github.com/Crazy-Crew/${rootProject.name}/issues) -""".trimIndent() - -val versions = listOf( - "1.20", - "1.20.1", - "1.20.2" -) - -modrinth { - autoAddDependsOn.set(false) - - token.set(System.getenv("modrinth_token")) - - projectId.set(rootProject.name.lowercase()) - - versionName.set("${rootProject.name} ${rootProject.version}") - versionNumber.set("${rootProject.version}") - - versionType.set(type) - - uploadFile.set(file("${rootProject.rootDir}/jars/${rootProject.name}-${rootProject.version}.jar")) - - gameVersions.addAll(versions) - - changelog.set(description) - - loaders.addAll("paper", "purpur") -} - -hangarPublish { - publications.register("plugin") { - version.set(rootProject.version as String) - - id.set(rootProject.name) - - channel.set(if (isSnapshot) "Beta" else "Release") - - changelog.set(description) - - apiKey.set(System.getenv("hangar_key")) - - platforms { - register(Platforms.PAPER) { - jar.set(file("${rootProject.rootDir}/jars/${rootProject.name}-${rootProject.version}.jar")) - platformVersions.set(versions) - } - } - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/Main.java b/paper/src/main/java/com/badbones69/crazyauctions/Main.java deleted file mode 100644 index eb29de7..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/Main.java +++ /dev/null @@ -1,479 +0,0 @@ -package com.badbones69.crazyauctions; - -import com.badbones69.crazyauctions.api.*; -import com.badbones69.crazyauctions.api.FileManager.Files; -import com.badbones69.crazyauctions.api.events.AuctionListEvent; -import com.badbones69.crazyauctions.controllers.DupePatch; -import com.badbones69.crazyauctions.controllers.GUI; -import com.badbones69.crazyauctions.currency.Vault; -import org.bstats.bukkit.Metrics; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; -import org.bukkit.permissions.PermissionAttachmentInfo; -import org.bukkit.plugin.java.JavaPlugin; -import org.yaml.snakeyaml.error.YAMLException; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Random; - -public class Main extends JavaPlugin implements Listener { - - public static FileManager fileManager = FileManager.getInstance(); - public static CrazyAuctions crazyAuctions = CrazyAuctions.getInstance(); - - @Override - public void onEnable() { - fileManager.logInfo(true).setup(this); - crazyAuctions.loadCrazyAuctions(); - Bukkit.getServer().getPluginManager().registerEvents(this, this); - Bukkit.getServer().getPluginManager().registerEvents(new GUI(), this); - Bukkit.getServer().getPluginManager().registerEvents(new DupePatch(), this); - Methods.updateAuction(); - startCheck(); - - if (!Vault.setupEconomy()) { saveDefaultConfig(); } - - Messages.addMissingMessages(); - new Metrics(this, 4624); //Starts up bStats - } - - @Override - public void onDisable() { - int file = 0; - Bukkit.getScheduler().cancelTask(file); - Files.DATA.saveFile(true); - } - - public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args) { - if (commandLable.equalsIgnoreCase("CrazyAuctions") || commandLable.equalsIgnoreCase("CrazyAuction") || commandLable.equalsIgnoreCase("CA") || commandLable.equalsIgnoreCase("AH") || commandLable.equalsIgnoreCase("HDV")) { - if (args.length == 0) { - if (!Methods.hasPermission(sender, "Access")) return true; - if (!(sender instanceof Player)) { - sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); - return true; - } - Player player = (Player) sender; - if (Files.CONFIG.getFile().contains("Settings.Category-Page-Opens-First")) { - if (Files.CONFIG.getFile().getBoolean("Settings.Category-Page-Opens-First")) { - GUI.openCategories(player, ShopType.SELL); - return true; - } - } - if (crazyAuctions.isSellingEnabled()) { - GUI.openShop(player, ShopType.SELL, Category.NONE, 1); - } else if (crazyAuctions.isBiddingEnabled()) { - GUI.openShop(player, ShopType.BID, Category.NONE, 1); - } else { - player.sendMessage(Methods.getPrefix() + Methods.color("&cThe bidding and selling options are both disabled. Please contact the admin about this.")); - } - return true; - } - if (args.length >= 1) { - if (args[0].equalsIgnoreCase("Help")) {// CA Help - if (!Methods.hasPermission(sender, "Access")) return true; - sender.sendMessage(Messages.HELP.getMessage()); - return true; - } - if (args[0].equalsIgnoreCase("test")) {// CA test [times] - if (!Methods.hasPermission(sender, "test")) return true; - int times = 1; - if (args.length >= 2) { - if (!Methods.isInt(args[1])) { - HashMap placeholders = new HashMap<>(); - placeholders.put("%Arg%", args[1]); - placeholders.put("%arg%", args[1]); - sender.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); - return true; - } - times = Integer.parseInt(args[1]); - } - int price = 10; - int amount = 1; - ItemStack item = Methods.getItemInHand((Player) sender); - if (item != null && item.getType() != Material.AIR) { - // For testing as another player - String seller = "Test-Account"; - for (int it = 1; it <= times; it++) { - int num = 1; - Random r = new Random(); - for (; Files.DATA.getFile().contains("Items." + num); num++) ; - Files.DATA.getFile().set("Items." + num + ".Price", price); - Files.DATA.getFile().set("Items." + num + ".Seller", seller); - if (args[0].equalsIgnoreCase("Bid")) { - Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Bid-Time"))); - } else { - Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Sell-Time"))); - } - Files.DATA.getFile().set("Items." + num + ".Full-Time", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Full-Expire-Time"))); - int id = r.nextInt(Integer.MAX_VALUE); - for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) - if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); - Files.DATA.getFile().set("Items." + num + ".StoreID", id); - ShopType type = ShopType.SELL; - Files.DATA.getFile().set("Items." + num + ".Biddable", args[0].equalsIgnoreCase("Bid")); - Files.DATA.getFile().set("Items." + num + ".TopBidder", "None"); - ItemStack I = item.clone(); - I.setAmount(amount); - Files.DATA.getFile().set("Items." + num + ".Item", I); - } - Files.DATA.saveFile(); - HashMap placeholders = new HashMap<>(); - placeholders.put("%Price%", price + ""); - placeholders.put("%price%", price + ""); - sender.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(placeholders)); - if (item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) { - Methods.setItemInHand((Player) sender, new ItemStack(Material.AIR)); - } else { - item.setAmount(item.getAmount() - amount); - } - } else { - sender.sendMessage(Messages.DOSENT_HAVE_ITEM_IN_HAND.getMessage()); - } - return true; - } - if (args[0].equalsIgnoreCase("Reload")) {// CA Reload - if (!Methods.hasPermission(sender, "Admin")) return true; - fileManager.logInfo(true).setup(this); - crazyAuctions.loadCrazyAuctions(); - sender.sendMessage(Messages.RELOAD.getMessage()); - return true; - } - if (args[0].equalsIgnoreCase("View")) {// CA View - if (!Methods.hasPermission(sender, "View")) return true; - if (!(sender instanceof Player)) { - sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); - return true; - } - if (args.length >= 2) { - Player player = (Player) sender; - GUI.openViewer(player, args[1], 1); - return true; - } - sender.sendMessage(Messages.CRAZYAUCTIONS_VIEW.getMessage()); - return true; - } - if (args[0].equalsIgnoreCase("Expired") || args[0].equalsIgnoreCase("Collect")) {// CA Expired - if (!Methods.hasPermission(sender, "Access")) return true; - if (!(sender instanceof Player)) { - sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); - return true; - } - Player player = (Player) sender; - GUI.openPlayersExpiredList(player, 1); - return true; - } - if (args[0].equalsIgnoreCase("Listed")) {// CA Listed - if (!Methods.hasPermission(sender, "Access")) return true; - if (!(sender instanceof Player)) { - sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); - return true; - } - Player player = (Player) sender; - GUI.openPlayersCurrentList(player, 1); - return true; - } - if (args[0].equalsIgnoreCase("Sell") || args[0].equalsIgnoreCase("Bid")) {// /CA Sell/Bid [Amount of Items] - if (!(sender instanceof Player)) { - sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); - return true; - } - if (args.length >= 2) { - Player player = (Player) sender; - if (args[0].equalsIgnoreCase("Sell")) { - if (!crazyAuctions.isSellingEnabled()) { - player.sendMessage(Messages.SELLING_DISABLED.getMessage()); - return true; - } - if (!Methods.hasPermission(player, "Sell")) return true; - } - if (args[0].equalsIgnoreCase("Bid")) { - if (!crazyAuctions.isBiddingEnabled()) { - player.sendMessage(Messages.BIDDING_DISABLED.getMessage()); - return true; - } - if (!Methods.hasPermission(player, "Bid")) return true; - } - ItemStack item = Methods.getItemInHand(player); - int amount = item.getAmount(); - if (args.length >= 3) { - if (!Methods.isInt(args[2])) { - HashMap placeholders = new HashMap<>(); - placeholders.put("%Arg%", args[2]); - placeholders.put("%arg%", args[2]); - player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); - return true; - } - amount = Integer.parseInt(args[2]); - if (amount <= 0) amount = 1; - if (amount > item.getAmount()) amount = item.getAmount(); - } - if (!Methods.isLong(args[1])) { - HashMap placeholders = new HashMap<>(); - placeholders.put("%Arg%", args[1]); - placeholders.put("%arg%", args[1]); - player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); - return true; - } - if (Methods.getItemInHand(player).getType() == Material.AIR) { - player.sendMessage(Messages.DOSENT_HAVE_ITEM_IN_HAND.getMessage()); - return false; - } - long price = Long.parseLong(args[1]); - if (args[0].equalsIgnoreCase("Bid")) { - if (price < Files.CONFIG.getFile().getLong("Settings.Minimum-Bid-Price")) { - player.sendMessage(Messages.BID_PRICE_TO_LOW.getMessage()); - return true; - } - if (price > Files.CONFIG.getFile().getLong("Settings.Max-Beginning-Bid-Price")) { - player.sendMessage(Messages.BID_PRICE_TO_HIGH.getMessage()); - return true; - } - } else { - if (price < Files.CONFIG.getFile().getLong("Settings.Minimum-Sell-Price")) { - player.sendMessage(Messages.SELL_PRICE_TO_LOW.getMessage()); - return true; - } - if (price > Files.CONFIG.getFile().getLong("Settings.Max-Beginning-Sell-Price")) { - player.sendMessage(Messages.SELL_PRICE_TO_HIGH.getMessage()); - return true; - } - } - if (!player.hasPermission("crazyauctions.bypass")) { - int SellLimit = 0; - int BidLimit = 0; - for (PermissionAttachmentInfo permission : player.getEffectivePermissions()) { - String perm = permission.getPermission(); - if (perm.startsWith("crazyauctions.sell.")) { - perm = perm.replace("crazyauctions.sell.", ""); - if (Methods.isInt(perm)) { - if (Integer.parseInt(perm) > SellLimit) { - SellLimit = Integer.parseInt(perm); - } - } - } - if (perm.startsWith("crazyauctions.bid.")) { - perm = perm.replace("crazyauctions.bid.", ""); - if (Methods.isInt(perm)) { - if (Integer.parseInt(perm) > BidLimit) { - BidLimit = Integer.parseInt(perm); - } - } - } - } - for (int i = 1; i < 100; i++) { - if (SellLimit < i) { - if (player.hasPermission("crazyauctions.sell." + i)) { - SellLimit = i; - } - } - if (BidLimit < i) { - if (player.hasPermission("crazyauctions.bid." + i)) { - BidLimit = i; - } - } - } - if (args[0].equalsIgnoreCase("Sell")) { - if (crazyAuctions.getItems(player, ShopType.SELL).size() >= SellLimit) { - player.sendMessage(Messages.MAX_ITEMS.getMessage()); - return true; - } - } - if (args[0].equalsIgnoreCase("Bid")) { - if (crazyAuctions.getItems(player, ShopType.BID).size() >= BidLimit) { - player.sendMessage(Messages.MAX_ITEMS.getMessage()); - return true; - } - } - } - for (String id : Files.CONFIG.getFile().getStringList("Settings.BlackList")) { - if (item.getType() == Methods.makeItem(id, 1).getType()) { - player.sendMessage(Messages.ITEM_BLACKLISTED.getMessage()); - return true; - } - } - if (!Files.CONFIG.getFile().getBoolean("Settings.Allow-Damaged-Items")) { - for (Material i : getDamageableItems()) { - if (item.getType() == i) { - if (item.getDurability() > 0) { - player.sendMessage(Messages.ITEM_DAMAGED.getMessage()); - return true; - } - } - } - } - if (!allowBook(item)) { - player.sendMessage(Messages.BOOK_NOT_ALLOWED.getMessage()); - return true; - } - String seller = player.getName(); - // For testing as another player - //String seller = "Test-Account"; - int num = 1; - Random r = new Random(); - for (; Files.DATA.getFile().contains("Items." + num); num++) ; - Files.DATA.getFile().set("Items." + num + ".Price", price); - Files.DATA.getFile().set("Items." + num + ".Seller", seller); - if (args[0].equalsIgnoreCase("Bid")) { - Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Bid-Time"))); - } else { - Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Sell-Time"))); - } - Files.DATA.getFile().set("Items." + num + ".Full-Time", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Full-Expire-Time"))); - int id = r.nextInt(999999); - // Runs 3x to check for same ID. - for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) - if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); - for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) - if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); - for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) - if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); - Files.DATA.getFile().set("Items." + num + ".StoreID", id); - ShopType type = ShopType.SELL; - if (args[0].equalsIgnoreCase("Bid")) { - Files.DATA.getFile().set("Items." + num + ".Biddable", true); - type = ShopType.BID; - } else { - Files.DATA.getFile().set("Items." + num + ".Biddable", false); - } - Files.DATA.getFile().set("Items." + num + ".TopBidder", "None"); - ItemStack I = item.clone(); - I.setAmount(amount); - Files.DATA.getFile().set("Items." + num + ".Item", I); - Files.DATA.saveFile(); - Bukkit.getPluginManager().callEvent(new AuctionListEvent(player, type, I, price)); - HashMap placeholders = new HashMap<>(); - placeholders.put("%Price%", price + ""); - placeholders.put("%price%", price + ""); - player.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(placeholders)); - if (item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) { - Methods.setItemInHand(player, new ItemStack(Material.AIR)); - } else { - item.setAmount(item.getAmount() - amount); - } - return false; - } - sender.sendMessage(Messages.CRAZYAUCTIONS_SELL_BID.getMessage()); - return true; - } - } - } - sender.sendMessage(Messages.CRAZYAUCTIONS_HELP.getMessage()); - return false; - } - - @EventHandler - public void onJoin(PlayerJoinEvent e) { - final Player player = e.getPlayer(); - if (player.getName().equalsIgnoreCase("BadBones69")) { - Bukkit.getScheduler().runTaskLater(this, () -> player.sendMessage(Methods.getPrefix() + Methods.color("&7This server is running your Crazy Auctions Plugin. " + "&7It is running version &av" + Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions").getDescription().getVersion() + "&7.")), 40); - } - } - - private void startCheck() { - Bukkit.getScheduler().runTaskTimer(this, Methods :: updateAuction, 20, 5 * 20); - } - - private ArrayList getDamageableItems() { - ArrayList ma = new ArrayList<>(); - if (Version.isNewer(Version.v1_12_R1)) { - ma.add(Material.matchMaterial("GOLDEN_HELMET")); - ma.add(Material.matchMaterial("GOLDEN_CHESTPLATE")); - ma.add(Material.matchMaterial("GOLDEN_LEGGINGS")); - ma.add(Material.matchMaterial("GOLDEN_BOOTS")); - ma.add(Material.matchMaterial("WOODEN_SWORD")); - ma.add(Material.matchMaterial("WOODEN_AXE")); - ma.add(Material.matchMaterial("WOODEN_PICKAXE")); - ma.add(Material.matchMaterial("WOODEN_AXE")); - ma.add(Material.matchMaterial("WOODEN_SHOVEL")); - ma.add(Material.matchMaterial("STONE_SHOVEL")); - ma.add(Material.matchMaterial("IRON_SHOVEL")); - ma.add(Material.matchMaterial("DIAMOND_SHOVEL")); - ma.add(Material.matchMaterial("WOODEN_HOE")); - ma.add(Material.matchMaterial("GOLDEN_HOE")); - ma.add(Material.matchMaterial("CROSSBOW")); - ma.add(Material.matchMaterial("TRIDENT")); - ma.add(Material.matchMaterial("TURTLE_HELMET")); - } else { - ma.add(Material.matchMaterial("GOLD_HELMET")); - ma.add(Material.matchMaterial("GOLD_CHESTPLATE")); - ma.add(Material.matchMaterial("GOLD_LEGGINGS")); - ma.add(Material.matchMaterial("GOLD_BOOTS")); - ma.add(Material.matchMaterial("WOOD_SWORD")); - ma.add(Material.matchMaterial("WOOD_AXE")); - ma.add(Material.matchMaterial("WOOD_PICKAXE")); - ma.add(Material.matchMaterial("WOOD_AXE")); - ma.add(Material.matchMaterial("WOOD_SPADE")); - ma.add(Material.matchMaterial("STONE_SPADE")); - ma.add(Material.matchMaterial("IRON_SPADE")); - ma.add(Material.matchMaterial("DIAMOND_SPADE")); - ma.add(Material.matchMaterial("WOOD_HOE")); - ma.add(Material.matchMaterial("GOLD_HOE")); - } - ma.add(Material.DIAMOND_HELMET); - ma.add(Material.DIAMOND_CHESTPLATE); - ma.add(Material.DIAMOND_LEGGINGS); - ma.add(Material.DIAMOND_BOOTS); - ma.add(Material.CHAINMAIL_HELMET); - ma.add(Material.CHAINMAIL_CHESTPLATE); - ma.add(Material.CHAINMAIL_LEGGINGS); - ma.add(Material.CHAINMAIL_BOOTS); - ma.add(Material.IRON_HELMET); - ma.add(Material.IRON_CHESTPLATE); - ma.add(Material.IRON_LEGGINGS); - ma.add(Material.IRON_BOOTS); - ma.add(Material.LEATHER_HELMET); - ma.add(Material.LEATHER_CHESTPLATE); - ma.add(Material.LEATHER_LEGGINGS); - ma.add(Material.LEATHER_BOOTS); - ma.add(Material.BOW); - ma.add(Material.STONE_SWORD); - ma.add(Material.IRON_SWORD); - ma.add(Material.DIAMOND_SWORD); - ma.add(Material.STONE_AXE); - ma.add(Material.IRON_AXE); - ma.add(Material.DIAMOND_AXE); - ma.add(Material.STONE_PICKAXE); - ma.add(Material.IRON_PICKAXE); - ma.add(Material.DIAMOND_PICKAXE); - ma.add(Material.STONE_AXE); - ma.add(Material.IRON_AXE); - ma.add(Material.DIAMOND_AXE); - ma.add(Material.STONE_HOE); - ma.add(Material.IRON_HOE); - ma.add(Material.DIAMOND_HOE); - ma.add(Material.FLINT_AND_STEEL); - ma.add(Material.ANVIL); - ma.add(Material.FISHING_ROD); - return ma; - } - - private boolean allowBook(ItemStack item) { - if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof BookMeta) { - Bukkit.getLogger().info("Checking " + item.getType() + " for illegal unicode."); - try { - Files.TEST_FILE.getFile().set("Test", item); - Files.TEST_FILE.saveFile(); - Bukkit.getLogger().info("" + item.getType() + " has passed unicode checks."); - } catch (YAMLException e) { - Bukkit.getLogger().info("" + item.getType() + " has failed unicode checks and has been denied."); - return false; - } - return ((BookMeta) item.getItemMeta()).getPages().stream().mapToInt(String :: length).sum() < 2000; - } - return true; - } - - public Material getMaterial(String newMaterial, String oldMaterial) { - return Material.matchMaterial(Version.isNewer(Version.v1_12_R1) ? newMaterial : oldMaterial); - } - -} diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java b/paper/src/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java deleted file mode 100644 index 4045c0e..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/CrazyAuctions.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.badbones69.crazyauctions.api; - -import com.badbones69.crazyauctions.api.FileManager.Files; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; - -public class CrazyAuctions { - - private static CrazyAuctions instance = new CrazyAuctions(); - private FileManager fileManager = FileManager.getInstance(); - private Boolean sellingEnabled; - private Boolean biddingEnabled; - - public static CrazyAuctions getInstance() { - return instance; - } - - public void loadCrazyAuctions() { - if (Files.CONFIG.getFile().contains("Settings.Feature-Toggle.Selling")) { - this.sellingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Selling"); - } else { - this.sellingEnabled = true; - } - if (Files.CONFIG.getFile().contains("Settings.Feature-Toggle.Bidding")) { - this.biddingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Bidding"); - } else { - this.biddingEnabled = true; - } - } - - public Boolean isSellingEnabled() { - return sellingEnabled; - } - - public Boolean isBiddingEnabled() { - return biddingEnabled; - } - - public ArrayList getItems(Player player) { - FileConfiguration data = Files.DATA.getFile(); - ArrayList items = new ArrayList<>(); - if (data.contains("Items")) { - for (String i : data.getConfigurationSection("Items").getKeys(false)) { - if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { - items.add(data.getItemStack("Items." + i + ".Item").clone()); - } - } - } - return items; - } - - public ArrayList getItems(Player player, ShopType type) { - FileConfiguration data = Files.DATA.getFile(); - ArrayList items = new ArrayList<>(); - if (data.contains("Items")) { - for (String i : data.getConfigurationSection("Items").getKeys(false)) { - if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { - if (data.getBoolean("Items." + i + ".Biddable")) { - if (type == ShopType.BID) { - items.add(data.getItemStack("Items." + i + ".Item").clone()); - } - } else { - if (type == ShopType.SELL) { - items.add(data.getItemStack("Items." + i + ".Item").clone()); - } - } - } - } - } - return items; - } - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/FileManager.java b/paper/src/main/java/com/badbones69/crazyauctions/api/FileManager.java deleted file mode 100644 index 329f39a..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/FileManager.java +++ /dev/null @@ -1,501 +0,0 @@ -package com.badbones69.crazyauctions.api; - -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; - -/** - * - * @author BadBones69 - * @version v1.0 - * - */ -public class FileManager { - - private static FileManager instance = new FileManager(); - private Plugin plugin; - private String prefix = ""; - private Boolean log = false; - private HashMap files = new HashMap<>(); - private ArrayList homeFolders = new ArrayList<>(); - private ArrayList customFiles = new ArrayList<>(); - private HashMap autoGenerateFiles = new HashMap<>(); - private HashMap configurations = new HashMap<>(); - - public static FileManager getInstance() { - return instance; - } - - /** - * Sets up the plugin and loads all necessary files. - * @param plugin The plugin this is getting loading for. - */ - public FileManager setup(Plugin plugin) { - prefix = "[" + plugin.getName() + "] "; - this.plugin = plugin; - if (!plugin.getDataFolder().exists()) { - plugin.getDataFolder().mkdirs(); - } - files.clear(); - customFiles.clear(); - //Loads all the normal static files. - for (Files file : Files.values()) { - File newFile = new File(plugin.getDataFolder(), file.getFileLocation()); - if (log) Bukkit.getLogger().info("Loading the " + file.getFileName()); - if (!newFile.exists()) { - try { - String fileLocation = file.getFileLocation(); - //Switch between 1.12.2- and 1.13+ config version. - if (file == Files.CONFIG) { - if (Version.isOlder(Version.v1_13_R2)) { - fileLocation = "config1.12.2-Down.yml"; - } else { - fileLocation = "config1.13-Up.yml"; - } - } - File serverFile = new File(plugin.getDataFolder(), "/" + file.getFileLocation()); - InputStream jarFile = getClass().getResourceAsStream("/" + fileLocation); - copyFile(jarFile, serverFile); - } catch (Exception e) { - if (log) Bukkit.getLogger().info("Failed to load " + file.getFileName()); - e.printStackTrace(); - continue; - } - } - files.put(file, newFile); - configurations.put(file, YamlConfiguration.loadConfiguration(newFile)); - if (log) Bukkit.getLogger().info("Successfully loaded " + file.getFileName()); - } - //Starts to load all the custom files. - if (homeFolders.size() > 0) { - if (log) Bukkit.getLogger().info("Loading custom files."); - for (String homeFolder : homeFolders) { - File homeFile = new File(plugin.getDataFolder(), "/" + homeFolder); - if (homeFile.exists()) { - String[] list = homeFile.list(); - if (list != null) { - for (String name : list) { - if (name.endsWith(".yml")) { - CustomFile file = new CustomFile(name, homeFolder, plugin); - if (file.exists()) { - customFiles.add(file); - if (log) Bukkit.getLogger().info("Loaded new custom file: " + homeFolder + "/" + name + "."); - } - } - } - } - - } else { - homeFile.mkdir(); - if (log) Bukkit.getLogger().info("The folder " + homeFolder + "/ was not found so it was created."); - for (String fileName : autoGenerateFiles.keySet()) { - if (autoGenerateFiles.get(fileName).equalsIgnoreCase(homeFolder)) { - homeFolder = autoGenerateFiles.get(fileName); - try { - File serverFile = new File(plugin.getDataFolder(), homeFolder + "/" + fileName); - InputStream jarFile = getClass().getResourceAsStream(homeFolder + "/" + fileName); - copyFile(jarFile, serverFile); - if (fileName.toLowerCase().endsWith(".yml")) { - customFiles.add(new CustomFile(fileName, homeFolder, plugin)); - } - if (log) Bukkit.getLogger().info("Created new default file: " + homeFolder + "/" + fileName + "."); - } catch (Exception e) { - if (log) Bukkit.getLogger().info("Failed to create new default file: " + homeFolder + "/" + fileName + "!"); - e.printStackTrace(); - } - } - } - } - } - if (log) Bukkit.getLogger().info("Finished loading custom files."); - } - return this; - } - - /** - * Turn on the logger system for the FileManager. - * @param log True to turn it on and false for it to be off. - */ - public FileManager logInfo(Boolean log) { - this.log = log; - return this; - } - - /** - * Check if the logger is logging in console. - * @return True if it is and false if it isn't. - */ - public Boolean isLogging() { - return log; - } - - /** - * Register a folder that has custom files in it. Make sure to have a "/" in front of the folder name. - * @param homeFolder The folder that has custom files in it. - */ - public FileManager registerCustomFilesFolder(String homeFolder) { - homeFolders.add(homeFolder); - return this; - } - - /** - * Unregister a folder that has custom files in it. Make sure to have a "/" in front of the folder name. - * @param homeFolder The folder with custom files in it. - */ - public FileManager unregisterCustomFilesFolder(String homeFolder) { - homeFolders.remove(homeFolder); - return this; - } - - /** - * Register a file that needs to be generated when it's home folder doesn't exist. Make sure to have a "/" in front of the home folder's name. - * @param fileName The name of the file you want to auto-generate when the folder doesn't exist. - * @param homeFolder The folder that has custom files in it. - */ - public FileManager registerDefaultGenerateFiles(String fileName, String homeFolder) { - autoGenerateFiles.put(fileName, homeFolder); - return this; - } - - /** - * Unregister a file that doesn't need to be generated when it's home folder doesn't exist. Make sure to have a "/" in front of the home folder's name. - * @param fileName The file that you want to remove from auto-generating. - */ - public FileManager unregisterDefaultGenerateFiles(String fileName) { - autoGenerateFiles.remove(fileName); - return this; - } - - /** - * Gets the file from the system. - * @return The file from the system. - */ - public FileConfiguration getFile(Files file) { - return configurations.get(file); - } - - /** - * Get a custom file from the loaded custom files instead of a hardcoded one. - * This allows you to get custom files like Per player data files. - * @param name Name of the crate you want. (Without the .yml) - * @return The custom file you wanted otherwise if not found will return null. - */ - public CustomFile getFile(String name) { - for (CustomFile file : customFiles) { - if (file.getName().equalsIgnoreCase(name)) { - return file; - } - } - return null; - } - - /** - * Saves the file from the loaded state to the file system. - */ - public void saveFile(Files file, boolean sync) { - try { - File targetFile = files.get(file); - FileConfiguration configuration = configurations.get(file); - - YamlConfiguration copy = new YamlConfiguration(); - configuration.getValues(false).forEach(copy :: set); - - BukkitRunnable runnable = new BukkitRunnable() { - @Override - public void run() { - try { - copy.save(targetFile); - } catch (IOException e) { - Bukkit.getLogger().info("Could not save " + file.getFileName() + "!"); - e.printStackTrace(); - } - } - }; - if (sync) { - runnable.run(); - } else { - runnable.runTaskAsynchronously(plugin); - } - } catch (NullPointerException e) { - Bukkit.getLogger().info("File is null " + file.getFileName() + "!"); - e.printStackTrace(); - } - } - - /** - * Save a custom file. - * @param name The name of the custom file. - */ - public void saveFile(String name) { - CustomFile file = getFile(name); - if (file != null) { - try { - file.getFile().save(new File(plugin.getDataFolder(), file.getHomeFolder() + "/" + file.getFileName())); - if (log) Bukkit.getLogger().info("Successfuly saved the " + file.getFileName() + "."); - } catch (Exception e) { - Bukkit.getLogger().info("Could not save " + file.getFileName() + "!"); - e.printStackTrace(); - } - } else { - if (log) Bukkit.getLogger().info("The file " + name + ".yml could not be found!"); - } - } - - /** - * Save a custom file. - * @param file The custom file you are saving. - * @return True if the file saved correct and false if there was an error. - */ - public Boolean saveFile(CustomFile file) { - return file.saveFile(); - } - - /** - * Overrides the loaded state file and loads the file systems file. - */ - public void reloadFile(Files file) { - configurations.put(file, YamlConfiguration.loadConfiguration(files.get(file))); - } - - /** - * Overrides the loaded state file and loads the file systems file. - */ - public void reloadFile(String name) { - CustomFile file = getFile(name); - if (file != null) { - try { - file.file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + file.getHomeFolder() + "/" + file.getFileName())); - if (log) Bukkit.getLogger().info("Successfuly reload the " + file.getFileName() + "."); - } catch (Exception e) { - Bukkit.getLogger().info("Could not reload the " + file.getFileName() + "!"); - e.printStackTrace(); - } - } else { - if (log) Bukkit.getLogger().info("The file " + name + ".yml could not be found!"); - } - } - - /** - * Overrides the loaded state file and loads the filesystems file. - * @return True if it reloaded correct and false if the file wasn't found. - */ - public Boolean reloadFile(CustomFile file) { - return file.reloadFile(); - } - - /** - * Was found here: https://bukkit.org/threads/extracting-file-from-jar.16962 - */ - private void copyFile(InputStream in, File out) throws Exception { - try (FileOutputStream fos = new FileOutputStream(out)) { - byte[] buf = new byte[1024]; - int i; - while ((i = in.read(buf)) != -1) { - fos.write(buf, 0, i); - } - } finally { - if (in != null) { - in.close(); - } - - } - } - - public enum Files { - - //ENUM_NAME("FileName.yml", "FilePath.yml"), - CONFIG("config.yml", "config.yml"), - DATA("Data.yml", "Data.yml"), - MESSAGES("Messages.yml", "Messages.yml"), - TEST_FILE("Test-File.yml", "Test-File.yml"); - - private final String fileName; - private final String fileLocation; - - /** - * The files that the server will try and load. - * @param fileName The file name that will be in the plugin's folder. - * @param fileLocation The location the file is in while in the Jar. - */ - private Files(String fileName, String fileLocation) { - this.fileName = fileName; - this.fileLocation = fileLocation; - } - - /** - * Get the name of the file. - * @return The name of the file. - */ - public String getFileName() { - return fileName; - } - - /** - * The location the jar it is at. - * @return The location in the jar the file is in. - */ - public String getFileLocation() { - return fileLocation; - } - - /** - * Gets the file from the system. - * @return The file from the system. - */ - public FileConfiguration getFile() { - return getInstance().getFile(this); - } - - /** - * Saves the file from the loaded state to the file system. - */ - public void saveFile(boolean sync) { - getInstance().saveFile(this, sync); - } - - public void saveFile() { - getInstance().saveFile(this, false); - } - - /** - * Overrides the loaded state file and loads the file systems file. - */ - public void relaodFile() { - getInstance().reloadFile(this); - } - - } - - public class CustomFile { - - private String name; - private Plugin plugin; - private String fileName; - private String homeFolder; - private FileConfiguration file; - - /** - * A custom file that is being made. - * @param name Name of the file. - * @param homeFolder The home folder of the file. - * @param plugin The plugin the files belong to. - */ - public CustomFile(String name, String homeFolder, Plugin plugin) { - this.name = name.replace(".yml", ""); - this.plugin = plugin; - this.fileName = name; - this.homeFolder = homeFolder; - if (new File(plugin.getDataFolder(), "/" + homeFolder).exists()) { - if (new File(plugin.getDataFolder(), "/" + homeFolder + "/" + name).exists()) { - file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + homeFolder + "/" + name)); - } else { - file = null; - } - } else { - new File(plugin.getDataFolder(), "/" + homeFolder).mkdir(); - if (log) Bukkit.getLogger().info("The folder " + homeFolder + "/ was not found so it was created."); - file = null; - } - } - - /** - * Get the name of the file without the .yml part. - * @return The name of the file without the .yml. - */ - public String getName() { - return name; - } - - /** - * Get the full name of the file. - * @return Full name of the file. - */ - public String getFileName() { - return fileName; - } - - /** - * Get the name of the home folder of the file. - * @return The name of the home folder the files are in. - */ - public String getHomeFolder() { - return homeFolder; - } - - /** - * Get the plugin the file belongs to. - * @return The plugin the file belongs to. - */ - public Plugin getPlugin() { - return plugin; - } - - /** - * Get the ConfigurationFile. - * @return The ConfigurationFile of this file. - */ - public FileConfiguration getFile() { - return file; - } - - /** - * Check if the file actually exists in the file system. - * @return True if it does and false if it doesn't. - */ - public Boolean exists() { - return file != null; - } - - /** - * Save the custom file. - * @return True if it saved correct and false if something went wrong. - */ - public Boolean saveFile() { - if (file != null) { - try { - file.save(new File(plugin.getDataFolder(), homeFolder + "/" + fileName)); - if (log) Bukkit.getLogger().info("Successfuly saved the " + fileName + "."); - return true; - } catch (Exception e) { - Bukkit.getLogger().info("Could not save " + fileName + "!"); - e.printStackTrace(); - return false; - } - } else { - if (log) Bukkit.getLogger().info("There was a null custom file that could not be found!"); - } - return false; - } - - /** - * Overrides the loaded state file and loads the filesystems file. - * @return True if it reloaded correct and false if the file wasn't found or errored. - */ - public Boolean reloadFile() { - if (file != null) { - try { - file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + homeFolder + "/" + fileName)); - if (log) Bukkit.getLogger().info("Successfuly reload the " + fileName + "."); - return true; - } catch (Exception e) { - Bukkit.getLogger().info("Could not reload the " + fileName + "!"); - e.printStackTrace(); - } - } else { - if (log) Bukkit.getLogger().info("There was a null custom file that was not found!"); - } - return false; - } - - } - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/Version.java b/paper/src/main/java/com/badbones69/crazyauctions/api/Version.java deleted file mode 100644 index 7b57a9d..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/Version.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.badbones69.crazyauctions.api; - -import org.bukkit.Bukkit; - -public enum Version { - - TOO_OLD(-1), - v1_7_R1(171), v1_7_R2(172), v1_7_R3(173), v1_7_R4(174), - v1_8_R1(181), v1_8_R2(182), v1_8_R3(183), - v1_9_R1(191), v1_9_R2(192), - v1_10_R1(1101), - v1_11_R1(1111), - v1_12_R1(1121), - v1_13_R2(1132), - v1_14_R1(1141), - v1_15_R1(1151), - v1_16_R1(1161), v1_16_R2(1162), v1_16_R3(1163), - TOO_NEW(-2); - - private static Version currentVersion; - private static Version latest; - private final int versionInteger; - - private Version(int versionInteger) { - this.versionInteger = versionInteger; - } - - /** - * - * @return Get the server's Minecraft version. - */ - public static Version getCurrentVersion() { - if (currentVersion == null) { - String ver = Bukkit.getServer().getClass().getPackage().getName(); - int v = Integer.parseInt(ver.substring(ver.lastIndexOf('.') + 1).replace("_", "").replace("R", "").replace("v", "")); - for (Version version : values()) { - if (version.getVersionInteger() == v) { - currentVersion = version; - break; - } - } - if (v > Version.getLatestVersion().getVersionInteger()) { - currentVersion = Version.getLatestVersion(); - } - if (currentVersion == null) { - currentVersion = Version.TOO_NEW; - } - } - return currentVersion; - } - - /** - * Get the latest version allowed by the Version class. - * @return The latest version. - */ - public static Version getLatestVersion() { - if (latest == null) { - Version v = Version.TOO_OLD; - for (Version version : values()) { - if (version.comparedTo(v) == 1) { - v = version; - } - } - return v; - } else { - return latest; - - } - } - - /** - * - * @return The server's minecraft version as an integer. - */ - public int getVersionInteger() { - return this.versionInteger; - } - - /** - * This checks if the current version is older, newer, or is the checked version. - * @param version The version you are checking. - * @return -1 if older, 0 if the same, and 1 if newer. - */ - public int comparedTo(Version version) { - int result = -1; - int current = this.getVersionInteger(); - int check = version.getVersionInteger(); - if (current > check || check == -2) {// check is newer then current - result = 1; - } else if (current == check) {// check is the same as current - result = 0; - } else if (check == -1) {// check is older then current - result = -1; - } - return result; - } - - /** - * Checks to see if the current version is newer then the checked version. - * @param version The version you are checking. - * @return True if newer then the checked version and false if the same or older. - */ - public static boolean isNewer(Version version) { - if (currentVersion == null) getCurrentVersion(); - return currentVersion.versionInteger > version.versionInteger || currentVersion.versionInteger == -2; - } - - /** - * Checks to see if the current version is the same as the checked version. - * @param version The version you are checking. - * @return True if both the current and checked version is the same and false if otherwise. - */ - public static boolean isSame(Version version) { - if (currentVersion == null) getCurrentVersion(); - return currentVersion.versionInteger == version.versionInteger; - } - - /** - * Checks to see if the current version is older than the checked version. - * @param version The version you are checking. - * @return True if older than the checked version and false if the same or newer. - */ - public static boolean isOlder(Version version) { - if (currentVersion == null) getCurrentVersion(); - return currentVersion.versionInteger < version.versionInteger || currentVersion.versionInteger == -1; - } - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java b/paper/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java deleted file mode 100644 index 1347974..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.badbones69.crazyauctions.currency; - -import com.badbones69.crazyauctions.api.FileManager.Files; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -public enum CurrencyManager { // Currency Manager - - VAULT("Vault", "Money"); - - private final String pluginName; - private final String name; - - /** - * @param pluginname - * name of the Plugin. - * @param name - * name of the Currency. - */ - private CurrencyManager(String pluginname, String name) { - this.pluginName = pluginname; - this.name = name; - } - - /** - * @param name - * name of the Type you want. - * @return Returns the Currency as a Enum. - */ - public static CurrencyManager getFromName(String name) { - for (CurrencyManager type : CurrencyManager.values()) { - if (type.getPluginName().equalsIgnoreCase(name)) { - return type; - } - } - return null; - } - - /** - * - * @param player - * Player you want the currency from. - * @return Returns the amount they have of the currency - */ - public static Long getMoney(Player player) { - return Vault.getMoney(player); - } - - /** - * - * @param player - * Player you want the currency from. - * @param amount - * The amount you want to take. - */ - public static void removeMoney(Player player, Long amount) { - Vault.removeMoney(player, amount); - } - - /** - * - * @param player - * Player you want the currency from. - * @param amount - * The amount you want to take. - */ - public static void removeMoney(OfflinePlayer player, Long amount) { - Vault.removeMoney(player, amount); - } - - /** - * - * @param player - * Player you want the currency from. - * @param amount - * The amount you want to add. - */ - public static void addMoney(Player player, Long amount) { - Vault.addMoney(player, amount); - } - - /** - * - * @param player - * Player you want the currency from. - * @param amount - * The amount you want to add. - */ - public static void addMoney(OfflinePlayer player, Long amount) { - Vault.addMoney(player, amount); - } - - /** - * @return Returns the Currency name as a string. - */ - public String getName() { - return name; - } - - /** - * @return Returns the Currency name as a string. - */ - public String getPluginName() { - return pluginName; - } - - /** - * - * @return Returns true if the server has the plugin. - */ - public Boolean hasPlugin() { - if (Bukkit.getServer().getPluginManager().getPlugin(pluginName) != null) { - return Files.CONFIG.getFile().getBoolean("Settings.Currencies." + pluginName + ".Enabled"); - } - return false; - } - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/currency/Vault.java b/paper/src/main/java/com/badbones69/crazyauctions/currency/Vault.java deleted file mode 100644 index 4444942..0000000 --- a/paper/src/main/java/com/badbones69/crazyauctions/currency/Vault.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.badbones69.crazyauctions.currency; - -import net.milkbowl.vault.economy.Economy; -import net.milkbowl.vault.economy.EconomyResponse; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; -import org.bukkit.plugin.RegisteredServiceProvider; - -public class Vault { - - public static Economy econ = null; - public static EconomyResponse r; - - public static boolean hasVault() { - return Bukkit.getServer().getPluginManager().getPlugin("Vault") != null; - } - - public static boolean setupEconomy() { - if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) { - return false; - } - RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); - if (rsp == null) { - return false; - } - econ = rsp.getProvider(); - return econ != null; - } - - public static Long getMoney(Player player) { - if (player != null) { - try { - return (long) econ.getBalance(player); - } catch (NullPointerException ignore) { - } - } - return 0L; - } - - public static void removeMoney(Player player, Long amount) { - econ.withdrawPlayer(player, amount); - } - - public static void removeMoney(OfflinePlayer player, Long amount) { - econ.withdrawPlayer(player, amount); - } - - public static void addMoney(Player player, Long amount) { - econ.depositPlayer(player, amount); - } - - public static void addMoney(OfflinePlayer player, Long amount) { - econ.depositPlayer(player, amount); - } - -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/paper/CrazyAuctions.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/CrazyAuctions.java new file mode 100644 index 0000000..276f6d6 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/CrazyAuctions.java @@ -0,0 +1,111 @@ +package com.badbones69.crazyauctions.paper; + +import com.badbones69.crazyauctions.paper.api.CrazyManager; +import com.badbones69.crazyauctions.paper.api.FileManager; +import com.badbones69.crazyauctions.paper.api.enums.Messages; +import com.badbones69.crazyauctions.paper.api.support.PluginSupport; +import com.badbones69.crazyauctions.paper.api.support.metrics.MetricsWrapper; +import com.badbones69.crazyauctions.paper.commands.AuctionCommand; +import com.badbones69.crazyauctions.paper.commands.AuctionTab; +import com.badbones69.crazyauctions.paper.controllers.GuiListener; +import com.badbones69.crazyauctions.paper.controllers.MarcoListener; +import com.badbones69.crazyauctions.paper.currency.VaultSupport; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.PluginCommand; +import org.bukkit.command.TabCompleter; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import java.util.Timer; +import java.util.TimerTask; + +public class CrazyAuctions extends JavaPlugin { + + @NotNull + public static CrazyAuctions get() { + return JavaPlugin.getPlugin(CrazyAuctions.class); + } + + private Timer timer; + + private FileManager fileManager; + private CrazyManager crazyManager; + + private VaultSupport support; + + @Override + public void onEnable() { + this.timer = new Timer(); + + this.fileManager = new FileManager(); + this.crazyManager = new CrazyManager(); + + this.fileManager.setup(); + this.crazyManager.load(); + + getServer().getPluginManager().registerEvents(new GuiListener(), this); + getServer().getPluginManager().registerEvents(new MarcoListener(), this); + + registerCommand(getCommand("crazyauctions"), new AuctionTab(), new AuctionCommand()); + + // Run a task every 5 seconds to update auctions. + TimerTask task = new TimerTask() { + @Override + public void run() { + Methods.updateAuction(); + } + }; + + this.timer.scheduleAtFixedRate(task, 20L, 5000L); + + // Add new messages. + Messages.addMissingMessages(); + + // Enable vault support if enabled. + if (PluginSupport.VAULT.isPluginEnabled()) { + this.support = new VaultSupport(); + support.loadVault(); + } + + // Create bstats instance. + MetricsWrapper wrapper = new MetricsWrapper(); + wrapper.start(); + } + + private void registerCommand(PluginCommand pluginCommand, TabCompleter tabCompleter, CommandExecutor commandExecutor) { + if (pluginCommand != null) { + pluginCommand.setExecutor(commandExecutor); + + if (tabCompleter != null) pluginCommand.setTabCompleter(tabCompleter); + } + } + + @Override + public void onDisable() { + if (timer != null) timer.cancel(); + + this.crazyManager.unload(); + } + + @NotNull + public Timer getTimer() { + return this.timer; + } + + public VaultSupport getSupport() { + return this.support; + } + + @NotNull + public CrazyManager getCrazyManager() { + return this.crazyManager; + } + + @NotNull + public FileManager getFileManager() { + return this.fileManager; + } + + public boolean isLogging() { + return true; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/Methods.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/Methods.java similarity index 81% rename from paper/src/main/java/com/badbones69/crazyauctions/Methods.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/Methods.java index c2c098c..884413d 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/Methods.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/Methods.java @@ -1,11 +1,9 @@ -package com.badbones69.crazyauctions; +package com.badbones69.crazyauctions.paper; -import com.badbones69.crazyauctions.api.FileManager.Files; -import com.badbones69.crazyauctions.api.Messages; -import com.badbones69.crazyauctions.api.Version; -import com.badbones69.crazyauctions.api.events.AuctionExpireEvent; -import com.badbones69.crazyauctions.api.events.AuctionWinBidEvent; -import com.badbones69.crazyauctions.currency.CurrencyManager; +import com.badbones69.crazyauctions.paper.api.FileManager.Files; +import com.badbones69.crazyauctions.paper.api.enums.Messages; +import com.badbones69.crazyauctions.paper.api.events.AuctionExpireEvent; +import com.badbones69.crazyauctions.paper.api.events.AuctionWinBidEvent; import org.bukkit.*; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; @@ -19,18 +17,19 @@ import java.util.regex.Pattern; public class Methods { - public final static Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F0-9]{6}"); + private final static CrazyAuctions plugin = CrazyAuctions.get(); + + private final static Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F0-9]{6}"); public static String color(String message) { - if (Version.isNewer(Version.v1_15_R1)) { - Matcher matcher = HEX_PATTERN.matcher(message); - StringBuffer buffer = new StringBuffer(); - while (matcher.find()) { - matcher.appendReplacement(buffer, net.md_5.bungee.api.ChatColor.of(matcher.group()).toString()); - } - return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString()); + Matcher matcher = HEX_PATTERN.matcher(message); + StringBuilder buffer = new StringBuilder(); + + while (matcher.find()) { + matcher.appendReplacement(buffer, net.md_5.bungee.api.ChatColor.of(matcher.group()).toString()); } - return ChatColor.translateAlternateColorCodes('&', message); + + return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString()); } public static String getPrefix() { @@ -47,46 +46,45 @@ public class Methods { 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) { - if (Version.isNewer(Version.v1_12_R1)) { - item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1); - - } else { - item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14); - } + 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) { - if (Version.isNewer(Version.v1_12_R1)) { - item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1); - - } else { - item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14); - } + item = new ItemStack(Material.RED_TERRACOTTA); } + ItemMeta me = item.getItemMeta(); + me.setDisplayName(color(name)); item.setItemMeta(me); return item; @@ -102,22 +100,21 @@ public class Methods { } Material m = Material.matchMaterial(type); ItemStack item; + try { item = new ItemStack(m, amount, (short) ty); } catch (Exception e) { - if (Version.isNewer(Version.v1_12_R1)) { - item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1); - - } else { - item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14); - } + item = new ItemStack(Material.RED_TERRACOTTA); } + ItemMeta me = item.getItemMeta(); me.setDisplayName(color(name)); - for (String L : lore) - l.add(color(L)); + + for (String L : lore) l.add(color(L)); + me.setLore(l); item.setItemMeta(me); + return item; } @@ -126,6 +123,7 @@ public class Methods { ItemMeta m = item.getItemMeta(); m.setDisplayName(color(name)); item.setItemMeta(m); + return item; } @@ -133,30 +131,35 @@ public class Methods { 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)); + 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); @@ -167,40 +170,25 @@ public class Methods { 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)); + + for (String i : list) lore.add(color(i)); m.setLore(lore); item.setItemMeta(m); } + return item; } - - public static Integer getVersion() { - String ver = Bukkit.getServer().getClass().getPackage().getName(); - ver = ver.substring(ver.lastIndexOf('.') + 1); - ver = ver.replace("_", "").replace("R", "").replace("v", ""); - return Integer.parseInt(ver); - } - - @SuppressWarnings("deprecation") + public static ItemStack getItemInHand(Player player) { - if (getVersion() >= 191) { - return player.getInventory().getItemInMainHand(); - } else { - return player.getItemInHand(); - } + return player.getInventory().getItemInMainHand(); } - - @SuppressWarnings("deprecation") + public static void setItemInHand(Player player, ItemStack item) { - if (getVersion() >= 191) { - player.getInventory().setItemInMainHand(item); - } else { - player.setItemInHand(item); - } + player.getInventory().setItemInMainHand(item); } public static boolean isInt(String s) { @@ -209,6 +197,7 @@ public class Methods { } catch (NumberFormatException nfe) { return false; } + return true; } @@ -218,6 +207,7 @@ public class Methods { } catch (NumberFormatException nfe) { return false; } + return true; } @@ -228,26 +218,18 @@ public class Methods { return null; } } - - @SuppressWarnings("deprecation") + public static OfflinePlayer getOfflinePlayer(String name) { return Bukkit.getServer().getOfflinePlayer(name); } - - public static Location getLoc(Player player) { - return player.getLocation(); - } - - public static void runCMD(Player player, String CMD) { - player.performCommand(CMD); - } - + public static boolean isOnline(String name) { for (Player player : Bukkit.getServer().getOnlinePlayers()) { if (player.getName().equalsIgnoreCase(name)) { return true; } } + return false; } @@ -257,6 +239,7 @@ public class Methods { return true; } } + p.sendMessage(Messages.NOT_ONLINE.getMessage()); return false; } @@ -266,21 +249,21 @@ public class Methods { player.sendMessage(Messages.NO_PERMISSION.getMessage()); return false; } + return true; } public static boolean hasPermission(CommandSender sender, String perm) { - if (sender instanceof Player) { - Player player = (Player) sender; + if (sender instanceof Player player) { if (!player.hasPermission("crazyauctions." + perm)) { player.sendMessage(Messages.NO_PERMISSION.getMessage()); return false; - } else { - return true; } - } else { + return true; } + + return true; } public static List getPage(List list, Integer page) { @@ -292,6 +275,7 @@ public class Methods { for (; index < endIndex; index++) { if (index < list.size()) items.add(list.get(index)); } + for (; items.size() == 0; page--) { if (page <= 0) break; index = page * max - max; @@ -300,6 +284,7 @@ public class Methods { if (index < list.size()) items.add(list.get(index)); } } + return items; } @@ -309,9 +294,11 @@ public class Methods { int max = 45; int index = page * max - max; int endIndex = index >= list.size() ? list.size() - 1 : index + max; + for (; index < endIndex; index++) { if (index < list.size()) items.add(list.get(index)); } + for (; items.size() == 0; page--) { if (page <= 0) break; index = page * max - max; @@ -320,6 +307,7 @@ public class Methods { if (index < list.size()) items.add(list.get(index)); } } + return items; } @@ -348,6 +336,7 @@ public class Methods { public static long convertToMill(String time) { Calendar cal = Calendar.getInstance(); + for (String i : time.split(" ")) { if (i.contains("D") || i.contains("d")) { cal.add(Calendar.DATE, Integer.parseInt(i.replace("D", "").replace("d", ""))); @@ -362,6 +351,7 @@ public class Methods { cal.add(Calendar.SECOND, Integer.parseInt(i.replace("S", "").replace("s", ""))); } } + return cal.getTimeInMillis(); } @@ -375,6 +365,7 @@ public class Methods { Calendar expireTime = Calendar.getInstance(); Calendar fullExpireTime = Calendar.getInstance(); boolean shouldSave = false; + if (data.contains("OutOfTime/Cancelled")) { for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { fullExpireTime.setTimeInMillis(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time")); @@ -384,33 +375,41 @@ public class Methods { } } } + if (data.contains("Items")) { for (String i : data.getConfigurationSection("Items").getKeys(false)) { expireTime.setTimeInMillis(data.getLong("Items." + i + ".Time-Till-Expire")); fullExpireTime.setTimeInMillis(data.getLong("Items." + i + ".Full-Time")); + if (cal.after(expireTime)) { int num = 1; for (; data.contains("OutOfTime/Cancelled." + num); num++) ; - if (data.getBoolean("Items." + i + ".Biddable") && !data.getString("Items." + i + ".TopBidder").equalsIgnoreCase("None") && CurrencyManager.getMoney(getPlayer(data.getString("Items." + i + ".TopBidder"))) >= data.getInt("Items." + i + ".Price")) { + + if (data.getBoolean("Items." + i + ".Biddable") && !data.getString("Items." + i + ".TopBidder").equalsIgnoreCase("None") && plugin.getSupport().getMoney(getPlayer(data.getString("Items." + i + ".TopBidder"))) >= data.getInt("Items." + i + ".Price")) { String winner = data.getString("Items." + i + ".TopBidder"); String seller = data.getString("Items." + i + ".Seller"); Long price = data.getLong("Items." + i + ".Price"); - CurrencyManager.addMoney(getOfflinePlayer(seller), price); - CurrencyManager.removeMoney(getOfflinePlayer(winner), price); + + plugin.getSupport().addMoney(getOfflinePlayer(seller), price); + plugin.getSupport().removeMoney(getOfflinePlayer(winner), price); + HashMap placeholders = new HashMap<>(); placeholders.put("%Price%", getPrice(i, false)); placeholders.put("%price%", getPrice(i, false)); placeholders.put("%Player%", winner); placeholders.put("%player%", winner); + if (isOnline(winner) && getPlayer(winner) != null) { Player player = getPlayer(winner); Bukkit.getPluginManager().callEvent(new AuctionWinBidEvent(player, data.getItemStack("Items." + i + ".Item"), price)); player.sendMessage(Messages.WIN_BIDDING.getMessage(placeholders)); } + if (isOnline(seller) && getPlayer(seller) != null) { Player player = getPlayer(seller); player.sendMessage(Messages.SOMEONE_WON_PLAYERS_BID.getMessage(placeholders)); } + data.set("OutOfTime/Cancelled." + num + ".Seller", winner); data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis()); data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); @@ -418,9 +417,11 @@ public class Methods { } else { String seller = data.getString("Items." + i + ".Seller"); Player player = getPlayer(seller); + if (isOnline(seller) && getPlayer(seller) != null) { player.sendMessage(Messages.ITEM_HAS_EXPIRED.getMessage()); } + AuctionExpireEvent event = new AuctionExpireEvent(player, data.getItemStack("Items." + i + ".Item")); Bukkit.getPluginManager().callEvent(event); data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); @@ -428,16 +429,19 @@ public class Methods { data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item")); } + data.set("Items." + i, null); shouldSave = true; } } } + if (shouldSave) Files.DATA.saveFile(); } public static String getPrice(String ID, Boolean Expired) { long price = 0L; + if (Expired) { if (Files.DATA.getFile().contains("OutOfTime/Cancelled." + ID + ".Price")) { price = Files.DATA.getFile().getLong("OutOfTime/Cancelled." + ID + ".Price"); @@ -447,7 +451,7 @@ public class Methods { price = Files.DATA.getFile().getLong("Items." + ID + ".Price"); } } + return String.valueOf(price); } - } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/paper/api/CrazyManager.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/CrazyManager.java new file mode 100644 index 0000000..5bd8b65 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/CrazyManager.java @@ -0,0 +1,55 @@ +package com.badbones69.crazyauctions.paper.api; + +import com.badbones69.crazyauctions.paper.api.FileManager.Files; +import com.badbones69.crazyauctions.paper.api.enums.ShopType; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; + +public class CrazyManager { + + private boolean sellingEnabled; + private boolean biddingEnabled; + + public void load() { + this.sellingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Selling", true); + + this.biddingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Bidding", true); + } + + public void unload() { + Files.DATA.saveFile(); + } + + public boolean isSellingEnabled() { + return sellingEnabled; + } + + public boolean isBiddingEnabled() { + return biddingEnabled; + } + + public ArrayList getItems(Player player, ShopType type) { + FileConfiguration data = Files.DATA.getFile(); + ArrayList items = new ArrayList<>(); + + if (data.contains("Items")) { + for (String i : data.getConfigurationSection("Items").getKeys(false)) { + if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { + if (data.getBoolean("Items." + i + ".Biddable")) { + if (type == ShopType.BID) { + items.add(data.getItemStack("Items." + i + ".Item").clone()); + } + } else { + if (type == ShopType.SELL) { + items.add(data.getItemStack("Items." + i + ".Item").clone()); + } + } + } + } + } + + return items; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/paper/api/FileManager.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/FileManager.java new file mode 100644 index 0000000..fe3bf3e --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/FileManager.java @@ -0,0 +1,505 @@ +package com.badbones69.crazyauctions.paper.api; + +import com.badbones69.crazyauctions.paper.CrazyAuctions; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.jetbrains.annotations.NotNull; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.logging.Level; + +public class FileManager { + + @NotNull + private final CrazyAuctions plugin = CrazyAuctions.get(); + + private final HashMap files = new HashMap<>(); + private final List homeFolders = new ArrayList<>(); + private final List customFiles = new ArrayList<>(); + private final HashMap jarHomeFolders = new HashMap<>(); + private final HashMap autoGenerateFiles = new HashMap<>(); + private final HashMap configurations = new HashMap<>(); + + /** + * Sets up the plugin and loads all necessary files. + */ + public FileManager setup() { + if (!this.plugin.getDataFolder().exists()) this.plugin.getDataFolder().mkdirs(); + + this.files.clear(); + this.customFiles.clear(); + this.configurations.clear(); + + // Loads all the normal static files. + for (Files file : Files.values()) { + File newFile = new File(this.plugin.getDataFolder(), file.getFileLocation()); + + if (this.plugin.isLogging()) this.plugin.getLogger().info("Loading the " + file.getFileName()); + + if (!newFile.exists()) { + try (InputStream jarFile = getClass().getResourceAsStream("/" + file.getFileJar())) { + File serverFile = new File(this.plugin.getDataFolder(), "/" + file.getFileLocation()); + copyFile(jarFile, serverFile); + } catch (Exception exception) { + this.plugin.getLogger().log(Level.WARNING, "Failed to load file: " + file.getFileName(), exception); + continue; + } + } + + this.files.put(file, newFile); + if (file.getFileName().endsWith(".yml")) this.configurations.put(file, YamlConfiguration.loadConfiguration(newFile)); + + if (this.plugin.isLogging()) this.plugin.getLogger().info("Successfully loaded " + file.getFileName()); + } + + // Starts to load all the custom files. + if (!this.homeFolders.isEmpty()) { + if (this.plugin.isLogging()) this.plugin.getLogger().info("Loading custom files."); + + for (String homeFolder : this.homeFolders) { + File homeFile = new File(this.plugin.getDataFolder(), "/" + homeFolder); + + if (homeFile.exists()) { + String[] list = homeFile.list(); + + if (list != null) { + for (String name : list) { + if (name.endsWith(".yml")) { + CustomFile file = new CustomFile(name, homeFolder); + + if (file.exists()) { + this.customFiles.add(file); + + if (this.plugin.isLogging()) this.plugin.getLogger().info("Loaded new custom file: " + homeFolder + "/" + name + "."); + } + } + } + } + } else { + homeFile.mkdir(); + + if (this.plugin.isLogging()) this.plugin.getLogger().info("The folder " + homeFolder + "/ was not found so it was created."); + + for (String fileName : this.autoGenerateFiles.keySet()) { + if (this.autoGenerateFiles.get(fileName).equalsIgnoreCase(homeFolder)) { + homeFolder = this.autoGenerateFiles.get(fileName); + + try (InputStream jarFile = getClass().getResourceAsStream((this.jarHomeFolders.getOrDefault(fileName, homeFolder)) + "/" + fileName)) { + File serverFile = new File(this.plugin.getDataFolder(), homeFolder + "/" + fileName); + copyFile(jarFile, serverFile); + + if (fileName.toLowerCase().endsWith(".yml")) this.customFiles.add(new CustomFile(fileName, homeFolder)); + + if (this.plugin.isLogging()) this.plugin.getLogger().info("Created new default file: " + homeFolder + "/" + fileName + "."); + } catch (Exception exception) { + this.plugin.getLogger().log(Level.SEVERE, "Failed to create new default file: " + homeFolder + "/" + fileName + "!", exception); + } + } + } + } + } + + if (this.plugin.isLogging()) this.plugin.getLogger().info("Finished loading custom files."); + } + + return this; + } + + /** + * Register a folder that has custom files in it. Make sure to have a "/" in front of the folder name. + * @param homeFolder The folder that has custom files in it. + */ + public FileManager registerCustomFilesFolder(String homeFolder) { + this.homeFolders.add(homeFolder); + return this; + } + + /** + * Unregister a folder that has custom files in it. Make sure to have a "/" in front of the folder name. + * @param homeFolder The folder with custom files in it. + */ + public FileManager unregisterCustomFilesFolder(String homeFolder) { + this.homeFolders.remove(homeFolder); + return this; + } + + /** + * Register a file that needs to be generated when it's home folder doesn't exist. Make sure to have a "/" in front of the home folder's name. + * @param fileName The name of the file you want to auto-generate when the folder doesn't exist. + * @param homeFolder The folder that has custom files in it. + */ + public FileManager registerDefaultGenerateFiles(String fileName, String homeFolder) { + this.autoGenerateFiles.put(fileName, homeFolder); + return this; + } + + /** + * Register a file that needs to be generated when it's home folder doesn't exist. Make sure to have a "/" in front of the home folder's name. + * @param fileName The name of the file you want to auto-generate when the folder doesn't exist. + * @param homeFolder The folder that has custom files in it. + * @param jarHomeFolder The folder that the file is found in the jar. + */ + public FileManager registerDefaultGenerateFiles(String fileName, String homeFolder, String jarHomeFolder) { + this.autoGenerateFiles.put(fileName, homeFolder); + this.jarHomeFolders.put(fileName, jarHomeFolder); + return this; + } + + /** + * Unregister a file that doesn't need to be generated when it's home folder doesn't exist. Make sure to have a "/" in front of the home folder's name. + * @param fileName The file that you want to remove from auto-generating. + */ + public FileManager unregisterDefaultGenerateFiles(String fileName) { + this.autoGenerateFiles.remove(fileName); + this.jarHomeFolders.remove(fileName); + return this; + } + + /** + * Gets the file from the system. + * @return The file from the system. + */ + public FileConfiguration getFile(Files file) { + return this.configurations.get(file); + } + + /** + * Get a custom file from the loaded custom files instead of a hardcoded one. + * This allows you to get custom files like Per player data files. + * @param name Name of the crate you want. (Without the .yml) + * @return The custom file you wanted otherwise if not found will return null. + */ + public CustomFile getFile(String name) { + for (CustomFile file : this.customFiles) { + if (file.getName().equalsIgnoreCase(name)) { + return file; + } + } + + return null; + } + + public void removeFile(String name) { + this.customFiles.remove(getFile(name)); + } + + public void addFile(String name, String folder) { + this.customFiles.add(new CustomFile(name, folder)); + } + + /** + * Saves the file from the loaded state to the file system. + */ + public void saveFile(Files file) { + try { + this.configurations.get(file).save(this.files.get(file)); + } catch (IOException exception) { + this.plugin.getLogger().log(Level.SEVERE, "Could not save " + file.getFileName() + "!", exception); + } + } + + /** + * Save a custom file. + * @param name The name of the custom file. + */ + public void saveFile(String name) { + CustomFile file = getFile(name); + + if (file == null) { + if (this.plugin.isLogging()) this.plugin.getLogger().warning("The file " + name + ".yml could not be found!"); + return; + } + + try { + file.getFile().save(new File(this.plugin.getDataFolder(), file.getHomeFolder() + "/" + file.getFileName())); + + if (this.plugin.isLogging()) this.plugin.getLogger().info("Successfully saved the " + file.getFileName() + "."); + } catch (Exception exception) { + this.plugin.getLogger().log(Level.SEVERE, "Could not save " + file.getFileName() + "!", exception); + } + } + + /** + * Save a custom file. + * + * @param file The custom file you are saving. + */ + public void saveFile(CustomFile file) { + file.saveFile(); + } + + /** + * Overrides the loaded state file and loads the file systems file. + */ + public void reloadFile(Files file) { + if (file.getFileName().endsWith(".yml")) this.configurations.put(file, YamlConfiguration.loadConfiguration(this.files.get(file))); + } + + /** + * Overrides the loaded state file and loads the file systems file. + */ + public void reloadFile(String name) { + CustomFile file = getFile(name); + + if (file != null) { + try { + file.file = YamlConfiguration.loadConfiguration(new File(this.plugin.getDataFolder(), "/" + file.getHomeFolder() + "/" + file.getFileName())); + + if (this.plugin.isLogging()) this.plugin.getLogger().info("Successfully reloaded the " + file.getFileName() + "."); + } catch (Exception exception) { + this.plugin.getLogger().log(Level.SEVERE, "Could not reload the " + file.getFileName() + "!", exception); + } + } else { + if (this.plugin.isLogging()) this.plugin.getLogger().warning("The file " + name + ".yml could not be found!"); + } + } + + /** + * Overrides the loaded state file and loads the filesystems file. + */ + public void reloadFile(CustomFile file) { + file.reloadFile(); + } + + public void reloadAllFiles() { + for (Files file : Files.values()) { + file.reloadFile(); + } + + for (CustomFile file : this.customFiles) { + file.reloadFile(); + } + } + + public List getAllCratesNames() { + List files = new ArrayList<>(); + + String[] file = new File(this.plugin.getDataFolder(), "/crates").list(); + + if (file != null) { + for (String name : file) { + if (!name.endsWith(".yml")) continue; + + files.add(name.replaceAll(".yml", "")); + } + } + + return files; + } + + /** + * Was found here: ... + */ + private void copyFile(InputStream in, File out) throws Exception { + try (InputStream fis = in; FileOutputStream fos = new FileOutputStream(out)) { + byte[] buf = new byte[1024]; + int i; + + while ((i = fis.read(buf)) != -1) { + fos.write(buf, 0, i); + } + } + } + + public enum Files { + + // ENUM_NAME("fileName.yml", "fileLocation.yml"), + // ENUM_NAME("fileName.yml", "newFileLocation.yml", "oldFileLocation.yml"), + CONFIG("config.yml", "config.yml"), + MESSAGES("messages.yml", "messages.yml"), + TEST_FILE("test-file.yml", "test-file.yml"), + DATA("data.yml", "data.yml"); + + private final String fileName; + private final String fileJar; + private final String fileLocation; + + @NotNull + private final CrazyAuctions plugin = CrazyAuctions.get(); + + @NotNull + private final FileManager fileManager = this.plugin.getFileManager(); + + /** + * The files that the server will try and load. + * @param fileName The file name that will be in the plugin's folder. + * @param fileLocation The location the file in the plugin's folder. + */ + Files(String fileName, String fileLocation) { + this(fileName, fileLocation, fileLocation); + } + + /** + * The files that the server will try and load. + * @param fileName The file name that will be in the plugin's folder. + * @param fileLocation The location of the file will be in the plugin's folder. + * @param fileJar The location of the file in the jar. + */ + Files(String fileName, String fileLocation, String fileJar) { + this.fileName = fileName; + this.fileLocation = fileLocation; + this.fileJar = fileJar; + } + + /** + * Get the name of the file. + * @return The name of the file. + */ + public String getFileName() { + return this.fileName; + } + + /** + * The location the jar it is at. + * @return The location in the jar the file is in. + */ + public String getFileLocation() { + return this.fileLocation; + } + + /** + * Get the location of the file in the jar. + * @return The location of the file in the jar. + */ + public String getFileJar() { + return this.fileJar; + } + + /** + * Gets the file from the system. + * @return The file from the system. + */ + public FileConfiguration getFile() { + return this.fileManager.getFile(this); + } + + /** + * Saves the file from the loaded state to the file system. + */ + public void saveFile() { + this.fileManager.saveFile(this); + } + + /** + * Overrides the loaded state file and loads the file systems file. + */ + public void reloadFile() { + if (this.getFileName().endsWith(".yml")) this.fileManager.reloadFile(this); + } + } + + public static class CustomFile { + + private final String name; + private final String fileName; + private final String homeFolder; + private FileConfiguration file; + + @NotNull + private final CrazyAuctions plugin = CrazyAuctions.get(); + + /** + * A custom file that is being made. + * @param name Name of the file. + * @param homeFolder The home folder of the file. + */ + public CustomFile(String name, String homeFolder) { + this.name = name.replace(".yml", ""); + this.fileName = name; + this.homeFolder = homeFolder; + + if (new File(this.plugin.getDataFolder(), "/" + homeFolder).exists()) { + if (new File(this.plugin.getDataFolder(), "/" + homeFolder + "/" + name).exists()) { + this.file = YamlConfiguration.loadConfiguration(new File(this.plugin.getDataFolder(), "/" + homeFolder + "/" + name)); + } else { + this.file = null; + } + } else { + new File(this.plugin.getDataFolder(), "/" + homeFolder).mkdir(); + + if (this.plugin.isLogging()) this.plugin.getLogger().info("The folder " + homeFolder + "/ was not found so it was created."); + + this.file = null; + } + } + + /** + * Get the name of the file without the .yml part. + * @return The name of the file without the .yml. + */ + public String getName() { + return this.name; + } + + /** + * Get the full name of the file. + * @return Full name of the file. + */ + public String getFileName() { + return this.fileName; + } + + /** + * Get the name of the home folder of the file. + * @return The name of the home folder the files are in. + */ + public String getHomeFolder() { + return this.homeFolder; + } + + /** + * Get the ConfigurationFile. + * @return The ConfigurationFile of this file. + */ + public FileConfiguration getFile() { + return this.file; + } + + /** + * Check if the file actually exists in the file system. + * @return True if it does and false if it doesn't. + */ + public boolean exists() { + return this.file != null; + } + + /** + * Save the custom file. + */ + public void saveFile() { + if (this.file != null) { + try { + this.file.save(new File(this.plugin.getDataFolder(), this.homeFolder + "/" + this.fileName)); + + if (this.plugin.isLogging()) plugin.getLogger().info("Successfully saved the " + this.fileName + "."); + } catch (Exception exception) { + this.plugin.getLogger().log(Level.WARNING, "Could not save " + this.fileName + "!", exception); + } + } else { + if (this.plugin.isLogging()) this.plugin.getLogger().warning("There was a null custom file that could not be found!"); + } + } + + /** + * Overrides the loaded state file and loads the filesystems file. + */ + public void reloadFile() { + if (this.file != null) { + try { + this.file = YamlConfiguration.loadConfiguration(new File(this.plugin.getDataFolder(), "/" + this.homeFolder + "/" + this.fileName)); + + if (this.plugin.isLogging()) this.plugin.getLogger().info("Successfully reloaded the " + this.fileName + "."); + } catch (Exception exception) { + this.plugin.getLogger().log(Level.SEVERE, "Could not reload the " + this.fileName + "!", exception); + } + } else { + if (this.plugin.isLogging()) this.plugin.getLogger().warning("There was a null custom file that was not found!"); + } + } + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/Category.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/Category.java similarity index 53% rename from paper/src/main/java/com/badbones69/crazyauctions/api/Category.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/Category.java index 11e46ee..f5fe1c7 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/Category.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/Category.java @@ -1,7 +1,6 @@ -package com.badbones69.crazyauctions.api; +package com.badbones69.crazyauctions.paper.api.enums; import org.bukkit.Material; - import java.util.ArrayList; public enum Category { @@ -41,17 +40,10 @@ public enum Category { private static ArrayList getArmor() { ArrayList ma = new ArrayList<>(); - if (Version.isNewer(Version.v1_12_R1)) { - ma.add(Material.matchMaterial("GOLDEN_HELMET")); - ma.add(Material.matchMaterial("GOLDEN_CHESTPLATE")); - ma.add(Material.matchMaterial("GOLDEN_LEGGINGS")); - ma.add(Material.matchMaterial("GOLDEN_BOOTS")); - } else { - ma.add(Material.matchMaterial("GOLD_HELMET")); - ma.add(Material.matchMaterial("GOLD_CHESTPLATE")); - ma.add(Material.matchMaterial("GOLD_LEGGINGS")); - ma.add(Material.matchMaterial("GOLD_BOOTS")); - } + ma.add(Material.GOLDEN_HELMET); + ma.add(Material.GOLDEN_CHESTPLATE); + ma.add(Material.GOLDEN_LEGGINGS); + ma.add(Material.GOLDEN_BOOTS); ma.add(Material.DIAMOND_HELMET); ma.add(Material.DIAMOND_CHESTPLATE); ma.add(Material.DIAMOND_LEGGINGS); @@ -68,42 +60,27 @@ public enum Category { ma.add(Material.DIAMOND_CHESTPLATE); ma.add(Material.DIAMOND_LEGGINGS); ma.add(Material.DIAMOND_BOOTS); - if (Version.isNewer(Version.v1_15_R1)) { - ma.add(Material.NETHERITE_HELMET); - ma.add(Material.NETHERITE_CHESTPLATE); - ma.add(Material.NETHERITE_LEGGINGS); - ma.add(Material.NETHERITE_BOOTS); - } + ma.add(Material.NETHERITE_HELMET); + ma.add(Material.NETHERITE_CHESTPLATE); + ma.add(Material.NETHERITE_LEGGINGS); + ma.add(Material.NETHERITE_BOOTS); + return ma; } private static ArrayList getTools() { ArrayList ma = new ArrayList<>(); - if (Version.isNewer(Version.v1_12_R1)) { - ma.add(Material.matchMaterial("WOODEN_PICKAXE")); - ma.add(Material.matchMaterial("WOODEN_AXE")); - ma.add(Material.matchMaterial("WOODEN_SHOVEL")); - ma.add(Material.matchMaterial("WOODEN_HOE")); - ma.add(Material.matchMaterial("GOLDEN_PICKAXE")); - ma.add(Material.matchMaterial("GOLDEN_AXE")); - ma.add(Material.matchMaterial("GOLDEN_SHOVEL")); - ma.add(Material.matchMaterial("GOLDEN_HOE")); - ma.add(Material.matchMaterial("STONE_SHOVEL")); - ma.add(Material.matchMaterial("IRON_SHOVEL")); - ma.add(Material.matchMaterial("DIAMOND_SHOVEL")); - } else { - ma.add(Material.matchMaterial("WOOD_PICKAXE")); - ma.add(Material.matchMaterial("WOOD_AXE")); - ma.add(Material.matchMaterial("WOOD_SPADE")); - ma.add(Material.matchMaterial("WOOD_HOE")); - ma.add(Material.matchMaterial("GOLD_PICKAXE")); - ma.add(Material.matchMaterial("GOLD_AXE")); - ma.add(Material.matchMaterial("GOLD_SPADE")); - ma.add(Material.matchMaterial("GOLD_HOE")); - ma.add(Material.matchMaterial("STONE_SPADE")); - ma.add(Material.matchMaterial("IRON_SPADE")); - ma.add(Material.matchMaterial("DIAMOND_SPADE")); - } + ma.add(Material.WOODEN_PICKAXE); + ma.add(Material.WOODEN_AXE); + ma.add(Material.WOODEN_SHOVEL); + ma.add(Material.WOODEN_HOE); + ma.add(Material.GOLDEN_PICKAXE); + ma.add(Material.GOLDEN_AXE); + ma.add(Material.GOLDEN_SHOVEL); + ma.add(Material.GOLDEN_HOE); + ma.add(Material.STONE_SHOVEL); + ma.add(Material.IRON_SHOVEL); + ma.add(Material.DIAMOND_SHOVEL); ma.add(Material.STONE_PICKAXE); ma.add(Material.IRON_PICKAXE); ma.add(Material.DIAMOND_PICKAXE); @@ -113,28 +90,19 @@ public enum Category { ma.add(Material.STONE_HOE); ma.add(Material.IRON_HOE); ma.add(Material.DIAMOND_HOE); - if (Version.isNewer(Version.v1_15_R1)) { - ma.add(Material.NETHERITE_PICKAXE); - ma.add(Material.NETHERITE_AXE); - ma.add(Material.NETHERITE_HOE); - ma.add(Material.NETHERITE_SHOVEL); - } + ma.add(Material.NETHERITE_PICKAXE); + ma.add(Material.NETHERITE_AXE); + ma.add(Material.NETHERITE_HOE); + ma.add(Material.NETHERITE_SHOVEL); return ma; } private static ArrayList getWeapons() { ArrayList ma = new ArrayList<>(); - if (Version.isNewer(Version.v1_12_R1)) { - ma.add(Material.matchMaterial("WOODEN_SWORD")); - ma.add(Material.matchMaterial("WOODEN_AXE")); - ma.add(Material.matchMaterial("GOLDEN_SWORD")); - ma.add(Material.matchMaterial("GOLDEN_AXE")); - } else { - ma.add(Material.matchMaterial("WOOD_SWORD")); - ma.add(Material.matchMaterial("WOOD_AXE")); - ma.add(Material.matchMaterial("GOLD_SWORD")); - ma.add(Material.matchMaterial("GOLD_AXE")); - } + ma.add(Material.GOLDEN_PICKAXE); + ma.add(Material.GOLDEN_AXE); + ma.add(Material.GOLDEN_SHOVEL); + ma.add(Material.GOLDEN_HOE); ma.add(Material.STONE_SWORD); ma.add(Material.IRON_SWORD); ma.add(Material.DIAMOND_SWORD); @@ -142,10 +110,8 @@ public enum Category { ma.add(Material.IRON_AXE); ma.add(Material.DIAMOND_AXE); ma.add(Material.BOW); - if (Version.isNewer(Version.v1_15_R1)) { - ma.add(Material.NETHERITE_SWORD); - ma.add(Material.NETHERITE_AXE); - } + ma.add(Material.NETHERITE_SWORD); + ma.add(Material.NETHERITE_AXE); return ma; } @@ -162,12 +128,8 @@ public enum Category { private static ArrayList getPotions() { ArrayList ma = new ArrayList<>(); ma.add(Material.POTION); - if (Material.matchMaterial("SPLASH_POTION") != null) { - ma.add(Material.matchMaterial("SPLASH_POTION")); - } - if (Material.matchMaterial("LINGERING_POTION") != null) { - ma.add(Material.matchMaterial("LINGERING_POTION")); - } + ma.add(Material.SPLASH_POTION); + ma.add(Material.LINGERING_POTION); return ma; } @@ -201,5 +163,4 @@ public enum Category { public ArrayList getItems() { return items; } - } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/Messages.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/Messages.java similarity index 95% rename from paper/src/main/java/com/badbones69/crazyauctions/api/Messages.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/Messages.java index 23be245..f1648f1 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/Messages.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/Messages.java @@ -1,9 +1,8 @@ -package com.badbones69.crazyauctions.api; +package com.badbones69.crazyauctions.paper.api.enums; -import com.badbones69.crazyauctions.Methods; -import com.badbones69.crazyauctions.api.FileManager.Files; +import com.badbones69.crazyauctions.paper.Methods; +import com.badbones69.crazyauctions.paper.api.FileManager.Files; import org.bukkit.configuration.file.FileConfiguration; - import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -16,12 +15,12 @@ public enum Messages { INVENTORY_FULL("Inventory-Full", "&cYour inventory is too full. Please open up some space to buy that."), NO_PERMISSION("No-Permission", "&cYou do not have permission to use that command!"), NOT_ONLINE("Not-Online", "&cThat player is not online at this time."), - DOSENT_HAVE_ITEM_IN_HAND("Doesnt-Have-Item-In-Hand", "&cYou must have an item in your hand."), + DOESNT_HAVE_ITEM_IN_HAND("Doesnt-Have-Item-In-Hand", "&cYou must have an item in your hand."), NOT_A_NUMBER("Not-A-Number", "&c%arg% is not a number."), GOT_ITEM_BACK("Got-Item-Back", "&7Your item has been returned."), CANCELLED_ITEM("Cancelled-Item", "&7You have cancelled an item on the auction list, return your items with /ah expired."), ITEM_HAS_EXPIRED("Item-Has-Expired", "&7An item you have in the Crazy Auctions has just expired."), - ADMIN_FORCE_CENCELLED("Admin-Force-Cancelled", "&7You have just force cancelled a sale."), + ADMIN_FORCE_CANCELLED("Admin-Force-Cancelled", "&7You have just force cancelled a sale."), ADMIN_FORCE_CANCELLED_TO_PLAYER("Admin-Force-Cancelled-To-Player", "&cOne of your items was just force cancelled by an Admin."), ITEM_DOESNT_EXIST("Item-Doesnt-Exist", "&cThat item isnt in the crazy auctions any more."), MAX_ITEMS("Max-Items", "&cYou cant list any more items to the Crazy Auctions."), @@ -42,7 +41,6 @@ public enum Messages { BID_MESSAGE("Bid-Msg", "&7You have just bid &a$%Bid% &7on that item."), SELLING_DISABLED("Selling-Disabled", "&cThe selling option is disabled."), BIDDING_DISABLED("Bidding-Disabled", "&cThe bidding option is disabled."), - CRAZYAUCTIONS_HELP("CrazyAuctions-Help", "&c/ah help"), CRAZYAUCTIONS_VIEW("CrazyAuctions-View", "&c/ah view "), CRAZYAUCTIONS_SELL_BID("CrazyAuctions-Sell-Bid", "&c/ah sell/bid [amount of items]"), BOOK_NOT_ALLOWED("Book-Not-Allowed", "&cThat book is not able to be sold in this auction house!"), @@ -54,8 +52,7 @@ public enum Messages { "&9/Ah Expired/Collect - &eView and manage your cancelled and expired items.", "&9/Ah Listed - &eView and manage the items you are selling.", "&9/Ah Help - &eView this help menu.")); - - private static final FileManager fileManager = FileManager.getInstance(); + private final String path; private String defaultMessage; private List defaultListMessage; diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/Reaons.java similarity index 69% rename from paper/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/Reaons.java index 206adf1..7a5a3bb 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/Reaons.java @@ -1,6 +1,6 @@ -package com.badbones69.crazyauctions.api.enums; +package com.badbones69.crazyauctions.paper.api.enums; -public enum CancelledReason { +public enum Reaons { /** * Cancelled by an administrator. diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/ShopType.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/ShopType.java similarity index 92% rename from paper/src/main/java/com/badbones69/crazyauctions/api/ShopType.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/ShopType.java index 3c3e4ce..d2a5478 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/ShopType.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/enums/ShopType.java @@ -1,4 +1,4 @@ -package com.badbones69.crazyauctions.api; +package com.badbones69.crazyauctions.paper.api.enums; public enum ShopType { diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionBuyEvent.java similarity index 87% rename from paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionBuyEvent.java index ed32bfa..c5df21d 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionBuyEvent.java @@ -1,4 +1,4 @@ -package com.badbones69.crazyauctions.api.events; +package com.badbones69.crazyauctions.paper.api.events; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -15,9 +15,10 @@ import org.bukkit.inventory.ItemStack; public class AuctionBuyEvent extends Event { private static final HandlerList handlers = new HandlerList(); - private Player player; - private long price; - private ItemStack item; + + private final Player player; + private final long price; + private final ItemStack item; /** * diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionCancelledEvent.java similarity index 83% rename from paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionCancelledEvent.java index fb013e2..ffe1027 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionCancelledEvent.java @@ -1,6 +1,6 @@ -package com.badbones69.crazyauctions.api.events; +package com.badbones69.crazyauctions.paper.api.events; -import com.badbones69.crazyauctions.api.enums.CancelledReason; +import com.badbones69.crazyauctions.paper.api.enums.Reaons; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -17,18 +17,20 @@ import org.bukkit.inventory.ItemStack; public class AuctionCancelledEvent extends Event { private static final HandlerList handlers = new HandlerList(); + + private final boolean isOnline; + private final ItemStack item; + private final Reaons reason; + private OfflinePlayer offlinePlayer; private Player onlinePlayer; - private boolean isOnline; - private ItemStack item; - private CancelledReason reason; /** * * @param offlinePlayer The player whose item is cancelled. * @param item The item that is cancelled. */ - public AuctionCancelledEvent(OfflinePlayer offlinePlayer, ItemStack item, CancelledReason reason) { + public AuctionCancelledEvent(OfflinePlayer offlinePlayer, ItemStack item, Reaons reason) { this.offlinePlayer = offlinePlayer; this.item = item; this.isOnline = false; @@ -40,7 +42,7 @@ public class AuctionCancelledEvent extends Event { * @param onlinePlayer The player whose item is cancelled. * @param item The item that is cancelled. */ - public AuctionCancelledEvent(Player onlinePlayer, ItemStack item, CancelledReason reason) { + public AuctionCancelledEvent(Player onlinePlayer, ItemStack item, Reaons reason) { this.onlinePlayer = onlinePlayer; this.item = item; this.isOnline = true; @@ -71,7 +73,7 @@ public class AuctionCancelledEvent extends Event { return item; } - public CancelledReason getReason() { + public Reaons getReason() { return reason; } diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionExpireEvent.java similarity index 92% rename from paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionExpireEvent.java index 9a99ed5..44b82fd 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionExpireEvent.java @@ -1,4 +1,4 @@ -package com.badbones69.crazyauctions.api.events; +package com.badbones69.crazyauctions.paper.api.events; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -16,10 +16,12 @@ import org.bukkit.inventory.ItemStack; public class AuctionExpireEvent extends Event { private static final HandlerList handlers = new HandlerList(); + + private final boolean isOnline; + private final ItemStack item; + private OfflinePlayer offlinePlayer; private Player onlinePlayer; - private boolean isOnline; - private ItemStack item; /** * diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionListEvent.java similarity index 83% rename from paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionListEvent.java index 743ea14..4d95dd0 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionListEvent.java @@ -1,6 +1,6 @@ -package com.badbones69.crazyauctions.api.events; +package com.badbones69.crazyauctions.paper.api.events; -import com.badbones69.crazyauctions.api.ShopType; +import com.badbones69.crazyauctions.paper.api.enums.ShopType; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -16,10 +16,10 @@ import org.bukkit.inventory.ItemStack; public class AuctionListEvent extends Event { private static final HandlerList handlers = new HandlerList(); - private Player player; - private long price; - private ShopType shop; - private ItemStack item; + private final Player player; + private final long price; + private final ShopType shop; + private final ItemStack item; /** * diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionNewBidEvent.java similarity index 87% rename from paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionNewBidEvent.java index 0b391f1..3021b15 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionNewBidEvent.java @@ -1,4 +1,4 @@ -package com.badbones69.crazyauctions.api.events; +package com.badbones69.crazyauctions.paper.api.events; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -12,9 +12,9 @@ import org.bukkit.inventory.ItemStack; public class AuctionNewBidEvent extends Event { private static final HandlerList handlers = new HandlerList(); - private Player player; - private long bid; - private ItemStack item; + private final Player player; + private final long bid; + private final ItemStack item; /** * diff --git a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionWinBidEvent.java similarity index 87% rename from paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionWinBidEvent.java index b91419a..bfa7aec 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/events/AuctionWinBidEvent.java @@ -1,4 +1,4 @@ -package com.badbones69.crazyauctions.api.events; +package com.badbones69.crazyauctions.paper.api.events; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -15,9 +15,9 @@ import org.bukkit.inventory.ItemStack; public class AuctionWinBidEvent extends Event { private static final HandlerList handlers = new HandlerList(); - private Player player; - private long bid; - private ItemStack item; + private final Player player; + private final long bid; + private final ItemStack item; /** * diff --git a/paper/src/main/java/com/badbones69/crazyauctions/paper/api/support/PluginSupport.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/support/PluginSupport.java new file mode 100644 index 0000000..0224edd --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/support/PluginSupport.java @@ -0,0 +1,32 @@ +package com.badbones69.crazyauctions.paper.api.support; + +import com.badbones69.crazyauctions.paper.CrazyAuctions; +import org.jetbrains.annotations.NotNull; + +public enum PluginSupport { + + DECENT_HOLOGRAMS("DecentHolograms"), + HOLOGRAPHIC_DISPLAYS("HolographicDisplays"), + VAULT("Vault"), + CMI("CMI"), + PLACEHOLDERAPI("PlaceholderAPI"), + ORAXEN("Oraxen"), + ITEMS_ADDER("ItemsAdder"); + + private final String name; + + @NotNull + private final CrazyAuctions plugin = CrazyAuctions.get(); + + PluginSupport(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public boolean isPluginEnabled() { + return this.plugin.getServer().getPluginManager().isPluginEnabled(this.name); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/paper/api/support/metrics/MetricsWrapper.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/support/metrics/MetricsWrapper.java new file mode 100644 index 0000000..ff5cfab --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/api/support/metrics/MetricsWrapper.java @@ -0,0 +1,36 @@ +package com.badbones69.crazyauctions.paper.api.support.metrics; + +import com.badbones69.crazyauctions.paper.CrazyAuctions; +import org.bstats.bukkit.Metrics; +import org.jetbrains.annotations.NotNull; + +public class MetricsWrapper { + + @NotNull + private final CrazyAuctions plugin = CrazyAuctions.get(); + + private Metrics metrics; + + public void start() { + if (this.metrics != null) { + if (this.plugin.isLogging()) this.plugin.getLogger().warning("Metrics is already enabled."); + return; + } + + this.metrics = new Metrics(this.plugin, 4624); + + if (this.plugin.isLogging()) this.plugin.getLogger().fine("Metrics has been enabled."); + } + + public void stop() { + if (this.metrics == null) { + if (this.plugin.isLogging()) this.plugin.getLogger().warning("Metrics isn't enabled so we do nothing."); + return; + } + + this.metrics.shutdown(); + this.metrics = null; + + if (this.plugin.isLogging()) this.plugin.getLogger().fine("Metrics has been turned off."); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/paper/commands/AuctionCommand.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/commands/AuctionCommand.java new file mode 100644 index 0000000..e9385be --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/commands/AuctionCommand.java @@ -0,0 +1,524 @@ +package com.badbones69.crazyauctions.paper.commands; + +import com.badbones69.crazyauctions.paper.CrazyAuctions; +import com.badbones69.crazyauctions.paper.Methods; +import com.badbones69.crazyauctions.paper.api.CrazyManager; +import com.badbones69.crazyauctions.paper.api.FileManager; +import com.badbones69.crazyauctions.paper.api.FileManager.Files; +import com.badbones69.crazyauctions.paper.api.enums.Category; +import com.badbones69.crazyauctions.paper.api.enums.Messages; +import com.badbones69.crazyauctions.paper.api.enums.ShopType; +import com.badbones69.crazyauctions.paper.api.events.AuctionListEvent; +import com.badbones69.crazyauctions.paper.controllers.GuiListener; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; +import org.bukkit.permissions.PermissionAttachmentInfo; +import org.jetbrains.annotations.NotNull; +import org.yaml.snakeyaml.error.YAMLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Random; +import java.util.logging.Level; + +public class AuctionCommand implements CommandExecutor { + + private final CrazyAuctions plugin = CrazyAuctions.get(); + + private final CrazyManager crazyManager = this.plugin.getCrazyManager(); + + private final FileManager fileManager = this.plugin.getFileManager(); + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, String commandLabel, String[] args) { + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); + + if (args.length == 0) { + if (!(sender instanceof Player player)) { + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); + return true; + } + + if (config.contains("Settings.Category-Page-Opens-First")) { + if (config.getBoolean("Settings.Category-Page-Opens-First")) { + GuiListener.openCategories(player, ShopType.SELL); + return true; + } + } + + if (crazyManager.isSellingEnabled()) { + GuiListener.openShop(player, ShopType.SELL, Category.NONE, 1); + } else if (crazyManager.isBiddingEnabled()) { + GuiListener.openShop(player, ShopType.BID, Category.NONE, 1); + } else { + player.sendMessage(Methods.getPrefix() + Methods.color("&cThe bidding and selling options are both disabled. Please contact the admin about this.")); + } + + return true; + } else { + switch (args[0].toLowerCase()) { + case "help" -> { + if (!Methods.hasPermission(sender, "access")) { + sender.sendMessage(Messages.NO_PERMISSION.getMessage()); + return true; + } + + sender.sendMessage(Messages.HELP.getMessage()); + return true; + } + + case "test" -> { + if (!Methods.hasPermission(sender, "test")) { + sender.sendMessage(Messages.NO_PERMISSION.getMessage()); + return true; + } + + int times = 1; + + if (args.length >= 2) { + if (!Methods.isInt(args[1])) { + HashMap placeholders = new HashMap<>(); + placeholders.put("%Arg%", args[1]); + placeholders.put("%arg%", args[1]); + sender.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); + return true; + } + + times = Integer.parseInt(args[1]); + } + + int price = 10; + int amount = 1; + ItemStack item = Methods.getItemInHand((Player) sender); + + if (item != null && item.getType() != Material.AIR) { + // For testing as another player + String seller = "Test-Account"; + + for (int it = 1; it <= times; it++) { + int num = 1; + + Random random = new Random(); + + for (; data.contains("Items." + num); num++) ; + + data.set("Items." + num + ".Price", price); + data.set("Items." + num + ".Seller", seller); + + if (args[0].equalsIgnoreCase("bid")) { + data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Bid-Time"))); + } else { + data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Sell-Time"))); + } + + data.set("Items." + num + ".Full-Time", Methods.convertToMill(config.getString("Settings.Full-Expire-Time"))); + int id = random.nextInt(Integer.MAX_VALUE); + + for (String i : data.getConfigurationSection("Items").getKeys(false)) + if (data.getInt("Items." + i + ".StoreID") == id) + id = random.nextInt(Integer.MAX_VALUE); + + data.set("Items." + num + ".StoreID", id); + data.set("Items." + num + ".Biddable", args[0].equalsIgnoreCase("Bid")); + data.set("Items." + num + ".TopBidder", "None"); + + ItemStack stack = item.clone(); + stack.setAmount(amount); + + data.set("Items." + num + ".Item", stack); + } + + Files.DATA.saveFile(); + + HashMap placeholders = new HashMap<>(); + placeholders.put("%Price%", String.valueOf(price)); + placeholders.put("%price%", String.valueOf(price)); + + sender.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(placeholders)); + + if (item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) { + Methods.setItemInHand((Player) sender, new ItemStack(Material.AIR)); + } else { + item.setAmount(item.getAmount() - amount); + } + } else { + sender.sendMessage(Messages.DOESNT_HAVE_ITEM_IN_HAND.getMessage()); + } + } + + case "reload" -> { + if (!Methods.hasPermission(sender, "admin")) { + sender.sendMessage(Messages.NO_PERMISSION.getMessage()); + return true; + } + + this.fileManager.setup(); + this.crazyManager.load(); + + sender.sendMessage(Messages.RELOAD.getMessage()); + return true; + } + + case "view" -> { + if (!Methods.hasPermission(sender, "view")) { + sender.sendMessage(Messages.NO_PERMISSION.getMessage()); + return true; + } + + if (!(sender instanceof Player player)) { + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); + return true; + } + + if (args.length >= 2) { + GuiListener.openViewer(player, args[1], 1); + return true; + } + + sender.sendMessage(Messages.CRAZYAUCTIONS_VIEW.getMessage()); + return true; + } + + case "expired", "collect" -> { + if (!Methods.hasPermission(sender, "access")) { + sender.sendMessage(Messages.NO_PERMISSION.getMessage()); + return true; + } + + if (!(sender instanceof Player player)) { + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); + return true; + } + + GuiListener.openPlayersExpiredList(player, 1); + return true; + } + + case "listed" -> { + if (!Methods.hasPermission(sender, "access")) return true; + + if (!(sender instanceof Player player)) { + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); + return true; + } + + GuiListener.openPlayersCurrentList(player, 1); + return true; + } + + case "sell", "bid" -> { + if (!(sender instanceof Player player)) { + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); + return true; + } + + if (args.length >= 2) { + if (args[0].equalsIgnoreCase("sell")) { + if (!crazyManager.isSellingEnabled()) { + player.sendMessage(Messages.SELLING_DISABLED.getMessage()); + return true; + } + + if (!Methods.hasPermission(player, "sell")) return true; + } + + if (args[0].equalsIgnoreCase("bid")) { + if (!crazyManager.isBiddingEnabled()) { + player.sendMessage(Messages.BIDDING_DISABLED.getMessage()); + return true; + } + + if (!Methods.hasPermission(player, "bid")) return true; + } + + ItemStack item = Methods.getItemInHand(player); + int amount = item.getAmount(); + + if (args.length >= 3) { + if (!Methods.isInt(args[2])) { + HashMap placeholders = new HashMap<>(); + placeholders.put("%Arg%", args[2]); + placeholders.put("%arg%", args[2]); + player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); + return true; + } + + amount = Integer.parseInt(args[2]); + if (amount <= 0) amount = 1; + if (amount > item.getAmount()) amount = item.getAmount(); + } + + if (!Methods.isLong(args[1])) { + HashMap placeholders = new HashMap<>(); + placeholders.put("%Arg%", args[1]); + placeholders.put("%arg%", args[1]); + player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); + return true; + } + + if (Methods.getItemInHand(player).getType() == Material.AIR) { + player.sendMessage(Messages.DOESNT_HAVE_ITEM_IN_HAND.getMessage()); + return false; + } + + long price = Long.parseLong(args[1]); + + if (args[0].equalsIgnoreCase("bid")) { + if (price < config.getLong("Settings.Minimum-Bid-Price")) { + player.sendMessage(Messages.BID_PRICE_TO_LOW.getMessage()); + return true; + } + + if (price > config.getLong("Settings.Max-Beginning-Bid-Price")) { + player.sendMessage(Messages.BID_PRICE_TO_HIGH.getMessage()); + return true; + } + } else { + if (price < config.getLong("Settings.Minimum-Sell-Price")) { + player.sendMessage(Messages.SELL_PRICE_TO_LOW.getMessage()); + return true; + } + if (price > config.getLong("Settings.Max-Beginning-Sell-Price")) { + player.sendMessage(Messages.SELL_PRICE_TO_HIGH.getMessage()); + return true; + } + } + + if (!player.hasPermission("crazyauctions.bypass")) { + int SellLimit = 0; + int BidLimit = 0; + + for (PermissionAttachmentInfo permission : player.getEffectivePermissions()) { + String perm = permission.getPermission(); + + if (perm.startsWith("crazyauctions.sell.")) { + perm = perm.replace("crazyauctions.sell.", ""); + + if (Methods.isInt(perm)) { + if (Integer.parseInt(perm) > SellLimit) { + SellLimit = Integer.parseInt(perm); + } + } + } + + if (perm.startsWith("crazyauctions.bid.")) { + perm = perm.replace("crazyauctions.bid.", ""); + if (Methods.isInt(perm)) { + if (Integer.parseInt(perm) > BidLimit) { + BidLimit = Integer.parseInt(perm); + } + } + } + } + + for (int i = 1; i < 100; i++) { + if (SellLimit < i) { + if (player.hasPermission("crazyauctions.sell." + i)) { + SellLimit = i; + } + } + + if (BidLimit < i) { + if (player.hasPermission("crazyauctions.bid." + i)) { + BidLimit = i; + } + } + } + + if (args[0].equalsIgnoreCase("sell")) { + if (crazyManager.getItems(player, ShopType.SELL).size() >= SellLimit) { + player.sendMessage(Messages.MAX_ITEMS.getMessage()); + return true; + } + } + + if (args[0].equalsIgnoreCase("bid")) { + if (crazyManager.getItems(player, ShopType.BID).size() >= BidLimit) { + player.sendMessage(Messages.MAX_ITEMS.getMessage()); + return true; + } + } + } + + 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.getBoolean("Settings.Allow-Damaged-Items")) { + for (Material i : getDamageableItems()) { + if (item.getType() == i) { + if (item.getDurability() > 0) { + player.sendMessage(Messages.ITEM_DAMAGED.getMessage()); + return true; + } + } + } + } + + if (!allowBook(item)) { + player.sendMessage(Messages.BOOK_NOT_ALLOWED.getMessage()); + return true; + } + + String seller = player.getName(); + int num = 1; + + Random random = new Random(); + + for (; data.contains("Items." + num); num++) ; + data.set("Items." + num + ".Price", price); + data.set("Items." + num + ".Seller", seller); + + if (args[0].equalsIgnoreCase("bid")) { + data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Bid-Time"))); + } else { + data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Sell-Time"))); + } + + data.set("Items." + num + ".Full-Time", Methods.convertToMill(config.getString("Settings.Full-Expire-Time"))); + int id = random.nextInt(999999); + // Runs 3x to check for same ID. + for (String i : data.getConfigurationSection("Items").getKeys(false)) + if (data.getInt("Items." + i + ".StoreID") == id) id = random.nextInt(Integer.MAX_VALUE); + for (String i : data.getConfigurationSection("Items").getKeys(false)) + if (data.getInt("Items." + i + ".StoreID") == id) id = random.nextInt(Integer.MAX_VALUE); + for (String i : data.getConfigurationSection("Items").getKeys(false)) + if (data.getInt("Items." + i + ".StoreID") == id) id = random.nextInt(Integer.MAX_VALUE); + data.set("Items." + num + ".StoreID", id); + ShopType type = ShopType.SELL; + + if (args[0].equalsIgnoreCase("bid")) { + data.set("Items." + num + ".Biddable", true); + type = ShopType.BID; + } else { + data.set("Items." + num + ".Biddable", false); + } + + data.set("Items." + num + ".TopBidder", "None"); + + ItemStack stack = item.clone(); + stack.setAmount(amount); + + data.set("Items." + num + ".Item", stack); + + Files.DATA.saveFile(); + + this.plugin.getServer().getPluginManager().callEvent(new AuctionListEvent(player, type, stack, price)); + + HashMap placeholders = new HashMap<>(); + + placeholders.put("%Price%", String.valueOf(price)); + placeholders.put("%price%", String.valueOf(price)); + player.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(placeholders)); + + if (item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) { + Methods.setItemInHand(player, new ItemStack(Material.AIR)); + } else { + item.setAmount(item.getAmount() - amount); + } + + return false; + } + + sender.sendMessage(Messages.CRAZYAUCTIONS_SELL_BID.getMessage()); + } + + default -> { + sender.sendMessage(Methods.getPrefix("&cPlease do /crazyauctions help for more information.")); + return true; + } + } + + return true; + } + } + + private ArrayList getDamageableItems() { + ArrayList ma = new ArrayList<>(); + ma.add(Material.GOLDEN_HELMET); + ma.add(Material.GOLDEN_CHESTPLATE); + ma.add(Material.GOLDEN_LEGGINGS); + ma.add(Material.GOLDEN_BOOTS); + ma.add(Material.GOLDEN_HOE); + ma.add(Material.WOODEN_SWORD); + ma.add(Material.WOODEN_PICKAXE); + ma.add(Material.WOODEN_AXE); + ma.add(Material.WOODEN_SHOVEL); + ma.add(Material.WOODEN_HOE); + ma.add(Material.STONE_SHOVEL); + ma.add(Material.IRON_SHOVEL); + ma.add(Material.DIAMOND_SHOVEL); + ma.add(Material.CROSSBOW); + ma.add(Material.TRIDENT); + ma.add(Material.TURTLE_HELMET); + ma.add(Material.DIAMOND_HELMET); + ma.add(Material.DIAMOND_CHESTPLATE); + ma.add(Material.DIAMOND_LEGGINGS); + ma.add(Material.DIAMOND_BOOTS); + ma.add(Material.CHAINMAIL_HELMET); + ma.add(Material.CHAINMAIL_CHESTPLATE); + ma.add(Material.CHAINMAIL_LEGGINGS); + ma.add(Material.CHAINMAIL_BOOTS); + ma.add(Material.IRON_HELMET); + ma.add(Material.IRON_CHESTPLATE); + ma.add(Material.IRON_LEGGINGS); + ma.add(Material.IRON_BOOTS); + ma.add(Material.LEATHER_HELMET); + ma.add(Material.LEATHER_CHESTPLATE); + ma.add(Material.LEATHER_LEGGINGS); + ma.add(Material.LEATHER_BOOTS); + ma.add(Material.BOW); + ma.add(Material.STONE_SWORD); + ma.add(Material.IRON_SWORD); + ma.add(Material.DIAMOND_SWORD); + ma.add(Material.STONE_AXE); + ma.add(Material.IRON_AXE); + ma.add(Material.DIAMOND_AXE); + ma.add(Material.STONE_PICKAXE); + ma.add(Material.IRON_PICKAXE); + ma.add(Material.DIAMOND_PICKAXE); + ma.add(Material.STONE_AXE); + ma.add(Material.IRON_AXE); + ma.add(Material.DIAMOND_AXE); + ma.add(Material.STONE_HOE); + ma.add(Material.IRON_HOE); + ma.add(Material.DIAMOND_HOE); + ma.add(Material.FLINT_AND_STEEL); + ma.add(Material.ANVIL); + ma.add(Material.FISHING_ROD); + + return ma; + } + + private boolean allowBook(ItemStack item) { + if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof BookMeta bookMeta) { + this.plugin.getLogger().info("Checking " + item.getType() + " for illegal unicode."); + + FileConfiguration file = Files.TEST_FILE.getFile(); + + try { + file.set("Test", item); + + Files.TEST_FILE.saveFile(); + + this.plugin.getLogger().info(item.getType() + " has passed unicode checks."); + } catch (YAMLException exception) { + this.plugin.getLogger().log(Level.SEVERE, item.getType() + " has failed unicode checks and has been denied.", exception); + return false; + } + + return bookMeta.getPages().stream().mapToInt(String :: length).sum() < 2000; + } + + return true; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/paper/commands/AuctionTab.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/commands/AuctionTab.java new file mode 100644 index 0000000..3582b84 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/commands/AuctionTab.java @@ -0,0 +1,56 @@ +package com.badbones69.crazyauctions.paper.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.util.StringUtil; +import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class AuctionTab implements TabCompleter { + + @Override + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String commandLabel, String[] args) { + List completions = new ArrayList<>(); + if (args.length == 1) { // /voucher + if (hasPermission(sender, "access")) { + completions.add("help"); + completions.add("collect"); + completions.add("expired"); + completions.add("listed"); + } + if (hasPermission(sender, "test")) completions.add("test"); + if (hasPermission(sender, "admin")) completions.add("reload"); + if (hasPermission(sender, "view")) completions.add("view"); + if (hasPermission(sender, "sell")) completions.add("sell"); + if (hasPermission(sender, "bid")) completions.add("bid"); + return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>()); + } else if (args.length == 2) { // /crazyauctions arg0 + return StringUtil.copyPartialMatches(args[1], completions, new ArrayList<>()); + } else if (args.length == 3) { // /crazyauctions arg0 arg1 + switch (args[0].toLowerCase()) { + case "bid", "sell" -> { + if (hasPermission(sender, "bid") || hasPermission(sender, "sell")) completions.addAll(Arrays.asList("50", "100", "250", "500", "1000", "2500", "5000", "10000")); + } + } + + return StringUtil.copyPartialMatches(args[2], completions, new ArrayList<>()); + } else if (args.length == 4) { // /crazyauctions arg0 arg1 arg2 + switch (args[0].toLowerCase()) { + case "bid", "sell" -> { + if (hasPermission(sender, "bid") || hasPermission(sender, "sell")) completions.addAll(Arrays.asList("50", "100", "250", "500", "1000", "2500", "5000", "10000")); + } + } + + return StringUtil.copyPartialMatches(args[3], completions, new ArrayList<>()); + } + + return new ArrayList<>(); + } + + private boolean hasPermission(CommandSender sender, String node) { + return sender.hasPermission("crazyauctions." + node) || sender.hasPermission("crazyauctions.admin.*"); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/controllers/GuiListener.java similarity index 86% rename from paper/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/controllers/GuiListener.java index bfd2d9c..305bc4c 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/controllers/GuiListener.java @@ -1,15 +1,19 @@ -package com.badbones69.crazyauctions.controllers; +package com.badbones69.crazyauctions.paper.controllers; -import com.badbones69.crazyauctions.Methods; -import com.badbones69.crazyauctions.api.*; -import com.badbones69.crazyauctions.api.FileManager.Files; -import com.badbones69.crazyauctions.api.enums.CancelledReason; -import com.badbones69.crazyauctions.api.events.AuctionBuyEvent; -import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent; -import com.badbones69.crazyauctions.api.events.AuctionNewBidEvent; -import com.badbones69.crazyauctions.currency.CurrencyManager; +import com.badbones69.crazyauctions.paper.CrazyAuctions; +import com.badbones69.crazyauctions.paper.Methods; +import com.badbones69.crazyauctions.paper.api.*; +import com.badbones69.crazyauctions.paper.api.FileManager.Files; +import com.badbones69.crazyauctions.paper.api.enums.Category; +import com.badbones69.crazyauctions.paper.api.enums.Reaons; +import com.badbones69.crazyauctions.paper.api.enums.Messages; +import com.badbones69.crazyauctions.paper.api.enums.ShopType; +import com.badbones69.crazyauctions.paper.api.events.AuctionBuyEvent; +import com.badbones69.crazyauctions.paper.api.events.AuctionCancelledEvent; +import com.badbones69.crazyauctions.paper.api.events.AuctionNewBidEvent; import org.bukkit.Bukkit; import org.bukkit.Sound; +import org.bukkit.SoundCategory; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -19,24 +23,23 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; -import java.util.logging.Level; +import java.util.UUID; -public class GUI implements Listener { +public class GuiListener implements Listener { - private static HashMap bidding = new HashMap<>(); - private static HashMap biddingID = new HashMap<>(); - private static HashMap shopType = new HashMap<>(); // Shop Type - private static HashMap shopCategory = new HashMap<>(); // Category Type - private static HashMap> List = new HashMap<>(); - private static HashMap IDs = new HashMap<>(); - private static CrazyAuctions crazyAuctions = CrazyAuctions.getInstance(); - private static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions"); + private static final CrazyAuctions plugin = CrazyAuctions.get(); + private static final CrazyManager crazyManager = plugin.getCrazyManager(); + + private static HashMap bidding = new HashMap<>(); + private static HashMap biddingID = new HashMap<>(); + private static HashMap shopType = new HashMap<>(); // Shop Type + private static HashMap shopCategory = new HashMap<>(); // Category Type + private static HashMap> List = new HashMap<>(); + private static HashMap IDs = new HashMap<>(); public static void openShop(Player player, ShopType sell, Category cat, int page) { Methods.updateAuction(); @@ -44,15 +47,18 @@ public class GUI implements Listener { FileConfiguration data = Files.DATA.getFile(); List items = new ArrayList<>(); List ID = new ArrayList<>(); + if (!data.contains("Items")) { data.set("Items.Clear", null); Files.DATA.saveFile(); } + if (cat != null) { - shopCategory.put(player, cat); + shopCategory.put(player.getUniqueId(), cat); } else { - shopCategory.put(player, Category.NONE); + shopCategory.put(player.getUniqueId(), Category.NONE); } + if (data.contains("Items")) { for (String i : data.getConfigurationSection("Items").getKeys(false)) { List lore = new ArrayList<>(); @@ -79,10 +85,13 @@ public class GUI implements Listener { } } } + int maxPage = Methods.getMaxPage(items); - for (; page > maxPage; page--) ; - Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page)); + for (; page > maxPage; page--); + + Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page)); List options = new ArrayList<>(); + options.add("SellingItems"); options.add("Cancelled/ExpiredItems"); options.add("PreviousPage"); @@ -90,31 +99,40 @@ public class GUI implements Listener { options.add("NextPage"); options.add("Category1"); options.add("Category2"); + if (sell == ShopType.SELL) { - shopType.put(player, ShopType.SELL); - if (crazyAuctions.isBiddingEnabled()) { + shopType.put(player.getUniqueId(), ShopType.SELL); + + if (crazyManager.isBiddingEnabled()) { options.add("Bidding/Selling.Selling"); } + options.add("WhatIsThis.SellingShop"); } + if (sell == ShopType.BID) { - shopType.put(player, ShopType.BID); - if (crazyAuctions.isSellingEnabled()) { + shopType.put(player.getUniqueId(), ShopType.BID); + + if (crazyManager.isSellingEnabled()) { options.add("Bidding/Selling.Bidding"); } + options.add("WhatIsThis.BiddingShop"); } + for (String o : options) { if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { continue; } } + String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item"); String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); List lore = new ArrayList<>(); int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot"); - String cName = Methods.color(config.getString("Settings.GUISettings.Category-Settings." + shopCategory.get(player).getName() + ".Name")); + String cName = Methods.color(config.getString("Settings.GUISettings.Category-Settings." + shopCategory.get(player.getUniqueId()).getName() + ".Name")); + 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)); @@ -124,20 +142,24 @@ public class GUI implements Listener { inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); } } + for (ItemStack item : Methods.getPage(items, page)) { int slot = inv.firstEmpty(); inv.setItem(slot, item); } + List Id = new ArrayList<>(Methods.getPageInts(ID, page)); - List.put(player, Id); + List.put(player.getUniqueId(), Id); player.openInventory(inv); } public static void openCategories(Player player, ShopType shop) { Methods.updateAuction(); FileConfiguration config = Files.CONFIG.getFile(); - Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Categories"))); + + Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.Categories"))); List options = new ArrayList<>(); + options.add("OtherSettings.Back"); options.add("OtherSettings.WhatIsThis.Categories"); options.add("Category-Settings.Armor"); @@ -148,12 +170,14 @@ public class GUI implements Listener { options.add("Category-Settings.Blocks"); options.add("Category-Settings.Other"); options.add("Category-Settings.None"); + for (String o : options) { if (config.contains("Settings.GUISettings." + o + ".Toggle")) { if (!config.getBoolean("Settings.GUISettings." + o + ".Toggle")) { continue; } } + String id = config.getString("Settings.GUISettings." + o + ".Item"); String name = config.getString("Settings.GUISettings." + o + ".Name"); int slot = config.getInt("Settings.GUISettings." + o + ".Slot"); @@ -163,7 +187,8 @@ public class GUI implements Listener { inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); } } - shopType.put(player, shop); + + shopType.put(player.getUniqueId(), shop); player.openInventory(inv); } @@ -173,16 +198,20 @@ public class GUI implements Listener { FileConfiguration data = Files.DATA.getFile(); List items = new ArrayList<>(); List ID = new ArrayList<>(); - Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Players-Current-Items"))); + + Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.Players-Current-Items"))); + List options = new ArrayList<>(); options.add("Back"); options.add("WhatIsThis.CurrentItems"); + for (String o : options) { if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { continue; } } + 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"); @@ -192,6 +221,7 @@ public class GUI implements Listener { inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); } } + if (data.contains("Items")) { for (String i : data.getConfigurationSection("Items").getKeys(false)) { if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { @@ -204,12 +234,14 @@ public class GUI implements Listener { } } } + for (ItemStack item : Methods.getPage(items, page)) { int slot = inv.firstEmpty(); inv.setItem(slot, item); } + List Id = new ArrayList<>(Methods.getPageInts(ID, page)); - List.put(player, Id); + List.put(player.getUniqueId(), Id); player.openInventory(inv); } @@ -219,6 +251,7 @@ public class GUI implements Listener { FileConfiguration data = Files.DATA.getFile(); List items = new ArrayList<>(); List ID = new ArrayList<>(); + if (data.contains("OutOfTime/Cancelled")) { for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { if (data.getString("OutOfTime/Cancelled." + i + ".Seller") != null) { @@ -233,21 +266,26 @@ public class GUI implements Listener { } } } + int maxPage = Methods.getMaxPage(items); - for (; page > maxPage; page--) ; - Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Cancelled/Expired-Items") + " #" + page)); + for (; page > maxPage; page--); + + Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.Cancelled/Expired-Items") + " #" + page)); List options = new ArrayList<>(); + options.add("Back"); options.add("PreviousPage"); options.add("Return"); options.add("NextPage"); options.add("WhatIsThis.Cancelled/ExpiredItems"); + for (String o : options) { if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { continue; } } + 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"); @@ -257,43 +295,53 @@ public class GUI implements Listener { inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); } } + for (ItemStack item : Methods.getPage(items, page)) { int slot = inv.firstEmpty(); inv.setItem(slot, item); } + List Id = new ArrayList<>(Methods.getPageInts(ID, page)); - List.put(player, Id); + List.put(player.getUniqueId(), Id); player.openInventory(inv); } public static void openBuying(Player player, String ID) { Methods.updateAuction(); + FileConfiguration config = Files.CONFIG.getFile(); FileConfiguration data = Files.DATA.getFile(); + if (!data.contains("Items." + ID)) { - openShop(player, ShopType.SELL, shopCategory.get(player), 1); + openShop(player, ShopType.SELL, shopCategory.get(player.getUniqueId()), 1); player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } + Inventory inv = Bukkit.createInventory(null, 9, Methods.color(config.getString("Settings.Buying-Item"))); + List options = new ArrayList<>(); options.add("Confirm"); options.add("Cancel"); + for (String o : options) { String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item"); String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); ItemStack item; + 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); } + if (o.equals("Confirm")) { inv.setItem(0, item); inv.setItem(1, item); inv.setItem(2, item); inv.setItem(3, item); } + if (o.equals("Cancel")) { inv.setItem(5, item); inv.setItem(6, item); @@ -301,13 +349,15 @@ public class GUI implements Listener { inv.setItem(8, item); } } + ItemStack item = data.getItemStack("Items." + ID + ".Item"); List lore = new ArrayList<>(); for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) { 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)); - IDs.put(player, ID); + IDs.put(player.getUniqueId(), ID); player.openInventory(inv); } @@ -315,49 +365,45 @@ public class GUI implements Listener { Methods.updateAuction(); FileConfiguration config = Files.CONFIG.getFile(); FileConfiguration data = Files.DATA.getFile(); + if (!data.contains("Items." + ID)) { - openShop(player, ShopType.BID, shopCategory.get(player), 1); + openShop(player, ShopType.BID, shopCategory.get(player.getUniqueId()), 1); player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } - Inventory inv = Bukkit.createInventory(null, 27, Methods.color(config.getString("Settings.Bidding-On-Item"))); - if (!bidding.containsKey(player)) bidding.put(player, 0); - if (Version.isNewer(Version.v1_12_R1)) { - 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")); - } else { - inv.setItem(9, Methods.makeItem("160:5", 1, "&a+1")); - inv.setItem(10, Methods.makeItem("160:5", 1, "&a+10")); - inv.setItem(11, Methods.makeItem("160:5", 1, "&a+100")); - inv.setItem(12, Methods.makeItem("160:5", 1, "&a+1000")); - inv.setItem(14, Methods.makeItem("160:14", 1, "&c-1000")); - inv.setItem(15, Methods.makeItem("160:14", 1, "&c-100")); - inv.setItem(16, Methods.makeItem("160:14", 1, "&c-10")); - inv.setItem(17, Methods.makeItem("160:14", 1, "&c-1")); - } + + Inventory inv = plugin.getServer().createInventory(null, 27, Methods.color(config.getString("Settings.Bidding-On-Item"))); + if (!bidding.containsKey(player)) 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(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(4, getBiddingItem(player, ID)); + inv.setItem(4, getBiddingItem(ID)); player.openInventory(inv); } public static void openViewer(Player player, String other, int page) { Methods.updateAuction(); + FileConfiguration config = Files.CONFIG.getFile(); FileConfiguration data = Files.DATA.getFile(); List items = new ArrayList<>(); List ID = new ArrayList<>(); + if (!data.contains("Items")) { data.set("Items.Clear", null); Files.DATA.saveFile(); } + if (data.contains("Items")) { for (String i : data.getConfigurationSection("Items").getKeys(false)) { if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(other)) { @@ -378,40 +424,51 @@ public class GUI implements Listener { } } } + int maxPage = Methods.getMaxPage(items); - for (; page > maxPage; page--) ; - Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page)); + for (; page > maxPage; page--); + + Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page)); + List options = new ArrayList<>(); options.add("WhatIsThis.Viewing"); + for (String o : options) { if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { continue; } } + 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"); + 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)); } } + for (ItemStack item : Methods.getPage(items, page)) { int slot = inv.firstEmpty(); inv.setItem(slot, item); } - List.put(player, new ArrayList<>(Methods.getPageInts(ID, page))); + + List.put(player.getUniqueId(), new ArrayList<>(Methods.getPageInts(ID, page))); player.openInventory(inv); } - public static ItemStack getBiddingGlass(Player player, String ID) { + private static ItemStack getBiddingGlass(Player player, String ID) { FileConfiguration config = Files.CONFIG.getFile(); + String id = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item"); String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name"); ItemStack item; - int bid = bidding.get(player); + + int bid = bidding.get(player.getUniqueId()); + if (config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) { List lore = new ArrayList<>(); for (String l : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) { @@ -421,42 +478,35 @@ public class GUI implements Listener { } else { item = Methods.makeItem(id, 1, name); } + return item; } - public static ItemStack getBiddingItem(Player player, String ID) { + private static ItemStack getBiddingItem(String ID) { FileConfiguration config = Files.CONFIG.getFile(); FileConfiguration data = Files.DATA.getFile(); String seller = data.getString("Items." + ID + ".Seller"); String topbidder = data.getString("Items." + ID + ".TopBidder"); ItemStack item = data.getItemStack("Items." + ID + ".Item"); List lore = new ArrayList<>(); + for (String l : config.getStringList("Settings.GUISettings.Bidding")) { 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); } private static void playClick(Player player) { - if (Files.CONFIG.getFile().contains("Settings.Sounds.Toggle")) { - if (Files.CONFIG.getFile().getBoolean("Settings.Sounds.Toggle")) { - String sound = Files.CONFIG.getFile().getString("Settings.Sounds.Sound"); - try { - player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1); - } catch (Exception e) { - if (Methods.getVersion() >= 191) { - player.playSound(player.getLocation(), Sound.valueOf("UI_BUTTON_CLICK"), 1, 1); - } else { - player.playSound(player.getLocation(), Sound.valueOf("CLICK"), 1, 1); - } - Bukkit.getLogger().log(Level.WARNING, "[Crazy Auctions]>> You set the sound to " + sound + " and this is not a sound for your minecraft version. " + "Please go to the config and set a correct sound or turn the sound off in the toggle setting."); - } - } - } else { - if (Methods.getVersion() >= 191) { - player.playSound(player.getLocation(), Sound.valueOf("UI_BUTTON_CLICK"), 1, 1); - } else { - player.playSound(player.getLocation(), Sound.valueOf("CLICK"), 1, 1); + FileConfiguration config = Files.CONFIG.getFile(); + + if (config.getBoolean("Settings.Sounds.Toggle", false)) { + String sound = config.getString("Settings.Sounds.Sound"); + + try { + player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1); + } catch (Exception e) { + player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1F, 1F); } } } @@ -464,13 +514,9 @@ public class GUI implements Listener { @EventHandler public void onInvClose(InventoryCloseEvent e) { FileConfiguration config = Files.CONFIG.getFile(); - Inventory inv = e.getInventory(); Player player = (Player) e.getPlayer(); - if (inv != null) { - if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) { - bidding.remove(player); - } - } + + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) bidding.remove(player); } @EventHandler @@ -478,24 +524,28 @@ public class GUI implements Listener { FileConfiguration config = Files.CONFIG.getFile(); FileConfiguration data = Files.DATA.getFile(); Player player = (Player) e.getWhoClicked(); - final Inventory inv = e.getInventory(); + final Inventory inv = e.getClickedInventory(); + if (inv != null) { if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Categories")))) { e.setCancelled(true); int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { if (e.getCurrentItem() != null) { ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { if (item.getItemMeta().hasDisplayName()) { for (Category cat : Category.values()) { if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.Category-Settings." + cat.getName() + ".Name")))) { - openShop(player, shopType.get(player), cat, 1); + openShop(player, shopType.get(player.getUniqueId()), cat, 1); playClick(player); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { - openShop(player, shopType.get(player), shopCategory.get(player), 1); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); playClick(player); return; } @@ -505,33 +555,40 @@ public class GUI implements Listener { } } } + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) { e.setCancelled(true); int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { if (e.getCurrentItem() != null) { ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { if (item.getItemMeta().hasDisplayName()) { if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bid.Name")))) { - String ID = biddingID.get(player); - int bid = bidding.get(player); + String ID = biddingID.get(player.getUniqueId()); + int bid = bidding.get(player.getUniqueId()); String topBidder = data.getString("Items." + ID + ".TopBidder"); - if (CurrencyManager.getMoney(player) < bid) { + + if (plugin.getSupport().getMoney(player) < bid) { HashMap placeholders = new HashMap<>(); - placeholders.put("%Money_Needed%", (bid - CurrencyManager.getMoney(player)) + ""); - placeholders.put("%money_needed%", (bid - CurrencyManager.getMoney(player)) + ""); + placeholders.put("%Money_Needed%", (bid - plugin.getSupport().getMoney(player)) + ""); + placeholders.put("%money_needed%", (bid - plugin.getSupport().getMoney(player)) + ""); player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders)); return; } + if (data.getLong("Items." + ID + ".Price") > bid) { player.sendMessage(Messages.BID_MORE_MONEY.getMessage()); return; } + if (data.getLong("Items." + ID + ".Price") >= bid && !topBidder.equalsIgnoreCase("None")) { player.sendMessage(Messages.BID_MORE_MONEY.getMessage()); return; } + Bukkit.getPluginManager().callEvent(new AuctionNewBidEvent(player, data.getItemStack("Items." + ID + ".Item"), bid)); data.set("Items." + ID + ".Price", bid); data.set("Items." + ID + ".TopBidder", player.getName()); @@ -539,11 +596,12 @@ public class GUI implements Listener { placeholders.put("%Bid%", bid + ""); player.sendMessage(Messages.BID_MESSAGE.getMessage(placeholders)); Files.DATA.saveFile(); - bidding.put(player, 0); + bidding.put(player.getUniqueId(), 0); player.closeInventory(); playClick(player); return; } + HashMap priceEdits = new HashMap<>(); priceEdits.put("&a+1", 1); priceEdits.put("&a+10", 10); @@ -553,12 +611,13 @@ public class GUI implements Listener { priceEdits.put("&c-10", -10); priceEdits.put("&c-100", -100); priceEdits.put("&c-1000", -1000); + for (String price : priceEdits.keySet()) { if (item.getItemMeta().getDisplayName().equals(Methods.color(price))) { try { - bidding.put(player, (bidding.get(player) + priceEdits.get(price))); - inv.setItem(4, getBiddingItem(player, biddingID.get(player))); - inv.setItem(13, getBiddingGlass(player, biddingID.get(player))); + bidding.put(player.getUniqueId(), (bidding.get(player.getUniqueId()) + priceEdits.get(price))); + inv.setItem(4, getBiddingItem(biddingID.get(player.getUniqueId()))); + inv.setItem(13, getBiddingGlass(player, biddingID.get(player.getUniqueId()))); playClick(player); return; } catch (Exception ex) { @@ -573,83 +632,100 @@ public class GUI implements Listener { } } } + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.GUIName")))) { e.setCancelled(true); final int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { if (e.getCurrentItem() != null) { final ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { if (item.getItemMeta().hasDisplayName()) { if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) { Methods.updateAuction(); int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); - openShop(player, shopType.get(player), shopCategory.get(player), page + 1); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page + 1); playClick(player); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) { Methods.updateAuction(); int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); if (page == 1) page++; - openShop(player, shopType.get(player), shopCategory.get(player), page - 1); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page - 1); playClick(player); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Refesh.Name")))) { Methods.updateAuction(); int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); - openShop(player, shopType.get(player), shopCategory.get(player), page); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page); playClick(player); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Selling.Name")))) { - openShop(player, ShopType.BID, shopCategory.get(player), 1); + openShop(player, ShopType.BID, shopCategory.get(player.getUniqueId()), 1); playClick(player); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Bidding.Name")))) { - openShop(player, ShopType.SELL, shopCategory.get(player), 1); + openShop(player, ShopType.SELL, shopCategory.get(player.getUniqueId()), 1); playClick(player); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancelled/ExpiredItems.Name")))) { openPlayersExpiredList(player, 1); playClick(player); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.SellingItems.Name")))) { openPlayersCurrentList(player, 1); playClick(player); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category1.Name")))) { - openCategories(player, shopType.get(player)); + openCategories(player, shopType.get(player.getUniqueId())); playClick(player); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category2.Name")))) { - openCategories(player, shopType.get(player)); + openCategories(player, shopType.get(player.getUniqueId())); playClick(player); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name")))) { return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name")))) { return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name")))) { return; } } + if (List.containsKey(player)) { - if (List.get(player).size() >= slot) { - int id = List.get(player).get(slot); + if (List.get(player.getUniqueId()).size() >= slot) { + int id = List.get(player.getUniqueId()).get(slot); boolean T = false; + if (data.contains("Items")) { for (String i : data.getConfigurationSection("Items").getKeys(false)) { int ID = data.getInt("Items." + i + ".StoreID"); + if (id == ID) { if (player.hasPermission("crazyAuctions.admin") || player.hasPermission("crazyauctions.force-end")) { if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) { @@ -657,10 +733,12 @@ public class GUI implements Listener { for (; data.contains("OutOfTime/Cancelled." + num); num++) ; String seller = data.getString("Items." + i + ".Seller"); Player sellerPlayer = Methods.getPlayer(seller); + if (Methods.isOnline(seller) && sellerPlayer != null) { sellerPlayer.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage()); } - AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Bukkit.getOfflinePlayer(seller)), data.getItemStack("Items." + i + ".Item"), CancelledReason.ADMIN_FORCE_CANCEL); + + AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Bukkit.getOfflinePlayer(seller)), data.getItemStack("Items." + i + ".Item"), Reaons.ADMIN_FORCE_CANCEL); Bukkit.getPluginManager().callEvent(event); data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time")); @@ -668,72 +746,86 @@ public class GUI implements Listener { data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item")); data.set("Items." + i, null); Files.DATA.saveFile(); - player.sendMessage(Messages.ADMIN_FORCE_CENCELLED.getMessage()); + player.sendMessage(Messages.ADMIN_FORCE_CANCELLED.getMessage()); playClick(player); int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); - openShop(player, shopType.get(player), shopCategory.get(player), page); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page); return; } } + 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 name = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name"); ItemStack I; + 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); } + inv.setItem(slot, I); playClick(player); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); return; } + long cost = data.getLong("Items." + i + ".Price"); - if (CurrencyManager.getMoney(player) < cost) { + + if (plugin.getSupport().getMoney(player) < cost) { String it = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Item"); String name = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name"); ItemStack I; + 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); } + inv.setItem(slot, I); playClick(player); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); return; } + 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 name = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name"); ItemStack I; + 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); } + inv.setItem(slot, I); playClick(player); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); return; } + playClick(player); openBidding(player, i); - biddingID.put(player, i); + biddingID.put(player.getUniqueId(), i); } else { playClick(player); openBuying(player, i); } + return; } } } + if (!T) { playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } @@ -743,62 +835,72 @@ public class GUI implements Listener { } } } + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Buying-Item")))) { e.setCancelled(true); int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { if (e.getCurrentItem() != null) { ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { if (item.getItemMeta().hasDisplayName()) { if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Confirm.Name")))) { - String ID = IDs.get(player); + String ID = IDs.get(player.getUniqueId()); long cost = data.getLong("Items." + ID + ".Price"); String seller = data.getString("Items." + ID + ".Seller"); + if (!data.contains("Items." + ID)) { playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } + if (Methods.isInvFull(player)) { playClick(player); player.closeInventory(); player.sendMessage(Messages.INVENTORY_FULL.getMessage()); return; } - if (CurrencyManager.getMoney(player) < cost) { + + if (plugin.getSupport().getMoney(player) < cost) { playClick(player); player.closeInventory(); HashMap placeholders = new HashMap<>(); - placeholders.put("%Money_Needed%", (cost - CurrencyManager.getMoney(player)) + ""); - placeholders.put("%money_needed%", (cost - CurrencyManager.getMoney(player)) + ""); + placeholders.put("%Money_Needed%", (cost - plugin.getSupport().getMoney(player)) + ""); + placeholders.put("%money_needed%", (cost - plugin.getSupport().getMoney(player)) + ""); player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders)); return; } + ItemStack i = data.getItemStack("Items." + ID + ".Item"); - Bukkit.getPluginManager().callEvent(new AuctionBuyEvent(player, i, cost)); - CurrencyManager.removeMoney(player, cost); - CurrencyManager.addMoney(Methods.getOfflinePlayer(seller), cost); + plugin.getServer().getPluginManager().callEvent(new AuctionBuyEvent(player, i, cost)); + plugin.getSupport().removeMoney(player, cost); + plugin.getSupport().addMoney(Methods.getOfflinePlayer(seller), cost); HashMap placeholders = new HashMap<>(); placeholders.put("%Price%", Methods.getPrice(ID, false)); placeholders.put("%price%", Methods.getPrice(ID, false)); placeholders.put("%Player%", player.getName()); placeholders.put("%player%", player.getName()); + player.sendMessage(Messages.BOUGHT_ITEM.getMessage(placeholders)); if (Methods.isOnline(seller) && Methods.getPlayer(seller) != null) { Player sell = Methods.getPlayer(seller); sell.sendMessage(Messages.PLAYER_BOUGHT_ITEM.getMessage(placeholders)); } + player.getInventory().addItem(i); data.set("Items." + ID, null); Files.DATA.saveFile(); playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancel.Name")))) { - openShop(player, shopType.get(player), shopCategory.get(player), 1); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); playClick(player); return; } @@ -807,30 +909,34 @@ public class GUI implements Listener { } } } + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Players-Current-Items")))) { e.setCancelled(true); int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { if (e.getCurrentItem() != null) { ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { if (item.getItemMeta().hasDisplayName()) { if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { - openShop(player, shopType.get(player), shopCategory.get(player), 1); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); playClick(player); return; } } + if (List.containsKey(player)) { - if (List.get(player).size() >= slot) { - int id = List.get(player).get(slot); + if (List.get(player.getUniqueId()).size() >= slot) { + int id = List.get(player.getUniqueId()).get(slot); boolean T = false; if (data.contains("Items")) { for (String i : data.getConfigurationSection("Items").getKeys(false)) { int ID = data.getInt("Items." + i + ".StoreID"); if (id == ID) { player.sendMessage(Messages.CANCELLED_ITEM.getMessage()); - AuctionCancelledEvent event = new AuctionCancelledEvent(player, data.getItemStack("Items." + i + ".Item"), CancelledReason.PLAYER_FORCE_CANCEL); + AuctionCancelledEvent event = new AuctionCancelledEvent(player, data.getItemStack("Items." + i + ".Item"), Reaons.PLAYER_FORCE_CANCEL); Bukkit.getPluginManager().callEvent(event); int num = 1; for (; data.contains("OutOfTime/Cancelled." + num); num++) ; @@ -846,9 +952,10 @@ public class GUI implements Listener { } } } + if (!T) { playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } @@ -858,6 +965,7 @@ public class GUI implements Listener { } } } + if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Cancelled/Expired-Items")))) { e.setCancelled(true); final int slot = e.getRawSlot(); @@ -869,9 +977,10 @@ public class GUI implements Listener { if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { Methods.updateAuction(); playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) { Methods.updateAuction(); int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); @@ -880,6 +989,7 @@ public class GUI implements Listener { openPlayersExpiredList(player, (page - 1)); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Return.Name")))) { Methods.updateAuction(); int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); @@ -896,12 +1006,14 @@ public class GUI implements Listener { } } } + player.sendMessage(Messages.GOT_ITEM_BACK.getMessage()); Files.DATA.saveFile(); playClick(player); openPlayersExpiredList(player, page); return; } + if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) { Methods.updateAuction(); int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); @@ -910,9 +1022,10 @@ public class GUI implements Listener { return; } } + if (List.containsKey(player)) { - if (List.get(player).size() >= slot) { - int id = List.get(player).get(slot); + if (List.get(player.getUniqueId()).size() >= slot) { + int id = List.get(player.getUniqueId()).get(slot); boolean T = false; if (data.contains("OutOfTime/Cancelled")) { for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { @@ -933,9 +1046,10 @@ public class GUI implements Listener { } } } + if (!T) { playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); } } @@ -946,5 +1060,4 @@ public class GUI implements Listener { } } } - } diff --git a/paper/src/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/controllers/MarcoListener.java similarity index 65% rename from paper/src/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java rename to paper/src/main/java/com/badbones69/crazyauctions/paper/controllers/MarcoListener.java index 83deb9e..f3f5606 100644 --- a/paper/src/main/java/com/badbones69/crazyauctions/controllers/DupePatch.java +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/controllers/MarcoListener.java @@ -1,19 +1,19 @@ -package com.badbones69.crazyauctions.controllers; +package com.badbones69.crazyauctions.paper.controllers; -import com.badbones69.crazyauctions.api.FileManager; +import com.badbones69.crazyauctions.paper.api.FileManager.Files; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -public class DupePatch implements Listener { +public class MarcoListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPreCommand(PlayerCommandPreprocessEvent event) { Player player = event.getPlayer(); - boolean macro = FileManager.Files.CONFIG.getFile().getBoolean("Settings.Patches.Macro-Dupe", true); + boolean macro = Files.CONFIG.getFile().getBoolean("Settings.Patches.Macro-Dupe", true); if (!macro) return; diff --git a/paper/src/main/java/com/badbones69/crazyauctions/paper/currency/VaultSupport.java b/paper/src/main/java/com/badbones69/crazyauctions/paper/currency/VaultSupport.java new file mode 100644 index 0000000..f4ffbae --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazyauctions/paper/currency/VaultSupport.java @@ -0,0 +1,45 @@ +package com.badbones69.crazyauctions.paper.currency; + +import com.badbones69.crazyauctions.paper.CrazyAuctions; +import net.milkbowl.vault.economy.Economy; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.jetbrains.annotations.NotNull; + +public class VaultSupport { + + private final CrazyAuctions plugin = CrazyAuctions.get(); + + private Economy vault = null; + + public Economy getVault() { + return vault; + } + + public void loadVault() { + RegisteredServiceProvider serviceProvider = this.plugin.getServer().getServicesManager().getRegistration(Economy.class); + + if (serviceProvider != null) vault = serviceProvider.getProvider(); + } + + public Long getMoney(@NotNull Player player) { + return (long) vault.getBalance(player); + } + + public void removeMoney(@NotNull Player player, Long amount) { + vault.withdrawPlayer(player, amount); + } + + public void removeMoney(@NotNull OfflinePlayer player, Long amount) { + vault.withdrawPlayer(player, amount); + } + + public void addMoney(Player player, Long amount) { + vault.depositPlayer(player, amount); + } + + public void addMoney(OfflinePlayer player, Long amount) { + vault.depositPlayer(player, amount); + } +} \ No newline at end of file diff --git a/paper/src/main/resources/config1.13-Up.yml b/paper/src/main/resources/config.yml similarity index 100% rename from paper/src/main/resources/config1.13-Up.yml rename to paper/src/main/resources/config.yml diff --git a/paper/src/main/resources/plugin.yml b/paper/src/main/resources/plugin.yml index 5de4b8b..ed936cd 100644 --- a/paper/src/main/resources/plugin.yml +++ b/paper/src/main/resources/plugin.yml @@ -1,12 +1,49 @@ -name: CrazyAuctions -author: BadBones69 -main: com.badbones69.crazyauctions.Main -website: https://www.spigotmc.org/resources/authors/badbones69.9719/ -version: ${version}${build.number} +name: '${name}' +main: '${group}.${name}' + +authors: ${authors} + +version: '${version}' +api-version: '${apiVersion}' +description: '${description}' +website: '${website}' + depend: [Vault] -api-version: 1.13 -description: A plugin to auction off items globally. + commands: - ca: + crazyauctions: description: Opens the Crazy Auctions GUI. - aliases: [crazyauction, crazyauctions, ah, hdv] \ No newline at end of file + aliases: [crazyauction, ah, ca] + +permissions: + crazyauctions.access: + default: true + + crazyauctions.test: + default: op + + crazyauctions.view: + default: true + + crazyauctions.reload: + default: op + + crazyauctions.sell: + default: true + + crazyauctions.bid: + default: true + + crazyauctions.player.*: + default: false + children: + crazyauctions.bid: true + crazyauctions.sell: true + crazyauctions.access: true + crazyauctions.view: true + + crazyauctions.admin: + default: op + children: + crazyauctions.test: true + crazyauctions.reload: true \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..e94a571 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,13 @@ +pluginManagement { + repositories { + + maven { url = 'https://repo.papermc.io/repository/maven-public/' } + + gradlePluginPortal() + mavenCentral() + } +} + +rootProject.name = 'CrazyAuctions' + +include 'paper' \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts deleted file mode 100644 index ca51714..0000000 --- a/settings.gradle.kts +++ /dev/null @@ -1,13 +0,0 @@ -pluginManagement { - repositories { - maven("https://repo.papermc.io/repository/maven-public/") - - gradlePluginPortal() - mavenCentral() - } -} - -rootProject.name = "CrazyAuctions" - -include("common") -include("paper") \ No newline at end of file