update everything

This commit is contained in:
Ryder Belserion 2023-11-27 01:17:59 -05:00
parent 2b1110f03c
commit 24757083a9
No known key found for this signature in database
43 changed files with 2076 additions and 2091 deletions

View File

@ -2,7 +2,7 @@
Contributions to the project are always welcome, Pull Requests do have some guidelines before being approved. 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. ## 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. 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. 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.

151
build.gradle Normal file
View File

@ -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"])
}
}
}
}

View File

@ -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)
}
}
}
}
}

View File

@ -1,11 +0,0 @@
plugins {
`kotlin-dsl`
}
dependencies {
implementation(libs.paperweight.plugin)
implementation(libs.jpenilla.plugin)
implementation(libs.shadow.plugin)
}

View File

@ -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"))
}
}
}

View File

@ -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"))
}
}

View File

@ -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/")
}
}
}

View File

@ -3,12 +3,12 @@ org.gradle.parallel = false
org.gradle.warning.mode = all org.gradle.warning.mode = all
authors = ["Ryderbelserion, Badbones69"] authors = ["Ryderbelserion, Badbones69"]
website = https://modrinth.com/plugin/crazycrates website = https://modrinth.com/plugin/crazyauctions
sources = https://github.com/Crazy-Crew/CrazyCrates sources = https://github.com/Crazy-Crew/CrazyAuctions
issues = https://github.com/Crazy-Crew/CrazyCrates/issues issues = https://github.com/Crazy-Crew/CrazyAuctions/issues
group = com.badbones69.com group = com.badbones69.crazyauctions
description = Auction off items in style! description = Auction off items in style.
version = 1.3 version = 1.3
apiVersion = 1.20 apiVersion = 1.20

View File

@ -1,46 +1,35 @@
[versions] [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" kyori_version = "4.14.0"
cluster_version = "3.1"
[plugins] [plugins]
hangar = { id = "io.papermc.hangar-publish-plugin", version = "0.1.0" } hangar = { id = "io.papermc.hangar-publish-plugin", version = "0.1.0" }
modrinth = { id = "com.modrinth.minotaur", version = "2.8.4" } modrinth = { id = "com.modrinth.minotaur", version = "2.8.4" }
[libraries] paperweight = { id = "io.papermc.paperweight.userdev", version = "1.5.9" }
cluster_paper = { module = "com.ryderbelserion.cluster:cluster-paper", version.ref = "cluster_version" } runpaper = { id = "xyz.jpenilla.run-paper", version = "2.2.2" }
cluster_api = { module = "com.ryderbelserion.cluster:cluster-api", version.ref = "cluster_version" } shadowjar = { id = "com.github.johnrengelman.shadow", version = "8.1.1" }
[libraries]
adventure = { module = "net.kyori:adventure-api", version.ref = "kyori_version" } adventure = { module = "net.kyori:adventure-api", version.ref = "kyori_version" }
minimessage = { module = "net.kyori:adventure-text-minimessage", 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" } vault = { module = "com.github.MilkBowl:VaultAPI", version = "1.7.1" }
kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "jetbrains_kotlin" }
triumphcmds = { module = "dev.triumphteam:triumph-cmd-bukkit", version = "2.0.0-SNAPSHOT" } 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" } metrics = { module = "org.bstats:bstats-bukkit", version = "3.0.2" }
itemsadder = { module = "com.github.LoneDev6:api-itemsadder", version = "3.6.1" } 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" } holographicdisplays = { module = "me.filoghost.holographicdisplays:holographicdisplays-api", version = "3.0.0" }
decentholograms = { module = "com.github.decentsoftware-eu:decentholograms", version = "2.8.4" } decentholograms = { module = "com.github.decentsoftware-eu:decentholograms", version = "2.8.4" }
placeholderapi = { module = "me.clip:placeholderapi", version = "2.11.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" }

92
gradlew.bat vendored
View File

@ -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

64
paper/build.gradle Normal file
View File

@ -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<String, String> 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)
}
}
}

View File

@ -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)
}
}
}
}

View File

@ -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<String, String> 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<String, String> 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 <Player>
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 <Price> [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<String, String> 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<String, String> 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<String, String> 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<Material> getDamageableItems() {
ArrayList<Material> 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);
}
}

View File

@ -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<ItemStack> getItems(Player player) {
FileConfiguration data = Files.DATA.getFile();
ArrayList<ItemStack> 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<ItemStack> getItems(Player player, ShopType type) {
FileConfiguration data = Files.DATA.getFile();
ArrayList<ItemStack> 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;
}
}

View File

@ -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, File> files = new HashMap<>();
private ArrayList<String> homeFolders = new ArrayList<>();
private ArrayList<CustomFile> customFiles = new ArrayList<>();
private HashMap<String, String> autoGenerateFiles = new HashMap<>();
private HashMap<Files, FileConfiguration> 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;
}
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<Economy> 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);
}
}

