From 24757083a90075238267aa68dae19b63499c7683 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Mon, 27 Nov 2023 01:17:59 -0500 Subject: [PATCH] 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} (68%) 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 68% 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