View File

@ -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;
}
}

View File

@ -1,11 +1,9 @@
package com.badbones69.crazyauctions; package com.badbones69.crazyauctions.paper;
import com.badbones69.crazyauctions.api.FileManager.Files; import com.badbones69.crazyauctions.paper.api.FileManager.Files;
import com.badbones69.crazyauctions.api.Messages; import com.badbones69.crazyauctions.paper.api.enums.Messages;
import com.badbones69.crazyauctions.api.Version; import com.badbones69.crazyauctions.paper.api.events.AuctionExpireEvent;
import com.badbones69.crazyauctions.api.events.AuctionExpireEvent; import com.badbones69.crazyauctions.paper.api.events.AuctionWinBidEvent;
import com.badbones69.crazyauctions.api.events.AuctionWinBidEvent;
import com.badbones69.crazyauctions.currency.CurrencyManager;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -19,18 +17,19 @@ import java.util.regex.Pattern;
public class Methods { 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) { public static String color(String message) {
if (Version.isNewer(Version.v1_15_R1)) { Matcher matcher = HEX_PATTERN.matcher(message);
Matcher matcher = HEX_PATTERN.matcher(message); StringBuilder buffer = new StringBuilder();
StringBuffer buffer = new StringBuffer();
while (matcher.find()) { while (matcher.find()) {
matcher.appendReplacement(buffer, net.md_5.bungee.api.ChatColor.of(matcher.group()).toString()); matcher.appendReplacement(buffer, net.md_5.bungee.api.ChatColor.of(matcher.group()).toString());
}
return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString());
} }
return ChatColor.translateAlternateColorCodes('&', message);
return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString());
} }
public static String getPrefix() { public static String getPrefix() {
@ -47,46 +46,45 @@ public class Methods {
public static ItemStack makeItem(String type, int amount) { public static ItemStack makeItem(String type, int amount) {
int ty = 0; int ty = 0;
if (type.contains(":")) { if (type.contains(":")) {
String[] b = type.split(":"); String[] b = type.split(":");
type = b[0]; type = b[0];
ty = Integer.parseInt(b[1]); ty = Integer.parseInt(b[1]);
} }
Material m = Material.matchMaterial(type); Material m = Material.matchMaterial(type);
ItemStack item; ItemStack item;
try { try {
item = new ItemStack(m, amount, (short) ty); item = new ItemStack(m, amount, (short) ty);
} catch (Exception e) { } catch (Exception e) {
if (Version.isNewer(Version.v1_12_R1)) { item = new ItemStack(Material.RED_TERRACOTTA);
item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1);
} else {
item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14);
}
} }
return item; return item;
} }
public static ItemStack makeItem(String type, int amount, String name) { public static ItemStack makeItem(String type, int amount, String name) {
int ty = 0; int ty = 0;
if (type.contains(":")) { if (type.contains(":")) {
String[] b = type.split(":"); String[] b = type.split(":");
type = b[0]; type = b[0];
ty = Integer.parseInt(b[1]); ty = Integer.parseInt(b[1]);
} }
Material m = Material.matchMaterial(type); Material m = Material.matchMaterial(type);
ItemStack item; ItemStack item;
try { try {
item = new ItemStack(m, amount, (short) ty); item = new ItemStack(m, amount, (short) ty);
} catch (Exception e) { } catch (Exception e) {
if (Version.isNewer(Version.v1_12_R1)) { item = new ItemStack(Material.RED_TERRACOTTA);
item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1);
} else {
item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14);
}
} }
ItemMeta me = item.getItemMeta(); ItemMeta me = item.getItemMeta();
me.setDisplayName(color(name)); me.setDisplayName(color(name));
item.setItemMeta(me); item.setItemMeta(me);
return item; return item;
@ -102,22 +100,21 @@ public class Methods {
} }
Material m = Material.matchMaterial(type); Material m = Material.matchMaterial(type);
ItemStack item; ItemStack item;
try { try {
item = new ItemStack(m, amount, (short) ty); item = new ItemStack(m, amount, (short) ty);
} catch (Exception e) { } catch (Exception e) {
if (Version.isNewer(Version.v1_12_R1)) { item = new ItemStack(Material.RED_TERRACOTTA);
item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1);
} else {
item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14);
}
} }
ItemMeta me = item.getItemMeta(); ItemMeta me = item.getItemMeta();
me.setDisplayName(color(name)); me.setDisplayName(color(name));
for (String L : lore)
l.add(color(L)); for (String L : lore) l.add(color(L));
me.setLore(l); me.setLore(l);
item.setItemMeta(me); item.setItemMeta(me);
return item; return item;
} }
@ -126,6 +123,7 @@ public class Methods {
ItemMeta m = item.getItemMeta(); ItemMeta m = item.getItemMeta();
m.setDisplayName(color(name)); m.setDisplayName(color(name));
item.setItemMeta(m); item.setItemMeta(m);
return item; return item;
} }
@ -133,30 +131,35 @@ public class Methods {
ArrayList<String> l = new ArrayList<>(); ArrayList<String> l = new ArrayList<>();
ItemStack item = new ItemStack(material, amount, (short) type); ItemStack item = new ItemStack(material, amount, (short) type);
ItemMeta m = item.getItemMeta(); ItemMeta m = item.getItemMeta();
m.setDisplayName(color(name)); m.setDisplayName(color(name));
for (String L : lore) for (String L : lore) l.add(color(L));
l.add(color(L));
m.setLore(l); m.setLore(l);
item.setItemMeta(m); item.setItemMeta(m);
return item; return item;
} }
public static ItemStack makeItem(Material material, int amount, int type, String name, List<String> lore, Map<Enchantment, Integer> enchants) { public static ItemStack makeItem(Material material, int amount, int type, String name, List<String> lore, Map<Enchantment, Integer> enchants) {
ItemStack item = new ItemStack(material, amount, (short) type); ItemStack item = new ItemStack(material, amount, (short) type);
ItemMeta m = item.getItemMeta(); ItemMeta m = item.getItemMeta();
m.setDisplayName(name); m.setDisplayName(name);
m.setLore(lore); m.setLore(lore);
item.setItemMeta(m); item.setItemMeta(m);
item.addUnsafeEnchantments(enchants); item.addUnsafeEnchantments(enchants);
return item; return item;
} }
public static ItemStack addLore(ItemStack item, String i) { public static ItemStack addLore(ItemStack item, String i) {
ArrayList<String> lore = new ArrayList<>(); ArrayList<String> lore = new ArrayList<>();
ItemMeta m = item.getItemMeta(); ItemMeta m = item.getItemMeta();
if (item.getItemMeta().hasLore()) { if (item.getItemMeta().hasLore()) {
lore.addAll(item.getItemMeta().getLore()); lore.addAll(item.getItemMeta().getLore());
} }
lore.add(i); lore.add(i);
m.setLore(lore); m.setLore(lore);
item.setItemMeta(m); item.setItemMeta(m);
@ -167,40 +170,25 @@ public class Methods {
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
ArrayList<String> lore = new ArrayList<>(); ArrayList<String> lore = new ArrayList<>();
ItemMeta m = item.getItemMeta(); ItemMeta m = item.getItemMeta();
if (item.hasItemMeta() && item.getItemMeta().hasLore()) { if (item.hasItemMeta() && item.getItemMeta().hasLore()) {
lore.addAll(item.getItemMeta().getLore()); lore.addAll(item.getItemMeta().getLore());
} }
for (String i : list)
lore.add(color(i)); for (String i : list) lore.add(color(i));
m.setLore(lore); m.setLore(lore);
item.setItemMeta(m); item.setItemMeta(m);
} }
return item; 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) { public static ItemStack getItemInHand(Player player) {
if (getVersion() >= 191) { return player.getInventory().getItemInMainHand();
return player.getInventory().getItemInMainHand();
} else {
return player.getItemInHand();
}
} }
@SuppressWarnings("deprecation")
public static void setItemInHand(Player player, ItemStack item) { public static void setItemInHand(Player player, ItemStack item) {
if (getVersion() >= 191) { player.getInventory().setItemInMainHand(item);
player.getInventory().setItemInMainHand(item);
} else {
player.setItemInHand(item);
}
} }
public static boolean isInt(String s) { public static boolean isInt(String s) {
@ -209,6 +197,7 @@ public class Methods {
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
return false; return false;
} }
return true; return true;
} }
@ -218,6 +207,7 @@ public class Methods {
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
return false; return false;
} }
return true; return true;
} }
@ -229,25 +219,17 @@ public class Methods {
} }
} }
@SuppressWarnings("deprecation")
public static OfflinePlayer getOfflinePlayer(String name) { public static OfflinePlayer getOfflinePlayer(String name) {
return Bukkit.getServer().getOfflinePlayer(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) { public static boolean isOnline(String name) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.getName().equalsIgnoreCase(name)) { if (player.getName().equalsIgnoreCase(name)) {
return true; return true;
} }
} }
return false; return false;
} }
@ -257,6 +239,7 @@ public class Methods {
return true; return true;
} }
} }
p.sendMessage(Messages.NOT_ONLINE.getMessage()); p.sendMessage(Messages.NOT_ONLINE.getMessage());
return false; return false;
} }
@ -266,21 +249,21 @@ public class Methods {
player.sendMessage(Messages.NO_PERMISSION.getMessage()); player.sendMessage(Messages.NO_PERMISSION.getMessage());
return false; return false;
} }
return true; return true;
} }
public static boolean hasPermission(CommandSender sender, String perm) { public static boolean hasPermission(CommandSender sender, String perm) {
if (sender instanceof Player) { if (sender instanceof Player player) {
Player player = (Player) sender;
if (!player.hasPermission("crazyauctions." + perm)) { if (!player.hasPermission("crazyauctions." + perm)) {
player.sendMessage(Messages.NO_PERMISSION.getMessage()); player.sendMessage(Messages.NO_PERMISSION.getMessage());
return false; return false;
} else {
return true;
} }
} else {
return true; return true;
} }
return true;
} }
public static List<ItemStack> getPage(List<ItemStack> list, Integer page) { public static List<ItemStack> getPage(List<ItemStack> list, Integer page) {
@ -292,6 +275,7 @@ public class Methods {
for (; index < endIndex; index++) { for (; index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index)); if (index < list.size()) items.add(list.get(index));
} }
for (; items.size() == 0; page--) { for (; items.size() == 0; page--) {
if (page <= 0) break; if (page <= 0) break;
index = page * max - max; index = page * max - max;
@ -300,6 +284,7 @@ public class Methods {
if (index < list.size()) items.add(list.get(index)); if (index < list.size()) items.add(list.get(index));
} }
} }
return items; return items;
} }
@ -309,9 +294,11 @@ public class Methods {
int max = 45; int max = 45;
int index = page * max - max; int index = page * max - max;
int endIndex = index >= list.size() ? list.size() - 1 : index + max; int endIndex = index >= list.size() ? list.size() - 1 : index + max;
for (; index < endIndex; index++) { for (; index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index)); if (index < list.size()) items.add(list.get(index));
} }
for (; items.size() == 0; page--) { for (; items.size() == 0; page--) {
if (page <= 0) break; if (page <= 0) break;
index = page * max - max; index = page * max - max;
@ -320,6 +307,7 @@ public class Methods {
if (index < list.size()) items.add(list.get(index)); if (index < list.size()) items.add(list.get(index));
} }
} }
return items; return items;
} }
@ -348,6 +336,7 @@ public class Methods {
public static long convertToMill(String time) { public static long convertToMill(String time) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
for (String i : time.split(" ")) { for (String i : time.split(" ")) {
if (i.contains("D") || i.contains("d")) { if (i.contains("D") || i.contains("d")) {
cal.add(Calendar.DATE, Integer.parseInt(i.replace("D", "").replace("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", ""))); cal.add(Calendar.SECOND, Integer.parseInt(i.replace("S", "").replace("s", "")));
} }
} }
return cal.getTimeInMillis(); return cal.getTimeInMillis();
} }
@ -375,6 +365,7 @@ public class Methods {
Calendar expireTime = Calendar.getInstance(); Calendar expireTime = Calendar.getInstance();
Calendar fullExpireTime = Calendar.getInstance(); Calendar fullExpireTime = Calendar.getInstance();
boolean shouldSave = false; boolean shouldSave = false;
if (data.contains("OutOfTime/Cancelled")) { if (data.contains("OutOfTime/Cancelled")) {
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
fullExpireTime.setTimeInMillis(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time")); fullExpireTime.setTimeInMillis(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time"));
@ -384,33 +375,41 @@ public class Methods {
} }
} }
} }
if (data.contains("Items")) { if (data.contains("Items")) {
for (String i : data.getConfigurationSection("Items").getKeys(false)) { for (String i : data.getConfigurationSection("Items").getKeys(false)) {
expireTime.setTimeInMillis(data.getLong("Items." + i + ".Time-Till-Expire")); expireTime.setTimeInMillis(data.getLong("Items." + i + ".Time-Till-Expire"));
fullExpireTime.setTimeInMillis(data.getLong("Items." + i + ".Full-Time")); fullExpireTime.setTimeInMillis(data.getLong("Items." + i + ".Full-Time"));
if (cal.after(expireTime)) { if (cal.after(expireTime)) {
int num = 1; int num = 1;
for (; data.contains("OutOfTime/Cancelled." + num); num++) ; 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 winner = data.getString("Items." + i + ".TopBidder");
String seller = data.getString("Items." + i + ".Seller"); String seller = data.getString("Items." + i + ".Seller");
Long price = data.getLong("Items." + i + ".Price"); 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<String, String> placeholders = new HashMap<>(); HashMap<String, String> placeholders = new HashMap<>();
placeholders.put("%Price%", getPrice(i, false)); placeholders.put("%Price%", getPrice(i, false));
placeholders.put("%price%", getPrice(i, false)); placeholders.put("%price%", getPrice(i, false));
placeholders.put("%Player%", winner); placeholders.put("%Player%", winner);
placeholders.put("%player%", winner); placeholders.put("%player%", winner);
if (isOnline(winner) && getPlayer(winner) != null) { if (isOnline(winner) && getPlayer(winner) != null) {
Player player = getPlayer(winner); Player player = getPlayer(winner);
Bukkit.getPluginManager().callEvent(new AuctionWinBidEvent(player, data.getItemStack("Items." + i + ".Item"), price)); Bukkit.getPluginManager().callEvent(new AuctionWinBidEvent(player, data.getItemStack("Items." + i + ".Item"), price));
player.sendMessage(Messages.WIN_BIDDING.getMessage(placeholders)); player.sendMessage(Messages.WIN_BIDDING.getMessage(placeholders));
} }
if (isOnline(seller) && getPlayer(seller) != null) { if (isOnline(seller) && getPlayer(seller) != null) {
Player player = getPlayer(seller); Player player = getPlayer(seller);
player.sendMessage(Messages.SOMEONE_WON_PLAYERS_BID.getMessage(placeholders)); player.sendMessage(Messages.SOMEONE_WON_PLAYERS_BID.getMessage(placeholders));
} }
data.set("OutOfTime/Cancelled." + num + ".Seller", winner); data.set("OutOfTime/Cancelled." + num + ".Seller", winner);
data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis()); data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis());
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
@ -418,9 +417,11 @@ public class Methods {
} else { } else {
String seller = data.getString("Items." + i + ".Seller"); String seller = data.getString("Items." + i + ".Seller");
Player player = getPlayer(seller); Player player = getPlayer(seller);
if (isOnline(seller) && getPlayer(seller) != null) { if (isOnline(seller) && getPlayer(seller) != null) {
player.sendMessage(Messages.ITEM_HAS_EXPIRED.getMessage()); player.sendMessage(Messages.ITEM_HAS_EXPIRED.getMessage());
} }
AuctionExpireEvent event = new AuctionExpireEvent(player, data.getItemStack("Items." + i + ".Item")); AuctionExpireEvent event = new AuctionExpireEvent(player, data.getItemStack("Items." + i + ".Item"));
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); 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 + ".StoreID", data.getInt("Items." + i + ".StoreID"));
data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item")); data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item"));
} }
data.set("Items." + i, null); data.set("Items." + i, null);
shouldSave = true; shouldSave = true;
} }
} }
} }
if (shouldSave) Files.DATA.saveFile(); if (shouldSave) Files.DATA.saveFile();
} }
public static String getPrice(String ID, Boolean Expired) { public static String getPrice(String ID, Boolean Expired) {
long price = 0L; long price = 0L;
if (Expired) { if (Expired) {
if (Files.DATA.getFile().contains("OutOfTime/Cancelled." + ID + ".Price")) { if (Files.DATA.getFile().contains("OutOfTime/Cancelled." + ID + ".Price")) {
price = Files.DATA.getFile().getLong("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"); price = Files.DATA.getFile().getLong("Items." + ID + ".Price");
} }
} }
return String.valueOf(price); return String.valueOf(price);
} }
} }

View File

@ -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<ItemStack> getItems(Player player, ShopType type) {
FileConfiguration data = Files.DATA.getFile();
ArrayList<ItemStack> 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;
}
}

View File

@ -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, File> files = new HashMap<>();
private final List<String> homeFolders = new ArrayList<>();
private final List<CustomFile> customFiles = new ArrayList<>();
private final HashMap<String, String> jarHomeFolders = new HashMap<>();
private final HashMap<String, String> autoGenerateFiles = new HashMap<>();
private final HashMap<Files, FileConfiguration> 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<String> getAllCratesNames() {
List<String> 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: <a href="https://bukkit.org/threads/extracting-file-from-jar.16962">...</a>
*/
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!");
}
}
}
}

View File

@ -1,7 +1,6 @@
package com.badbones69.crazyauctions.api; package com.badbones69.crazyauctions.paper.api.enums;
import org.bukkit.Material; import org.bukkit.Material;
import java.util.ArrayList; import java.util.ArrayList;
public enum Category { public enum Category {
@ -41,17 +40,10 @@ public enum Category {
private static ArrayList<Material> getArmor() { private static ArrayList<Material> getArmor() {
ArrayList<Material> ma = new ArrayList<>(); ArrayList<Material> ma = new ArrayList<>();
if (Version.isNewer(Version.v1_12_R1)) { ma.add(Material.GOLDEN_HELMET);
ma.add(Material.matchMaterial("GOLDEN_HELMET")); ma.add(Material.GOLDEN_CHESTPLATE);
ma.add(Material.matchMaterial("GOLDEN_CHESTPLATE")); ma.add(Material.GOLDEN_LEGGINGS);
ma.add(Material.matchMaterial("GOLDEN_LEGGINGS")); ma.add(Material.GOLDEN_BOOTS);
ma.add(Material.matchMaterial("GOLDEN_BOOTS"));
} else {
ma.add(Material.matchMaterial("GOLD_HELMET"));
ma.add(Material.matchMaterial("GOLD_CHESTPLATE"));
ma.add(Material.matchMaterial("GOLD_LEGGINGS"));
ma.add(Material.matchMaterial("GOLD_BOOTS"));
}
ma.add(Material.DIAMOND_HELMET); ma.add(Material.DIAMOND_HELMET);
ma.add(Material.DIAMOND_CHESTPLATE); ma.add(Material.DIAMOND_CHESTPLATE);
ma.add(Material.DIAMOND_LEGGINGS); ma.add(Material.DIAMOND_LEGGINGS);
@ -68,42 +60,27 @@ public enum Category {
ma.add(Material.DIAMOND_CHESTPLATE); ma.add(Material.DIAMOND_CHESTPLATE);
ma.add(Material.DIAMOND_LEGGINGS); ma.add(Material.DIAMOND_LEGGINGS);
ma.add(Material.DIAMOND_BOOTS); ma.add(Material.DIAMOND_BOOTS);
if (Version.isNewer(Version.v1_15_R1)) { ma.add(Material.NETHERITE_HELMET);
ma.add(Material.NETHERITE_HELMET); ma.add(Material.NETHERITE_CHESTPLATE);
ma.add(Material.NETHERITE_CHESTPLATE); ma.add(Material.NETHERITE_LEGGINGS);
ma.add(Material.NETHERITE_LEGGINGS); ma.add(Material.NETHERITE_BOOTS);
ma.add(Material.NETHERITE_BOOTS);
}
return ma; return ma;
} }
private static ArrayList<Material> getTools() { private static ArrayList<Material> getTools() {
ArrayList<Material> ma = new ArrayList<>(); ArrayList<Material> ma = new ArrayList<>();
if (Version.isNewer(Version.v1_12_R1)) { ma.add(Material.WOODEN_PICKAXE);
ma.add(Material.matchMaterial("WOODEN_PICKAXE")); ma.add(Material.WOODEN_AXE);
ma.add(Material.matchMaterial("WOODEN_AXE")); ma.add(Material.WOODEN_SHOVEL);
ma.add(Material.matchMaterial("WOODEN_SHOVEL")); ma.add(Material.WOODEN_HOE);
ma.add(Material.matchMaterial("WOODEN_HOE")); ma.add(Material.GOLDEN_PICKAXE);
ma.add(Material.matchMaterial("GOLDEN_PICKAXE")); ma.add(Material.GOLDEN_AXE);
ma.add(Material.matchMaterial("GOLDEN_AXE")); ma.add(Material.GOLDEN_SHOVEL);
ma.add(Material.matchMaterial("GOLDEN_SHOVEL")); ma.add(Material.GOLDEN_HOE);
ma.add(Material.matchMaterial("GOLDEN_HOE")); ma.add(Material.STONE_SHOVEL);
ma.add(Material.matchMaterial("STONE_SHOVEL")); ma.add(Material.IRON_SHOVEL);
ma.add(Material.matchMaterial("IRON_SHOVEL")); ma.add(Material.DIAMOND_SHOVEL);
ma.add(Material.matchMaterial("DIAMOND_SHOVEL"));
} else {
ma.add(Material.matchMaterial("WOOD_PICKAXE"));
ma.add(Material.matchMaterial("WOOD_AXE"));
ma.add(Material.matchMaterial("WOOD_SPADE"));
ma.add(Material.matchMaterial("WOOD_HOE"));
ma.add(Material.matchMaterial("GOLD_PICKAXE"));
ma.add(Material.matchMaterial("GOLD_AXE"));
ma.add(Material.matchMaterial("GOLD_SPADE"));
ma.add(Material.matchMaterial("GOLD_HOE"));
ma.add(Material.matchMaterial("STONE_SPADE"));
ma.add(Material.matchMaterial("IRON_SPADE"));
ma.add(Material.matchMaterial("DIAMOND_SPADE"));
}
ma.add(Material.STONE_PICKAXE); ma.add(Material.STONE_PICKAXE);
ma.add(Material.IRON_PICKAXE); ma.add(Material.IRON_PICKAXE);
ma.add(Material.DIAMOND_PICKAXE); ma.add(Material.DIAMOND_PICKAXE);
@ -113,28 +90,19 @@ public enum Category {
ma.add(Material.STONE_HOE); ma.add(Material.STONE_HOE);
ma.add(Material.IRON_HOE); ma.add(Material.IRON_HOE);
ma.add(Material.DIAMOND_HOE); ma.add(Material.DIAMOND_HOE);
if (Version.isNewer(Version.v1_15_R1)) { ma.add(Material.NETHERITE_PICKAXE);
ma.add(Material.NETHERITE_PICKAXE); ma.add(Material.NETHERITE_AXE);
ma.add(Material.NETHERITE_AXE); ma.add(Material.NETHERITE_HOE);
ma.add(Material.NETHERITE_HOE); ma.add(Material.NETHERITE_SHOVEL);
ma.add(Material.NETHERITE_SHOVEL);
}
return ma; return ma;
} }
private static ArrayList<Material> getWeapons() { private static ArrayList<Material> getWeapons() {
ArrayList<Material> ma = new ArrayList<>(); ArrayList<Material> ma = new ArrayList<>();
if (Version.isNewer(Version.v1_12_R1)) { ma.add(Material.GOLDEN_PICKAXE);
ma.add(Material.matchMaterial("WOODEN_SWORD")); ma.add(Material.GOLDEN_AXE);
ma.add(Material.matchMaterial("WOODEN_AXE")); ma.add(Material.GOLDEN_SHOVEL);
ma.add(Material.matchMaterial("GOLDEN_SWORD")); ma.add(Material.GOLDEN_HOE);
ma.add(Material.matchMaterial("GOLDEN_AXE"));
} else {
ma.add(Material.matchMaterial("WOOD_SWORD"));
ma.add(Material.matchMaterial("WOOD_AXE"));
ma.add(Material.matchMaterial("GOLD_SWORD"));
ma.add(Material.matchMaterial("GOLD_AXE"));
}
ma.add(Material.STONE_SWORD); ma.add(Material.STONE_SWORD);
ma.add(Material.IRON_SWORD); ma.add(Material.IRON_SWORD);
ma.add(Material.DIAMOND_SWORD); ma.add(Material.DIAMOND_SWORD);
@ -142,10 +110,8 @@ public enum Category {
ma.add(Material.IRON_AXE); ma.add(Material.IRON_AXE);
ma.add(Material.DIAMOND_AXE); ma.add(Material.DIAMOND_AXE);
ma.add(Material.BOW); ma.add(Material.BOW);
if (Version.isNewer(Version.v1_15_R1)) { ma.add(Material.NETHERITE_SWORD);
ma.add(Material.NETHERITE_SWORD); ma.add(Material.NETHERITE_AXE);
ma.add(Material.NETHERITE_AXE);
}
return ma; return ma;
} }
@ -162,12 +128,8 @@ public enum Category {
private static ArrayList<Material> getPotions() { private static ArrayList<Material> getPotions() {
ArrayList<Material> ma = new ArrayList<>(); ArrayList<Material> ma = new ArrayList<>();
ma.add(Material.POTION); ma.add(Material.POTION);
if (Material.matchMaterial("SPLASH_POTION") != null) { ma.add(Material.SPLASH_POTION);
ma.add(Material.matchMaterial("SPLASH_POTION")); ma.add(Material.LINGERING_POTION);
}
if (Material.matchMaterial("LINGERING_POTION") != null) {
ma.add(Material.matchMaterial("LINGERING_POTION"));
}
return ma; return ma;
} }
@ -201,5 +163,4 @@ public enum Category {
public ArrayList<Material> getItems() { public ArrayList<Material> getItems() {
return items; return items;
} }
} }

View File

@ -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.paper.Methods;
import com.badbones69.crazyauctions.api.FileManager.Files; import com.badbones69.crazyauctions.paper.api.FileManager.Files;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; 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."), 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!"), 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."), 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."), NOT_A_NUMBER("Not-A-Number", "&c%arg% is not a number."),
GOT_ITEM_BACK("Got-Item-Back", "&7Your item has been returned."), 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."), 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."), 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."), 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."), 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."), 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."), BID_MESSAGE("Bid-Msg", "&7You have just bid &a$%Bid% &7on that item."),
SELLING_DISABLED("Selling-Disabled", "&cThe selling option is disabled."), SELLING_DISABLED("Selling-Disabled", "&cThe selling option is disabled."),
BIDDING_DISABLED("Bidding-Disabled", "&cThe bidding 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 <player>"), CRAZYAUCTIONS_VIEW("CrazyAuctions-View", "&c/ah view <player>"),
CRAZYAUCTIONS_SELL_BID("CrazyAuctions-Sell-Bid", "&c/ah sell/bid <price> [amount of items]"), CRAZYAUCTIONS_SELL_BID("CrazyAuctions-Sell-Bid", "&c/ah sell/bid <price> [amount of items]"),
BOOK_NOT_ALLOWED("Book-Not-Allowed", "&cThat book is not able to be sold in this auction house!"), BOOK_NOT_ALLOWED("Book-Not-Allowed", "&cThat book is not able to be sold in this auction house!"),
@ -55,7 +53,6 @@ public enum Messages {
"&9/Ah Listed - &eView and manage the items you are selling.", "&9/Ah Listed - &eView and manage the items you are selling.",
"&9/Ah Help - &eView this help menu.")); "&9/Ah Help - &eView this help menu."));
private static final FileManager fileManager = FileManager.getInstance();
private final String path; private final String path;
private String defaultMessage; private String defaultMessage;
private List<String> defaultListMessage; private List<String> defaultListMessage;

View File

@ -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. * Cancelled by an administrator.

View File

@ -1,4 +1,4 @@
package com.badbones69.crazyauctions.api; package com.badbones69.crazyauctions.paper.api.enums;
public enum ShopType { public enum ShopType {

View File

@ -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.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -15,9 +15,10 @@ import org.bukkit.inventory.ItemStack;
public class AuctionBuyEvent extends Event { public class AuctionBuyEvent extends Event {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private Player player;
private long price; private final Player player;
private ItemStack item; private final long price;
private final ItemStack item;
/** /**
* *

View File

@ -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.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -17,18 +17,20 @@ import org.bukkit.inventory.ItemStack;
public class AuctionCancelledEvent extends Event { public class AuctionCancelledEvent extends Event {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private final boolean isOnline;
private final ItemStack item;
private final Reaons reason;
private OfflinePlayer offlinePlayer; private OfflinePlayer offlinePlayer;
private Player onlinePlayer; private Player onlinePlayer;
private boolean isOnline;
private ItemStack item;
private CancelledReason reason;
/** /**
* *
* @param offlinePlayer The player whose item is cancelled. * @param offlinePlayer The player whose item is cancelled.
* @param item The item that 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.offlinePlayer = offlinePlayer;
this.item = item; this.item = item;
this.isOnline = false; this.isOnline = false;
@ -40,7 +42,7 @@ public class AuctionCancelledEvent extends Event {
* @param onlinePlayer The player whose item is cancelled. * @param onlinePlayer The player whose item is cancelled.
* @param item The item that 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.onlinePlayer = onlinePlayer;
this.item = item; this.item = item;
this.isOnline = true; this.isOnline = true;
@ -71,7 +73,7 @@ public class AuctionCancelledEvent extends Event {
return item; return item;
} }
public CancelledReason getReason() { public Reaons getReason() {
return reason; return reason;
} }

View File

@ -1,4 +1,4 @@
package com.badbones69.crazyauctions.api.events; package com.badbones69.crazyauctions.paper.api.events;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -16,10 +16,12 @@ import org.bukkit.inventory.ItemStack;
public class AuctionExpireEvent extends Event { public class AuctionExpireEvent extends Event {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private final boolean isOnline;
private final ItemStack item;
private OfflinePlayer offlinePlayer; private OfflinePlayer offlinePlayer;
private Player onlinePlayer; private Player onlinePlayer;
private boolean isOnline;
private ItemStack item;
/** /**
* *

View File

@ -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.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -16,10 +16,10 @@ import org.bukkit.inventory.ItemStack;
public class AuctionListEvent extends Event { public class AuctionListEvent extends Event {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private Player player; private final Player player;
private long price; private final long price;
private ShopType shop; private final ShopType shop;
private ItemStack item; private final ItemStack item;
/** /**
* *

View File

@ -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.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -12,9 +12,9 @@ import org.bukkit.inventory.ItemStack;
public class AuctionNewBidEvent extends Event { public class AuctionNewBidEvent extends Event {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private Player player; private final Player player;
private long bid; private final long bid;
private ItemStack item; private final ItemStack item;
/** /**
* *

View File

@ -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.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -15,9 +15,9 @@ import org.bukkit.inventory.ItemStack;
public class AuctionWinBidEvent extends Event { public class AuctionWinBidEvent extends Event {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private Player player; private final Player player;
private long bid; private final long bid;
private ItemStack item; private final ItemStack item;
/** /**
* *

View File

@ -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);
}
}

View File

@ -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.");
}
}

View File

@ -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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<Material> getDamageableItems() {
ArrayList<Material> 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;
}
}

View File

@ -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<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String commandLabel, String[] args) {
List<String> 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.*");
}
}

View File

@ -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.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class DupePatch implements Listener { public class MarcoListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPreCommand(PlayerCommandPreprocessEvent event) { public void onPreCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer(); 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; if (!macro) return;

View File

@ -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<Economy> 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);
}
}

View File

@ -1,12 +1,49 @@
name: CrazyAuctions name: '${name}'
author: BadBones69 main: '${group}.${name}'
main: com.badbones69.crazyauctions.Main
website: https://www.spigotmc.org/resources/authors/badbones69.9719/ authors: ${authors}
version: ${version}${build.number}
version: '${version}'
api-version: '${apiVersion}'
description: '${description}'
website: '${website}'
depend: [Vault] depend: [Vault]
api-version: 1.13
description: A plugin to auction off items globally.
commands: commands:
ca: crazyauctions:
description: Opens the Crazy Auctions GUI. description: Opens the Crazy Auctions GUI.
aliases: [crazyauction, crazyauctions, ah, hdv] 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

13
settings.gradle Normal file
View File

@ -0,0 +1,13 @@
pluginManagement {
repositories {
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
gradlePluginPortal()
mavenCentral()
}
}
rootProject.name = 'CrazyAuctions'
include 'paper'

View File

@ -1,13 +0,0 @@
pluginManagement {
repositories {
maven("https://repo.papermc.io/repository/maven-public/")
gradlePluginPortal()
mavenCentral()
}
}
rootProject.name = "CrazyAuctions"
include("common")
include("paper")