add actual v1 code

This commit is contained in:
Ryder Belserion 2023-08-21 14:06:07 -04:00
parent a1bc9a041c
commit f6182d3b3e
No known key found for this signature in database
39 changed files with 3039 additions and 2757 deletions

17
.gitignore vendored
View File

@ -1,3 +1,14 @@
.idea
.gradle
build
\.idea/
*.iml
*.class
target/classes/
target/
\.DS_Store
dependency-reduced-pom.xml

120
README.md
View File

@ -1,111 +1,41 @@
<br />
## Crazy Auctions
[![CrazyAuctions](https://raw.githubusercontent.com/RyderBelserion/Assets/main/crazycrew/banners/CrazyAuctions.png)](https://www.spigotmc.org/resources/crazy-crates.17599/)
[![Join us on Discord](https://img.shields.io/discord/182615261403283459.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.badbones69.com)
<div align="center">
[![CrazyAuctions's Stargazers](https://img.shields.io/github/stars/Crazy-Crew/Crazy-Auctions?label=stars&logo=github)](https://github.com/Crazy-Crew/Crazy-Auctions/stargazers)
[![CrazyAuctions's Forks](https://img.shields.io/github/forks/Crazy-Crew/Crazy-Auctions?label=forks&logo=github)](https://github.com/Crazy-Crew/Crazy-Auctions/network/members)
[![CrazyAuctions's Watchers](https://img.shields.io/github/watchers/Crazy-Crew/Crazy-Auctions?label=watchers&logo=github)](https://github.com/Crazy-Crew/Crazy-Auctions/watchers)
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![GPU License][license-shield]][license-url]
[![Contact][discord-shield]][discord-url]
![CodeFactor][codefactor-shield]
CrazyAuctions is a simple auctions plugin where you can sell your items and bid on other items!
<a href="/#"><img src="https://raw.githubusercontent.com/intergrav/devins-badges/v2/assets/cozy/unsupported/spigot_64h.png" height="50"></a>
<a href="/#"><img src="https://raw.githubusercontent.com/intergrav/devins-badges/v2/assets/cozy/supported/paper_64h.png" height="50"></a>
<a href="/#"><img src="https://raw.githubusercontent.com/intergrav/devins-badges/v2/assets/cozy/supported/purpur_64h.png" height="50"></a>
## Contact
[![Join us on Discord](https://img.shields.io/discord/182615261403283459.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.badbones69.com)
<p align="center">
A simple auctions plugin where you can sell your items and bid on other items!
<br />
<a href="https://github.com/Crazy-Crew/CrazyAuctions/wiki"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="https://github.com/Crazy-Crew/CrazyAuctions/issues">Report Bug</a>
·
<a href="https://github.com/Crazy-Crew/CrazyAuctions/discussions/categories/feature-rquests">Request Feature</a>
·
<a href="https://github.com/Crazy-Crew/CrazyAuctions/discussions/categories/support">Get Support</a>
</p>
</div>
<!-- TABLE OF CONTENTS -->
<details>
<summary>Table of Contents</summary>
<ol>
<li>
<a href="#getting-started">Getting Started</a>
<ul>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#installation">Installation</a></li>
</ul>
</li>
<li><a href="#roadmap">Roadmap</a></li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#license">License</a></li>
<li><a href="#contact">Contact</a></li>
</ol>
</details>
Join us on [Discord](https://discord.badbones69.com)
## Downloads
#### Stable Builds
https://modrinth.com/plugin/crazyauctions ( Soon )
[![Build Status](https://jenkins.badbones69.com/view/Stable/job/Crazy-Auctions/badge/icon)](https://jenkins.badbones69.com/view/Stable/job/Crazy-Auctions/)
#### Beta Builds
https://ci.badbones69.com/view/Beta/job/CrazyAuctions-Beta/
Downloads can be obtained from the [spigot page](https://www.spigotmc.org/resources/crazy-auctions.25219/) or the [Jenkins](https://jenkins.badbones69.com/view/Stable/job/Crazy-Auctions/).
## Getting Started
## Plugin Data
[![bStats Graph Data](https://bstats.org/signatures/bukkit/CrazyAuctions.svg)](https://bstats.org/plugin/bukkit/CrazyAuctions/4624)
How to get started with contributing / maintaining your own version of CrazyAuctions!
## API
In Progress.
### Prerequisites
### Dependency Information
A list of things necessary to make sure you can build CrazyAuctions properly.
* Intellij IDEA
* https://www.jetbrains.com/idea/download/
* Gradle
#### Maven
In Progress.
### Installation
#### Gradle
In Progress.
1. Clone the repo
```sh
git clone https://github.com/Crazy-Crew/CrazyAuctions.git
```
2. Open the repository using Intellij IDEA & wait until it finishes downloading/indexing.
3. Run the shadowJar task.
```gradle
./gradlew shadowJar or gradle shadowJar
```
## Working with CrazyAuctions.
## Roadmap
#### Contributing
Fork the project & open a pull request.
Check our public [trello board](https://trello.com/b/bzQ5TwXo) for our current plans, any bugs and general tracking of the project progress.
## Contributing
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/yourfeature`)
3. Commit your Changes (`git commit -m 'your amazing feature.'`)
4. Push to the Branch (`git push`)
5. Open a Pull Request
## License
Distributed under the MIT License. See [`LICENSE`](/LICENSE) for more information.
[discord-shield]: https://img.shields.io/discord/182615261403283459.svg?style=for-the-badge
[discord-url]: https://discord.gg/crazycrew
[contributors-shield]: https://img.shields.io/github/contributors/Crazy-Crew/CrazyAuctions.svg?style=for-the-badge
[contributors-url]: https://github.com/Crazy-Crew/CrazyAuctions/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/Crazy-Crew/CrazyAuctions.svg?style=for-the-badge
[forks-url]: https://github.com/Crazy-Crew/CrazyAuctions/network/members
[stars-shield]: https://img.shields.io/github/stars/Crazy-Crew/CrazyAuctions.svg?style=for-the-badge
[stars-url]: https://github.com/Crazy-Crew/CrazyAuctions/stargazers
[issues-shield]: https://img.shields.io/github/issues/Crazy-Crew/CrazyAuctions.svg?style=for-the-badge
[issues-url]: https://github.com/Crazy-Crew/CrazyAuctions/issues
[license-shield]: https://img.shields.io/github/license/Crazy-Crew/CrazyAuctions.svg?style=for-the-badge
[license-url]: https://github.com/Crazy-Crew/CrazyAuctions/blob/master/LICENSE.MD
[codefactor-shield]: https://img.shields.io/codefactor/grade/github/crazy-crew/CrazyAuctions/main?style=for-the-badge
#### Compiling
Clone the project & run the install task.

View File

@ -1,80 +0,0 @@
plugins {
java
id("com.github.johnrengelman.shadow") version "7.1.2"
}
val buildNumber: String? = System.getenv("BUILD_NUMBER")
val jenkinsVersion = "1.2.18-b$buildNumber"
group = "com.badbones69.crazyauctions"
version = "1.2.18"
description = "A simple auctions plugin where you can sell your items and bid on other items! "
repositories {
/**
* Paper Team
*/
maven("https://repo.papermc.io/repository/maven-public/")
/**
* NBT Team
*/
maven("https://repo.codemc.org/repository/maven-public/")
/**
* Everything else we need.
*/
maven("https://jitpack.io/")
mavenCentral()
}
dependencies {
implementation(libs.bukkit.bstats)
implementation(libs.nbt.api)
compileOnly(libs.reserve.api)
compileOnly(libs.vault.api)
compileOnly(libs.paper)
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
tasks {
shadowJar {
if (buildNumber != null) {
archiveFileName.set("${rootProject.name}-[v${jenkinsVersion}].jar")
} else {
archiveFileName.set("${rootProject.name}-[v${rootProject.version}].jar")
}
listOf(
"de.tr7zw",
"org.bstats"
).forEach {
relocate(it, "${rootProject.group}.plugin.lib.$it")
}
}
compileJava {
options.release.set(17)
}
processResources {
filesMatching("plugin.yml") {
expand(
"name" to rootProject.name,
"group" to rootProject.group,
"version" to rootProject.version,
"description" to rootProject.description
)
}
}
}

View File

@ -1,30 +0,0 @@
[versions]
# Paper Team
paper = "1.19.2-R0.1-SNAPSHOT"
# Bukkit
bukkit-bstats = "3.0.0"
# Placeholders
placeholder-api = "2.11.2"
# Misc Libraries
nbt-api = "2.10.0"
vault-api = "1.7"
reserve-api = "0.1.5.0"
[libraries]
# Paper Team
paper = { module = "io.papermc.paper:paper-api", version.ref = "paper" }
# Bukkit
bukkit-bstats = { module = "org.bstats:bstats-bukkit", version.ref = "bukkit-bstats" }
# Misc Libraries
vault-api = { module = "com.github.MilkBowl:VaultAPI", version.ref = "vault-api" }
nbt-api = { module = "de.tr7zw:nbt-data-api", version.ref = "nbt-api" }
reserve-api = { module = "net.tnemc:Reserve", version.ref = "reserve-api" }

View File

@ -1,5 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

116
pom.xml Normal file
View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.badbones69</groupId>
<artifactId>crazyauctions</artifactId>
<version>1.2.19</version>
<name>Crazy-Auctions</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--This is used to show the build number for jenkins.-->
<build.number/>
</properties>
<distributionManagement>
<repository>
<id>crazycrew-repo-releases</id>
<name>CrazyCrew Team</name>
<url>https://repo.badbones69.com/releases</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>Reserve</artifactId>
<version>0.1.5.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.name}-[v${project.version}]</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<!-- Replace this with your package! -->
<shadedPattern>com.badbones69.crazyauctions.libraries</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,3 +0,0 @@
rootProject.name = "CrazyAuctions"
enableFeaturePreview("VERSION_CATALOGS")

View File

@ -1,72 +0,0 @@
package com.badbones69.crazyauctions;
import com.badbones69.crazyauctions.api.CrazyManager;
import com.badbones69.crazyauctions.api.FileManager;
import com.badbones69.crazyauctions.api.FileManager.Files;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class CrazyAuctions extends JavaPlugin implements Listener {
private static CrazyAuctions plugin;
private Starter starter;
private final FileManager fileManager = getStarter().getFileManager();
private final CrazyManager crazyManager = getStarter().getCrazyManager();
private final Methods methods = getStarter().getMethods();
private boolean isEnabled = false;
@Override
public void onEnable() {
try {
plugin = this;
starter = new Starter();
starter.run();
fileManager.setup();
crazyManager.load();
// methods.updateAuction();
} catch (Exception e) {
e.printStackTrace();
isEnabled = false;
return;
}
isEnabled = true;
enable();
}
@Override
public void onDisable() {
if (!isEnabled) return;
disable();
}
private void enable() {
}
private void disable() {
Files.DATA.saveFile();
}
public static CrazyAuctions getPlugin() {
return plugin;
}
public Starter getStarter() {
return starter;
}
}

View File

@ -0,0 +1,479 @@
package com.badbones69.crazyauctions;
import com.badbones69.crazyauctions.api.*;
import com.badbones69.crazyauctions.api.FileManager.Files;
import com.badbones69.crazyauctions.api.events.AuctionListEvent;
import com.badbones69.crazyauctions.controllers.DupePatch;
import com.badbones69.crazyauctions.controllers.GUI;
import com.badbones69.crazyauctions.currency.Vault;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.java.JavaPlugin;
import org.yaml.snakeyaml.error.YAMLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
public class Main extends JavaPlugin implements Listener {
public static FileManager fileManager = FileManager.getInstance();
public static CrazyAuctions crazyAuctions = CrazyAuctions.getInstance();
@Override
public void onEnable() {
fileManager.logInfo(true).setup(this);
crazyAuctions.loadCrazyAuctions();
Bukkit.getServer().getPluginManager().registerEvents(this, this);
Bukkit.getServer().getPluginManager().registerEvents(new GUI(), this);
Bukkit.getServer().getPluginManager().registerEvents(new DupePatch(), this);
Methods.updateAuction();
startCheck();
if (!Vault.setupEconomy()) { saveDefaultConfig(); }
Messages.addMissingMessages();
new Metrics(this, 4624); //Starts up bStats
}
@Override
public void onDisable() {
int file = 0;
Bukkit.getScheduler().cancelTask(file);
Files.DATA.saveFile(true);
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args) {
if (commandLable.equalsIgnoreCase("CrazyAuctions") || commandLable.equalsIgnoreCase("CrazyAuction") || commandLable.equalsIgnoreCase("CA") || commandLable.equalsIgnoreCase("AH") || commandLable.equalsIgnoreCase("HDV")) {
if (args.length == 0) {
if (!Methods.hasPermission(sender, "Access")) return true;
if (!(sender instanceof Player)) {
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage());
return true;
}
Player player = (Player) sender;
if (Files.CONFIG.getFile().contains("Settings.Category-Page-Opens-First")) {
if (Files.CONFIG.getFile().getBoolean("Settings.Category-Page-Opens-First")) {
GUI.openCategories(player, ShopType.SELL);
return true;
}
}
if (crazyAuctions.isSellingEnabled()) {
GUI.openShop(player, ShopType.SELL, Category.NONE, 1);
} else if (crazyAuctions.isBiddingEnabled()) {
GUI.openShop(player, ShopType.BID, Category.NONE, 1);
} else {
player.sendMessage(Methods.getPrefix() + Methods.color("&cThe bidding and selling options are both disabled. Please contact the admin about this."));
}
return true;
}
if (args.length >= 1) {
if (args[0].equalsIgnoreCase("Help")) {// CA Help
if (!Methods.hasPermission(sender, "Access")) return true;
sender.sendMessage(Messages.HELP.getMessage());
return true;
}
if (args[0].equalsIgnoreCase("test")) {// CA test [times]
if (!Methods.hasPermission(sender, "test")) return true;
int times = 1;
if (args.length >= 2) {
if (!Methods.isInt(args[1])) {
HashMap<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,117 +1,277 @@
package com.badbones69.crazyauctions;
import com.badbones69.crazyauctions.api.FileManager.Files;
import com.badbones69.crazyauctions.api.enums.Messages;
import com.badbones69.crazyauctions.utils.ItemBuilder;
import com.badbones69.crazyauctions.utils.func.ServerProtocol;
import net.md_5.bungee.api.chat.TextComponent;
import com.badbones69.crazyauctions.api.Messages;
import com.badbones69.crazyauctions.api.Version;
import com.badbones69.crazyauctions.api.events.AuctionExpireEvent;
import com.badbones69.crazyauctions.api.events.AuctionWinBidEvent;
import com.badbones69.crazyauctions.currency.CurrencyManager;
import org.bukkit.*;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@SuppressWarnings("deprecation")
public class Methods {
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
public final static Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F0-9]{6}");
public final Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F0-9]{6}");
public String color(String message) {
if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) {
public static String color(String message) {
if (Version.isNewer(Version.v1_15_R1)) {
Matcher matcher = HEX_PATTERN.matcher(message);
StringBuilder buffer = new StringBuilder();
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(buffer, net.md_5.bungee.api.ChatColor.of(matcher.group()).toString());
}
return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString());
}
return ChatColor.translateAlternateColorCodes('&', message);
}
public String getPrefix() {
public static String getPrefix() {
return color(Files.CONFIG.getFile().getString("Settings.Prefix", ""));
}
public String getPrefix(String msg) {
public static String getPrefix(String msg) {
return color(Files.CONFIG.getFile().getString("Settings.Prefix", "") + msg);
}
public String sanitizeColor(String msg) {
return sanitizeFormat(color(msg));
}
public String removeColor(String msg) {
public static String removeColor(String msg) {
return ChatColor.stripColor(msg);
}
public static String sanitizeFormat(String string) {
return TextComponent.toLegacyText(TextComponent.fromLegacyText(string));
}
public ItemStack makeItem(Material material, int amount, String name, List<String> lore, HashMap<Enchantment, Integer> enchants) {
ItemBuilder newItem = new ItemBuilder().setMaterial(material).setAmount(amount).setName(name).setLore(lore).setEnchantments(enchants);
return newItem.build();
}
public ItemStack getItemInHand(Player player) {
return player.getInventory().getItemInMainHand();
}
public void setItemInHand(Player player, ItemStack item) {
player.getInventory().setItemInMainHand(item);
}
public Player getPlayer(String name) {
public static ItemStack makeItem(String type, int amount) {
int ty = 0;
if (type.contains(":")) {
String[] b = type.split(":");
type = b[0];
ty = Integer.parseInt(b[1]);
}
Material m = Material.matchMaterial(type);
ItemStack item;
try {
return plugin.getServer().getPlayer(name);
item = new ItemStack(m, amount, (short) ty);
} catch (Exception e) {
if (Version.isNewer(Version.v1_12_R1)) {
item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1);
} else {
item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14);
}
}
return item;
}
public static ItemStack makeItem(String type, int amount, String name) {
int ty = 0;
if (type.contains(":")) {
String[] b = type.split(":");
type = b[0];
ty = Integer.parseInt(b[1]);
}
Material m = Material.matchMaterial(type);
ItemStack item;
try {
item = new ItemStack(m, amount, (short) ty);
} catch (Exception e) {
if (Version.isNewer(Version.v1_12_R1)) {
item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1);
} else {
item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14);
}
}
ItemMeta me = item.getItemMeta();
me.setDisplayName(color(name));
item.setItemMeta(me);
return item;
}
public static ItemStack makeItem(String type, int amount, String name, List<String> lore) {
ArrayList<String> l = new ArrayList<>();
int ty = 0;
if (type.contains(":")) {
String[] b = type.split(":");
type = b[0];
ty = Integer.parseInt(b[1]);
}
Material m = Material.matchMaterial(type);
ItemStack item;
try {
item = new ItemStack(m, amount, (short) ty);
} catch (Exception e) {
if (Version.isNewer(Version.v1_12_R1)) {
item = new ItemStack(Material.matchMaterial("RED_TERRACOTTA"), 1);
} else {
item = new ItemStack(Material.matchMaterial("STAINED_CLAY"), 1, (short) 14);
}
}
ItemMeta me = item.getItemMeta();
me.setDisplayName(color(name));
for (String L : lore)
l.add(color(L));
me.setLore(l);
item.setItemMeta(me);
return item;
}
public static ItemStack makeItem(Material material, int amount, int type, String name) {
ItemStack item = new ItemStack(material, amount, (short) type);
ItemMeta m = item.getItemMeta();
m.setDisplayName(color(name));
item.setItemMeta(m);
return item;
}
public static ItemStack makeItem(Material material, int amount, int type, String name, List<String> lore) {
ArrayList<String> l = new ArrayList<>();
ItemStack item = new ItemStack(material, amount, (short) type);
ItemMeta m = item.getItemMeta();
m.setDisplayName(color(name));
for (String L : lore)
l.add(color(L));
m.setLore(l);
item.setItemMeta(m);
return item;
}
public static ItemStack makeItem(Material material, int amount, int type, String name, List<String> lore, Map<Enchantment, Integer> enchants) {
ItemStack item = new ItemStack(material, amount, (short) type);
ItemMeta m = item.getItemMeta();
m.setDisplayName(name);
m.setLore(lore);
item.setItemMeta(m);
item.addUnsafeEnchantments(enchants);
return item;
}
public static ItemStack addLore(ItemStack item, String i) {
ArrayList<String> lore = new ArrayList<>();
ItemMeta m = item.getItemMeta();
if (item.getItemMeta().hasLore()) {
lore.addAll(item.getItemMeta().getLore());
}
lore.add(i);
m.setLore(lore);
item.setItemMeta(m);
return item;
}
public static ItemStack addLore(ItemStack item, List<String> list) {
if (item != null && item.getType() != Material.AIR) {
ArrayList<String> lore = new ArrayList<>();
ItemMeta m = item.getItemMeta();
if (item.hasItemMeta() && item.getItemMeta().hasLore()) {
lore.addAll(item.getItemMeta().getLore());
}
for (String i : list)
lore.add(color(i));
m.setLore(lore);
item.setItemMeta(m);
}
return item;
}
public static Integer getVersion() {
String ver = Bukkit.getServer().getClass().getPackage().getName();
ver = ver.substring(ver.lastIndexOf('.') + 1);
ver = ver.replace("_", "").replace("R", "").replace("v", "");
return Integer.parseInt(ver);
}
@SuppressWarnings("deprecation")
public static ItemStack getItemInHand(Player player) {
if (getVersion() >= 191) {
return player.getInventory().getItemInMainHand();
} else {
return player.getItemInHand();
}
}
@SuppressWarnings("deprecation")
public static void setItemInHand(Player player, ItemStack item) {
if (getVersion() >= 191) {
player.getInventory().setItemInMainHand(item);
} else {
player.setItemInHand(item);
}
}
public static boolean isInt(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
public static boolean isLong(String s) {
try {
Long.parseLong(s);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
public static Player getPlayer(String name) {
try {
return Bukkit.getServer().getPlayer(name);
} catch (Exception e) {
return null;
}
}
@SuppressWarnings("deprecation")
public OfflinePlayer getOfflinePlayer(String name) {
return plugin.getServer().getOfflinePlayer(name);
public static OfflinePlayer getOfflinePlayer(String name) {
return Bukkit.getServer().getOfflinePlayer(name);
}
public boolean isOnline(String name) {
for (Player player : plugin.getServer().getOnlinePlayers()) {
if (player.getName().equalsIgnoreCase(name)) return true;
public static Location getLoc(Player player) {
return player.getLocation();
}
public static void runCMD(Player player, String CMD) {
player.performCommand(CMD);
}
public static boolean isOnline(String name) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.getName().equalsIgnoreCase(name)) {
return true;
}
}
return false;
}
public boolean isOnline(String name, CommandSender commandSender) {
for (Player player : plugin.getServer().getOnlinePlayers()) {
if (player.getName().equalsIgnoreCase(name)) return true;
public static boolean isOnline(String name, CommandSender p) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.getName().equalsIgnoreCase(name)) {
return true;
}
}
commandSender.sendMessage(Messages.NOT_ONLINE.getMessage());
p.sendMessage(Messages.NOT_ONLINE.getMessage());
return false;
}
public boolean hasPermission(Player player, String perm) {
public static boolean hasPermission(Player player, String perm) {
if (!player.hasPermission("crazyauctions." + perm)) {
player.sendMessage(Messages.NO_PERMISSION.getMessage());
return false;
}
return true;
}
public boolean hasPermission(CommandSender sender, String perm) {
public static boolean hasPermission(CommandSender sender, String perm) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.hasPermission("crazyauctions." + perm)) {
player.sendMessage(Messages.NO_PERMISSION.getMessage());
return false;
@ -123,7 +283,171 @@ public class Methods {
}
}
public boolean isInvFull(Player player) {
public static List<ItemStack> getPage(List<ItemStack> list, Integer page) {
List<ItemStack> items = new ArrayList<>();
if (page <= 0) page = 1;
int max = 45;
int index = page * max - max;
int endIndex = index >= list.size() ? list.size() - 1 : index + max;
for (; index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
for (; items.size() == 0; page--) {
if (page <= 0) break;
index = page * max - max;
endIndex = index >= list.size() ? list.size() - 1 : index + max;
for (; index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
}
return items;
}
public static List<Integer> getPageInts(List<Integer> list, Integer page) {
List<Integer> items = new ArrayList<>();
if (page <= 0) page = 1;
int max = 45;
int index = page * max - max;
int endIndex = index >= list.size() ? list.size() - 1 : index + max;
for (; index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
for (; items.size() == 0; page--) {
if (page <= 0) break;
index = page * max - max;
endIndex = index >= list.size() ? list.size() - 1 : index + max;
for (; index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
}
return items;
}
public static int getMaxPage(List<ItemStack> list) {
int maxPage = 1;
int amount = list.size();
for (; amount > 45; amount -= 45, maxPage++) ;
return maxPage;
}
public static String convertToTime(long time) {
Calendar C = Calendar.getInstance();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(time);
int total = ((int) (cal.getTimeInMillis() / 1000) - (int) (C.getTimeInMillis() / 1000));
int D = 0;
int H = 0;
int M = 0;
int S = 0;
for (; total > 86400; total -= 86400, D++) ;
for (; total > 3600; total -= 3600, H++) ;
for (; total > 60; total -= 60, M++) ;
S += total;
return D + "d " + H + "h " + M + "m " + S + "s ";
}
public static long convertToMill(String time) {
Calendar cal = Calendar.getInstance();
for (String i : time.split(" ")) {
if (i.contains("D") || i.contains("d")) {
cal.add(Calendar.DATE, Integer.parseInt(i.replace("D", "").replace("d", "")));
}
if (i.contains("H") || i.contains("h")) {
cal.add(Calendar.HOUR, Integer.parseInt(i.replace("H", "").replace("h", "")));
}
if (i.contains("M") || i.contains("m")) {
cal.add(Calendar.MINUTE, Integer.parseInt(i.replace("M", "").replace("m", "")));
}
if (i.contains("S") || i.contains("s")) {
cal.add(Calendar.SECOND, Integer.parseInt(i.replace("S", "").replace("s", "")));
}
}
return cal.getTimeInMillis();
}
public static boolean isInvFull(Player player) {
return player.getInventory().firstEmpty() == -1;
}
public static void updateAuction() {
FileConfiguration data = Files.DATA.getFile();
Calendar cal = Calendar.getInstance();
Calendar expireTime = Calendar.getInstance();
Calendar fullExpireTime = Calendar.getInstance();
boolean shouldSave = false;
if (data.contains("OutOfTime/Cancelled")) {
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
fullExpireTime.setTimeInMillis(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time"));
if (cal.after(fullExpireTime)) {
data.set("OutOfTime/Cancelled." + i, null);
shouldSave = true;
}
}
}
if (data.contains("Items")) {
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
expireTime.setTimeInMillis(data.getLong("Items." + i + ".Time-Till-Expire"));
fullExpireTime.setTimeInMillis(data.getLong("Items." + i + ".Full-Time"));
if (cal.after(expireTime)) {
int num = 1;
for (; data.contains("OutOfTime/Cancelled." + num); num++) ;
if (data.getBoolean("Items." + i + ".Biddable") && !data.getString("Items." + i + ".TopBidder").equalsIgnoreCase("None") && CurrencyManager.getMoney(getPlayer(data.getString("Items." + i + ".TopBidder"))) >= data.getInt("Items." + i + ".Price")) {
String winner = data.getString("Items." + i + ".TopBidder");
String seller = data.getString("Items." + i + ".Seller");
Long price = data.getLong("Items." + i + ".Price");
CurrencyManager.addMoney(getOfflinePlayer(seller), price);
CurrencyManager.removeMoney(getOfflinePlayer(winner), price);
HashMap<String, String> placeholders = new HashMap<>();
placeholders.put("%Price%", getPrice(i, false));
placeholders.put("%price%", getPrice(i, false));
placeholders.put("%Player%", winner);
placeholders.put("%player%", winner);
if (isOnline(winner) && getPlayer(winner) != null) {
Player player = getPlayer(winner);
Bukkit.getPluginManager().callEvent(new AuctionWinBidEvent(player, data.getItemStack("Items." + i + ".Item"), price));
player.sendMessage(Messages.WIN_BIDDING.getMessage(placeholders));
}
if (isOnline(seller) && getPlayer(seller) != null) {
Player player = getPlayer(seller);
player.sendMessage(Messages.SOMEONE_WON_PLAYERS_BID.getMessage(placeholders));
}
data.set("OutOfTime/Cancelled." + num + ".Seller", winner);
data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis());
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item"));
} else {
String seller = data.getString("Items." + i + ".Seller");
Player player = getPlayer(seller);
if (isOnline(seller) && getPlayer(seller) != null) {
player.sendMessage(Messages.ITEM_HAS_EXPIRED.getMessage());
}
AuctionExpireEvent event = new AuctionExpireEvent(player, data.getItemStack("Items." + i + ".Item"));
Bukkit.getPluginManager().callEvent(event);
data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller"));
data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis());
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item"));
}
data.set("Items." + i, null);
shouldSave = true;
}
}
}
if (shouldSave) Files.DATA.saveFile();
}
public static String getPrice(String ID, Boolean Expired) {
long price = 0L;
if (Expired) {
if (Files.DATA.getFile().contains("OutOfTime/Cancelled." + ID + ".Price")) {
price = Files.DATA.getFile().getLong("OutOfTime/Cancelled." + ID + ".Price");
}
} else {
if (Files.DATA.getFile().contains("Items." + ID + ".Price")) {
price = Files.DATA.getFile().getLong("Items." + ID + ".Price");
}
}
return String.valueOf(price);
}
}

View File

@ -1,50 +0,0 @@
package com.badbones69.crazyauctions;
import com.badbones69.crazyauctions.api.CrazyManager;
import com.badbones69.crazyauctions.api.FileManager;
import com.badbones69.crazyauctions.api.economy.vault.VaultSupport;
import com.badbones69.crazyauctions.utils.SkullCreator;
public class Starter {
private FileManager fileManager;
private CrazyManager crazyManager;
private VaultSupport vaultSupport;
private Methods methods;
private SkullCreator skullCreator;
public void run() {
fileManager = new FileManager();
crazyManager = new CrazyManager();
vaultSupport = new VaultSupport();
methods = new Methods();
skullCreator = new SkullCreator();
}
public FileManager getFileManager() {
return fileManager;
}
public CrazyManager getCrazyManager() {
return crazyManager;
}
public VaultSupport getVaultSupport() {
return vaultSupport;
}
public Methods getMethods() {
return methods;
}
public SkullCreator getSkullCreator() {
return skullCreator;
}
}

View File

@ -1,11 +1,11 @@
package com.badbones69.crazyauctions.api.enums;
package com.badbones69.crazyauctions.api;
import com.badbones69.crazyauctions.utils.func.ServerProtocol;
import org.bukkit.Material;
import java.util.ArrayList;
public enum AuctionCategories {
public enum Category {
NONE("None", new ArrayList<>()),
OTHER("Other", getOthers()),
ARMOR("Armor", getArmor()),
@ -14,194 +14,192 @@ public enum AuctionCategories {
FOOD("Food", getFood()),
POTIONS("Potions", getPotions()),
BLOCKS("Blocks", getBlocks());
private final String name;
private final ArrayList<Material> items;
/**
* @param name Name of the Shop Type.
*/
AuctionCategories(String name, ArrayList<Material> items) {
private Category(String name, ArrayList<Material> items) {
this.name = name;
this.items = items;
}
/**
* @param name Name of the Type you want.
* @return Returns the Type as an Enum.
*/
public static AuctionCategories getFromName(String name) {
for (AuctionCategories type : AuctionCategories.values()) {
if (type.getName().equalsIgnoreCase(name)) return type;
public static Category getFromName(String name) {
for (Category type : Category.values()) {
if (type.getName().equalsIgnoreCase(name)) {
return type;
}
}
return null;
}
private static ArrayList<Material> getArmor() {
ArrayList<Material> ma = new ArrayList<>();
ma.add(Material.LEATHER_HELMET);
ma.add(Material.LEATHER_CHESTPLATE);
ma.add(Material.LEATHER_LEGGINGS);
ma.add(Material.LEATHER_BOOTS);
ma.add(Material.GOLDEN_HELMET);
ma.add(Material.GOLDEN_CHESTPLATE);
ma.add(Material.GOLDEN_LEGGINGS);
ma.add(Material.GOLDEN_BOOTS);
ma.add(Material.CHAINMAIL_HELMET);
ma.add(Material.CHAINMAIL_CHESTPLATE);
ma.add(Material.CHAINMAIL_LEGGINGS);
ma.add(Material.CHAINMAIL_BOOTS);
ma.add(Material.IRON_HELMET);
ma.add(Material.IRON_CHESTPLATE);
ma.add(Material.IRON_LEGGINGS);
ma.add(Material.IRON_BOOTS);
if (Version.isNewer(Version.v1_12_R1)) {
ma.add(Material.matchMaterial("GOLDEN_HELMET"));
ma.add(Material.matchMaterial("GOLDEN_CHESTPLATE"));
ma.add(Material.matchMaterial("GOLDEN_LEGGINGS"));
ma.add(Material.matchMaterial("GOLDEN_BOOTS"));
} else {
ma.add(Material.matchMaterial("GOLD_HELMET"));
ma.add(Material.matchMaterial("GOLD_CHESTPLATE"));
ma.add(Material.matchMaterial("GOLD_LEGGINGS"));
ma.add(Material.matchMaterial("GOLD_BOOTS"));
}
ma.add(Material.DIAMOND_HELMET);
ma.add(Material.DIAMOND_CHESTPLATE);
ma.add(Material.DIAMOND_LEGGINGS);
ma.add(Material.DIAMOND_BOOTS);
ma.add(Material.TURTLE_HELMET);
if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) {
ma.add(Material.CHAINMAIL_HELMET);
ma.add(Material.CHAINMAIL_CHESTPLATE);
ma.add(Material.CHAINMAIL_LEGGINGS);
ma.add(Material.CHAINMAIL_BOOTS);
ma.add(Material.IRON_HELMET);
ma.add(Material.IRON_CHESTPLATE);
ma.add(Material.IRON_LEGGINGS);
ma.add(Material.IRON_BOOTS);
ma.add(Material.DIAMOND_HELMET);
ma.add(Material.DIAMOND_CHESTPLATE);
ma.add(Material.DIAMOND_LEGGINGS);
ma.add(Material.DIAMOND_BOOTS);
if (Version.isNewer(Version.v1_15_R1)) {
ma.add(Material.NETHERITE_HELMET);
ma.add(Material.NETHERITE_CHESTPLATE);
ma.add(Material.NETHERITE_LEGGINGS);
ma.add(Material.NETHERITE_BOOTS);
}
return ma;
}
private static ArrayList<Material> getTools() {
ArrayList<Material> ma = new ArrayList<>();
ma.add(Material.WOODEN_PICKAXE);
ma.add(Material.WOODEN_AXE);
ma.add(Material.WOODEN_SHOVEL);
ma.add(Material.WOODEN_HOE);
if (Version.isNewer(Version.v1_12_R1)) {
ma.add(Material.matchMaterial("WOODEN_PICKAXE"));
ma.add(Material.matchMaterial("WOODEN_AXE"));
ma.add(Material.matchMaterial("WOODEN_SHOVEL"));
ma.add(Material.matchMaterial("WOODEN_HOE"));
ma.add(Material.matchMaterial("GOLDEN_PICKAXE"));
ma.add(Material.matchMaterial("GOLDEN_AXE"));
ma.add(Material.matchMaterial("GOLDEN_SHOVEL"));
ma.add(Material.matchMaterial("GOLDEN_HOE"));
ma.add(Material.matchMaterial("STONE_SHOVEL"));
ma.add(Material.matchMaterial("IRON_SHOVEL"));
ma.add(Material.matchMaterial("DIAMOND_SHOVEL"));
} else {
ma.add(Material.matchMaterial("WOOD_PICKAXE"));
ma.add(Material.matchMaterial("WOOD_AXE"));
ma.add(Material.matchMaterial("WOOD_SPADE"));
ma.add(Material.matchMaterial("WOOD_HOE"));
ma.add(Material.matchMaterial("GOLD_PICKAXE"));
ma.add(Material.matchMaterial("GOLD_AXE"));
ma.add(Material.matchMaterial("GOLD_SPADE"));
ma.add(Material.matchMaterial("GOLD_HOE"));
ma.add(Material.matchMaterial("STONE_SPADE"));
ma.add(Material.matchMaterial("IRON_SPADE"));
ma.add(Material.matchMaterial("DIAMOND_SPADE"));
}
ma.add(Material.STONE_PICKAXE);
ma.add(Material.STONE_AXE);
ma.add(Material.STONE_SHOVEL);
ma.add(Material.STONE_HOE);
ma.add(Material.GOLDEN_PICKAXE);
ma.add(Material.GOLDEN_AXE);
ma.add(Material.GOLDEN_SHOVEL);
ma.add(Material.GOLDEN_HOE);
ma.add(Material.IRON_PICKAXE);
ma.add(Material.IRON_AXE);
ma.add(Material.IRON_SHOVEL);
ma.add(Material.IRON_HOE);
ma.add(Material.DIAMOND_PICKAXE);
ma.add(Material.STONE_AXE);
ma.add(Material.IRON_AXE);
ma.add(Material.DIAMOND_AXE);
ma.add(Material.DIAMOND_SHOVEL);
ma.add(Material.STONE_HOE);
ma.add(Material.IRON_HOE);
ma.add(Material.DIAMOND_HOE);
ma.add(Material.SHEARS);
ma.add(Material.FISHING_ROD);
ma.add(Material.FLINT_AND_STEEL);
ma.add(Material.SPYGLASS);
if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) {
if (Version.isNewer(Version.v1_15_R1)) {
ma.add(Material.NETHERITE_PICKAXE);
ma.add(Material.NETHERITE_AXE);
ma.add(Material.NETHERITE_HOE);
ma.add(Material.NETHERITE_SHOVEL);
}
return ma;
}
private static ArrayList<Material> getWeapons() {
ArrayList<Material> ma = new ArrayList<>();
ma.add(Material.WOODEN_SWORD);
ma.add(Material.WOODEN_AXE);
if (Version.isNewer(Version.v1_12_R1)) {
ma.add(Material.matchMaterial("WOODEN_SWORD"));
ma.add(Material.matchMaterial("WOODEN_AXE"));
ma.add(Material.matchMaterial("GOLDEN_SWORD"));
ma.add(Material.matchMaterial("GOLDEN_AXE"));
} else {
ma.add(Material.matchMaterial("WOOD_SWORD"));
ma.add(Material.matchMaterial("WOOD_AXE"));
ma.add(Material.matchMaterial("GOLD_SWORD"));
ma.add(Material.matchMaterial("GOLD_AXE"));
}
ma.add(Material.STONE_SWORD);
ma.add(Material.STONE_AXE);
ma.add(Material.GOLDEN_SWORD);
ma.add(Material.GOLDEN_AXE);
ma.add(Material.IRON_SWORD);
ma.add(Material.IRON_AXE);
ma.add(Material.DIAMOND_SWORD);
ma.add(Material.STONE_AXE);
ma.add(Material.IRON_AXE);
ma.add(Material.DIAMOND_AXE);
ma.add(Material.BOW);
ma.add(Material.CROSSBOW);
ma.add(Material.TRIDENT);
if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) {
if (Version.isNewer(Version.v1_15_R1)) {
ma.add(Material.NETHERITE_SWORD);
ma.add(Material.NETHERITE_AXE);
}
return ma;
}
private static ArrayList<Material> getFood() {
ArrayList<Material> ma = new ArrayList<>();
for (Material m : Material.values()) {
if (m.isEdible()) {
if (m != Material.POTION) ma.add(m);
}
}
return ma;
}
private static ArrayList<Material> getPotions() {
ArrayList<Material> ma = new ArrayList<>();
ma.add(Material.POTION);
if (Material.matchMaterial("SPLASH_POTION") != null) ma.add(Material.matchMaterial("SPLASH_POTION"));
if (Material.matchMaterial("LINGERING_POTION") != null) ma.add(Material.matchMaterial("LINGERING_POTION"));
if (Material.matchMaterial("SPLASH_POTION") != null) {
ma.add(Material.matchMaterial("SPLASH_POTION"));
}
if (Material.matchMaterial("LINGERING_POTION") != null) {
ma.add(Material.matchMaterial("LINGERING_POTION"));
}
return ma;
}
private static ArrayList<Material> getBlocks() {
ArrayList<Material> ma = new ArrayList<>();
for (Material m : Material.values()) {
if (m.isBlock()) ma.add(m);
if (m.isBlock()) {
ma.add(m);
}
}
return ma;
}
private static ArrayList<Material> getOthers() {
ArrayList<Material> ma = new ArrayList<>();
for (Material m : Material.values()) {
if (!(getArmor().contains(m) || getTools().contains(m) || getWeapons().contains(m) || getFood().contains(m) || getPotions().contains(m) || getBlocks().contains(m))) ma.add(m);
if (!(getArmor().contains(m) || getTools().contains(m) || getWeapons().contains(m) || getFood().contains(m) || getPotions().contains(m) || getBlocks().contains(m))) {
ma.add(m);
}
}
return ma;
}
/**
* @return Returns the type name as a string.
*/
public String getName() {
return name;
}
public ArrayList<Material> getItems() {
return items;
}
}

View File

@ -1,24 +1,29 @@
package com.badbones69.crazyauctions.api;
import com.badbones69.crazyauctions.api.FileManager.Files;
import com.badbones69.crazyauctions.api.enums.ShopCategories;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
public class CrazyManager {
public class CrazyAuctions {
private static CrazyAuctions instance = new CrazyAuctions();
private FileManager fileManager = FileManager.getInstance();
private Boolean sellingEnabled;
private Boolean biddingEnabled;
public void load() {
public static CrazyAuctions getInstance() {
return instance;
}
public void loadCrazyAuctions() {
if (Files.CONFIG.getFile().contains("Settings.Feature-Toggle.Selling")) {
this.sellingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Selling");
} else {
this.sellingEnabled = true;
}
if (Files.CONFIG.getFile().contains("Settings.Feature-Toggle.Bidding")) {
this.biddingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Bidding");
} else {
@ -37,32 +42,35 @@ public class CrazyManager {
public ArrayList<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());
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, ShopCategories type) {
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 == ShopCategories.BID) items.add(data.getItemStack("Items." + i + ".Item").clone());
if (type == ShopType.BID) {
items.add(data.getItemStack("Items." + i + ".Item").clone());
}
} else {
if (type == ShopCategories.SELL) items.add(data.getItemStack("Items." + i + ".Item").clone());
if (type == ShopType.SELL) {
items.add(data.getItemStack("Items." + i + ".Item").clone());
}
}
}
}
}
return items;
}
}

View File

@ -1,8 +1,11 @@
package com.badbones69.crazyauctions.api;
import com.badbones69.crazyauctions.CrazyAuctions;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -11,107 +14,110 @@ import java.util.ArrayList;
import java.util.HashMap;
/**
*
* @author BadBones69
* @version v1.0
*
*/
public class FileManager {
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private static FileManager instance = new FileManager();
private Plugin plugin;
private String prefix = "";
private Boolean log = false;
private HashMap<Files, 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<>();
private boolean log = false;
private final HashMap<Files, File> files = new HashMap<>();
private final ArrayList<String> homeFolders = new ArrayList<>();
private final ArrayList<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<>();
public static FileManager getInstance() {
return instance;
}
/**
* Loads all necessary files.
* Sets up the plugin and loads all necessary files.
* @param plugin The plugin this is getting loading for.
*/
public FileManager setup() {
if (!plugin.getDataFolder().exists()) plugin.getDataFolder().mkdirs();
public FileManager setup(Plugin plugin) {
prefix = "[" + plugin.getName() + "] ";
this.plugin = plugin;
if (!plugin.getDataFolder().exists()) {
plugin.getDataFolder().mkdirs();
}
files.clear();
customFiles.clear();
// Loads all the normal static files.
//Loads all the normal static files.
for (Files file : Files.values()) {
File newFile = new File(plugin.getDataFolder(), file.getFileLocation());
if (isLogging()) plugin.getLogger().info("Loading the " + file.getFileName());
if (log) Bukkit.getLogger().info("Loading the " + file.getFileName());
if (!newFile.exists()) {
try {
String fileLocation = file.getFileLocation();
//Switch between 1.12.2- and 1.13+ config version.
if (file == Files.CONFIG) {
if (Version.isOlder(Version.v1_13_R2)) {
fileLocation = "config1.12.2-Down.yml";
} else {
fileLocation = "config1.13-Up.yml";
}
}
File serverFile = new File(plugin.getDataFolder(), "/" + file.getFileLocation());
InputStream jarFile = getClass().getResourceAsStream("/" + file.getFileJar());
InputStream jarFile = getClass().getResourceAsStream("/" + fileLocation);
copyFile(jarFile, serverFile);
} catch (Exception e) {
if (isLogging()) plugin.getLogger().info("Failed to load " + file.getFileName());
if (log) Bukkit.getLogger().info("Failed to load " + file.getFileName());
e.printStackTrace();
continue;
}
}
files.put(file, newFile);
configurations.put(file, YamlConfiguration.loadConfiguration(newFile));
if (isLogging()) plugin.getLogger().info("Successfully loaded " + file.getFileName());
if (log) Bukkit.getLogger().info("Successfully loaded " + file.getFileName());
}
// Starts to load all the custom files.
//Starts to load all the custom files.
if (homeFolders.size() > 0) {
if (isLogging()) plugin.getLogger().info("Loading custom files.");
if (log) Bukkit.getLogger().info("Loading custom files.");
for (String homeFolder : homeFolders) {
File homeFile = new File(plugin.getDataFolder(), "/" + homeFolder);
if (homeFile.exists()) {
String[] list = homeFile.list();
if (list != null) {
for (String name : list) {
if (name.endsWith(".yml")) {
CustomFile file = new CustomFile(name, homeFolder);
CustomFile file = new CustomFile(name, homeFolder, plugin);
if (file.exists()) {
customFiles.add(file);
if (isLogging()) plugin.getLogger().info("Loaded new custom file: " + homeFolder + "/" + name + ".");
if (log) Bukkit.getLogger().info("Loaded new custom file: " + homeFolder + "/" + name + ".");
}
}
}
}
} else {
homeFile.mkdir();
if (isLogging()) plugin.getLogger().info("The folder " + homeFolder + "/ was not found so it was created.");
if (log) Bukkit.getLogger().info("The folder " + homeFolder + "/ was not found so it was created.");
for (String fileName : autoGenerateFiles.keySet()) {
if (autoGenerateFiles.get(fileName).equalsIgnoreCase(homeFolder)) {
homeFolder = autoGenerateFiles.get(fileName);
try {
File serverFile = new File(plugin.getDataFolder(), homeFolder + "/" + fileName);
InputStream jarFile = getClass().getResourceAsStream(homeFolder + "/" + fileName);
copyFile(jarFile, serverFile);
if (fileName.toLowerCase().endsWith(".yml")) customFiles.add(new CustomFile(fileName, homeFolder));
if (isLogging()) plugin.getLogger().info("Created new default file: " + homeFolder + "/" + fileName + ".");
if (fileName.toLowerCase().endsWith(".yml")) {
customFiles.add(new CustomFile(fileName, homeFolder, plugin));
}
if (log) Bukkit.getLogger().info("Created new default file: " + homeFolder + "/" + fileName + ".");
} catch (Exception e) {
if (isLogging()) plugin.getLogger().info("Failed to create new default file: " + homeFolder + "/" + fileName + "!");
if (log) Bukkit.getLogger().info("Failed to create new default file: " + homeFolder + "/" + fileName + "!");
e.printStackTrace();
}
}
}
}
}
if (isLogging()) plugin.getLogger().info("Finished loading custom files.");
if (log) Bukkit.getLogger().info("Finished loading custom files.");
}
return this;
}
@ -119,7 +125,7 @@ public class FileManager {
* Turn on the logger system for the FileManager.
* @param log True to turn it on and false for it to be off.
*/
public FileManager setLog(boolean log) {
public FileManager logInfo(Boolean log) {
this.log = log;
return this;
}
@ -128,7 +134,7 @@ public class FileManager {
* Check if the logger is logging in console.
* @return True if it is and false if it isn't.
*/
public boolean isLogging() {
public Boolean isLogging() {
return log;
}
@ -185,21 +191,42 @@ public class FileManager {
*/
public CustomFile getFile(String name) {
for (CustomFile file : customFiles) {
if (file.getName().equalsIgnoreCase(name)) return file;
if (file.getName().equalsIgnoreCase(name)) {
return file;
}
}
return null;
}
/**
* Saves the file from the loaded state to the file system.
*/
public void saveFile(Files file) {
public void saveFile(Files file, boolean sync) {
try {
configurations.get(file).save(files.get(file));
} catch (IOException e) {
plugin.getLogger().warning("Could not save " + file.getFileName() + "!");
File targetFile = files.get(file);
FileConfiguration configuration = configurations.get(file);
YamlConfiguration copy = new YamlConfiguration();
configuration.getValues(false).forEach(copy :: set);
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
try {
copy.save(targetFile);
} catch (IOException e) {
Bukkit.getLogger().info("Could not save " + file.getFileName() + "!");
e.printStackTrace();
}
}
};
if (sync) {
runnable.run();
} else {
runnable.runTaskAsynchronously(plugin);
}
} catch (NullPointerException e) {
Bukkit.getLogger().info("File is null " + file.getFileName() + "!");
e.printStackTrace();
}
}
@ -210,18 +237,16 @@ public class FileManager {
*/
public void saveFile(String name) {
CustomFile file = getFile(name);
if (file != null) {
try {
file.getFile().save(new File(plugin.getDataFolder(), file.getHomeFolder() + "/" + file.getFileName()));
if (isLogging()) plugin.getLogger().info("Successfully saved the " + file.getFileName() + ".");
if (log) Bukkit.getLogger().info("Successfuly saved the " + file.getFileName() + ".");
} catch (Exception e) {
plugin.getLogger().warning("Could not save " + file.getFileName() + "!");
Bukkit.getLogger().info("Could not save " + file.getFileName() + "!");
e.printStackTrace();
}
} else {
if (isLogging()) plugin.getLogger().warning("The file " + name + ".yml could not be found!");
if (log) Bukkit.getLogger().info("The file " + name + ".yml could not be found!");
}
}
@ -230,7 +255,7 @@ public class FileManager {
* @param file The custom file you are saving.
* @return True if the file saved correct and false if there was an error.
*/
public boolean saveFile(CustomFile file) {
public Boolean saveFile(CustomFile file) {
return file.saveFile();
}
@ -246,18 +271,16 @@ public class FileManager {
*/
public void reloadFile(String name) {
CustomFile file = getFile(name);
if (file != null) {
try {
file.file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + file.getHomeFolder() + "/" + file.getFileName()));
if (isLogging()) plugin.getLogger().info("Successfully reloaded the " + file.getFileName() + ".");
if (log) Bukkit.getLogger().info("Successfuly reload the " + file.getFileName() + ".");
} catch (Exception e) {
plugin.getLogger().warning("Could not reload the " + file.getFileName() + "!");
Bukkit.getLogger().info("Could not reload the " + file.getFileName() + "!");
e.printStackTrace();
}
} else {
if (isLogging()) plugin.getLogger().warning("The file " + name + ".yml could not be found!");
if (log) Bukkit.getLogger().info("The file " + name + ".yml could not be found!");
}
}
@ -265,70 +288,47 @@ public class FileManager {
* Overrides the loaded state file and loads the filesystems file.
* @return True if it reloaded correct and false if the file wasn't found.
*/
public boolean reloadFile(CustomFile file) {
public Boolean reloadFile(CustomFile file) {
return file.reloadFile();
}
/**
* Was found here: <a href="https://bukkit.org/threads/extracting-file-from-jar.16962">...</a>
* Was found here: https://bukkit.org/threads/extracting-file-from-jar.16962
*/
private void copyFile(InputStream in, File out) throws Exception {
try (InputStream fis = in; FileOutputStream fos = new FileOutputStream(out)) {
try (FileOutputStream fos = new FileOutputStream(out)) {
byte[] buf = new byte[1024];
int i;
while ((i = fis.read(buf)) != -1) {
while ((i = in.read(buf)) != -1) {
fos.write(buf, 0, i);
}
}
}
public void reloadAllFiles() {
for (Files file : Files.values()) {
file.reloadFile();
}
for (CustomFile file : customFiles) {
file.reloadFile();
} finally {
if (in != null) {
in.close();
}
}
}
public enum Files {
// ENUM_NAME("fileName.yml", "fileLocation.yml"),
// ENUM_NAME("fileName.yml", "newFileLocation.yml", "oldFileLocation.yml"),
//ENUM_NAME("FileName.yml", "FilePath.yml"),
CONFIG("config.yml", "config.yml"),
DATA("data.yml", "data.yml"),
MESSAGES("messages.yml", "messages.yml"),
TEST_FILE("test-file.yml", "test-file.yml");
DATA("Data.yml", "Data.yml"),
MESSAGES("Messages.yml", "Messages.yml"),
TEST_FILE("Test-File.yml", "Test-File.yml");
private final String fileName;
private final String fileJar;
private final String fileLocation;
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private final FileManager fileManager = plugin.getStarter().getFileManager();
/**
* The files that the server will try and load.
* @param fileName The file name that will be in the plugin's folder.
* @param fileLocation The location the file in the plugin's folder.
* @param fileLocation The location the file is in while in the Jar.
*/
Files(String fileName, String fileLocation) {
this(fileName, fileLocation, fileLocation);
}
/**
* The files that the server will try and load.
* @param fileName The file name that will be in the plugin's folder.
* @param fileLocation The location of the file will be in the plugin's folder.
* @param fileJar The location of the file in the jar.
*/
Files(String fileName, String fileLocation, String fileJar) {
private Files(String fileName, String fileLocation) {
this.fileName = fileName;
this.fileLocation = fileLocation;
this.fileJar = fileJar;
}
/**
@ -346,57 +346,54 @@ public class FileManager {
public String getFileLocation() {
return fileLocation;
}
/**
* Get the location of the file in the jar.
* @return The location of the file in the jar.
*/
public String getFileJar() {
return fileJar;
}
/**
* Gets the file from the system.
* @return The file from the system.
*/
public FileConfiguration getFile() {
return fileManager.getFile(this);
return getInstance().getFile(this);
}
/**
* Saves the file from the loaded state to the file system.
*/
public void saveFile(boolean sync) {
getInstance().saveFile(this, sync);
}
public void saveFile() {
fileManager.saveFile(this);
getInstance().saveFile(this, false);
}
/**
* Overrides the loaded state file and loads the file systems file.
*/
public void reloadFile() {
fileManager.reloadFile(this);
public void relaodFile() {
getInstance().reloadFile(this);
}
}
public class CustomFile {
private final String name;
private final String fileName;
private final String homeFolder;
private String name;
private Plugin plugin;
private String fileName;
private String homeFolder;
private FileConfiguration file;
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
/**
* A custom file that is being made.
* @param name Name of the file.
* @param homeFolder The home folder of the file.
* @param plugin The plugin the files belong to.
*/
public CustomFile(String name, String homeFolder) {
public CustomFile(String name, String homeFolder, Plugin plugin) {
this.name = name.replace(".yml", "");
this.plugin = plugin;
this.fileName = name;
this.homeFolder = homeFolder;
if (new File(plugin.getDataFolder(), "/" + homeFolder).exists()) {
if (new File(plugin.getDataFolder(), "/" + homeFolder + "/" + name).exists()) {
file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + homeFolder + "/" + name));
@ -405,13 +402,11 @@ public class FileManager {
}
} else {
new File(plugin.getDataFolder(), "/" + homeFolder).mkdir();
if (isLogging()) plugin.getLogger().info("The folder " + homeFolder + "/ was not found so it was created.");
if (log) Bukkit.getLogger().info("The folder " + homeFolder + "/ was not found so it was created.");
file = null;
}
}
/**
* Get the name of the file without the .yml part.
* @return The name of the file without the .yml.
@ -419,7 +414,7 @@ public class FileManager {
public String getName() {
return name;
}
/**
* Get the full name of the file.
* @return Full name of the file.
@ -427,7 +422,7 @@ public class FileManager {
public String getFileName() {
return fileName;
}
/**
* Get the name of the home folder of the file.
* @return The name of the home folder the files are in.
@ -435,7 +430,15 @@ public class FileManager {
public String getHomeFolder() {
return homeFolder;
}
/**
* Get the plugin the file belongs to.
* @return The plugin the file belongs to.
*/
public Plugin getPlugin() {
return plugin;
}
/**
* Get the ConfigurationFile.
* @return The ConfigurationFile of this file.
@ -443,7 +446,7 @@ public class FileManager {
public FileConfiguration getFile() {
return file;
}
/**
* Check if the file actually exists in the file system.
* @return True if it does and false if it doesn't.
@ -451,7 +454,7 @@ public class FileManager {
public Boolean exists() {
return file != null;
}
/**
* Save the custom file.
* @return True if it saved correct and false if something went wrong.
@ -460,43 +463,39 @@ public class FileManager {
if (file != null) {
try {
file.save(new File(plugin.getDataFolder(), homeFolder + "/" + fileName));
if (isLogging()) plugin.getLogger().info("Successfully saved the " + fileName + ".");
if (log) Bukkit.getLogger().info("Successfuly saved the " + fileName + ".");
return true;
} catch (Exception e) {
plugin.getLogger().warning("Could not save " + fileName + "!");
Bukkit.getLogger().info("Could not save " + fileName + "!");
e.printStackTrace();
return false;
}
} else {
if (isLogging()) plugin.getLogger().warning("There was a null custom file that could not be found!");
if (log) Bukkit.getLogger().info("There was a null custom file that could not be found!");
}
return false;
}
/**
* Overrides the loaded state file and loads the filesystems file.
* @return True if it reloaded correct and false if the file wasn't found or error.
* @return True if it reloaded correct and false if the file wasn't found or errored.
*/
public Boolean reloadFile() {
if (file != null) {
try {
file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + homeFolder + "/" + fileName));
if (isLogging()) plugin.getLogger().info("Successfully reloaded the " + fileName + ".");
if (log) Bukkit.getLogger().info("Successfuly reload the " + fileName + ".");
return true;
} catch (Exception e) {
plugin.getLogger().warning("Could not reload the " + fileName + "!");
Bukkit.getLogger().info("Could not reload the " + fileName + "!");
e.printStackTrace();
}
} else {
if (isLogging()) plugin.getLogger().warning("There was a null custom file that was not found!");
if (log) Bukkit.getLogger().info("There was a null custom file that was not found!");
}
return false;
}
}
}

View File

@ -1,8 +1,6 @@
package com.badbones69.crazyauctions.api.enums;
package com.badbones69.crazyauctions.api;
import com.badbones69.crazyauctions.CrazyAuctions;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.FileManager;
import com.badbones69.crazyauctions.api.FileManager.Files;
import org.bukkit.configuration.file.FileConfiguration;
@ -56,54 +54,47 @@ public enum Messages {
"&9/Ah Expired/Collect - &eView and manage your cancelled and expired items.",
"&9/Ah Listed - &eView and manage the items you are selling.",
"&9/Ah Help - &eView this help menu."));
private static final FileManager fileManager = FileManager.getInstance();
private final String path;
private String defaultMessage;
private List<String> defaultListMessage;
private static final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private static final Methods methods = plugin.getStarter().getMethods();
Messages(String path, String defaultMessage) {
private Messages(String path, String defaultMessage) {
this.path = path;
this.defaultMessage = defaultMessage;
}
Messages(String path, List<String> defaultListMessage) {
private Messages(String path, List<String> defaultListMessage) {
this.path = path;
this.defaultListMessage = defaultListMessage;
}
public static String convertList(List<String> list) {
StringBuilder message = new StringBuilder();
String message = "";
for (String m : list) {
message.append(methods.color(m)).append("\n");
message += Methods.color(m) + "\n";
}
return message.toString();
return message;
}
public static String convertList(List<String> list, HashMap<String, String> placeholders) {
StringBuilder message = new StringBuilder();
String message = "";
for (String m : list) {
message.append(methods.color(m)).append("\n");
message += Methods.color(m) + "\n";
}
for (String ph : placeholders.keySet()) {
message = new StringBuilder(methods.color(message.toString().replace(ph, placeholders.get(ph))).replace(ph, placeholders.get(ph).toLowerCase()));
message = Methods.color(message.replace(ph, placeholders.get(ph))).replace(ph, placeholders.get(ph).toLowerCase());
}
return message.toString();
return message;
}
public static void addMissingMessages() {
FileConfiguration messages = Files.MESSAGES.getFile();
boolean saveFile = false;
for (Messages message : values()) {
if (!messages.contains("Messages." + message.getPath())) {
saveFile = true;
if (message.getDefaultMessage() != null) {
messages.set("Messages." + message.getPath(), message.getDefaultMessage());
} else {
@ -111,22 +102,23 @@ public enum Messages {
}
}
}
if (saveFile) Files.MESSAGES.saveFile();
if (saveFile) {
Files.MESSAGES.saveFile();
}
}
public String getMessage() {
if (isList()) {
if (exists()) {
return methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path)));
return Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path)));
} else {
return methods.color(convertList(getDefaultListMessage()));
return Methods.color(convertList(getDefaultListMessage()));
}
} else {
if (exists()) {
return methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path));
return Methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path));
} else {
return methods.getPrefix(getDefaultMessage());
return Methods.getPrefix(getDefaultMessage());
}
}
}
@ -135,18 +127,20 @@ public enum Messages {
String message;
if (isList()) {
if (exists()) {
message = methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders));
message = Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders));
} else {
message = methods.color(convertList(getDefaultListMessage(), placeholders));
message = Methods.color(convertList(getDefaultListMessage(), placeholders));
}
} else {
if (exists()) {
message = methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path));
message = Methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path));
} else {
message = methods.getPrefix(getDefaultMessage());
message = Methods.getPrefix(getDefaultMessage());
}
for (String ph : placeholders.keySet()) {
if (message.contains(ph)) message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase());
if (message.contains(ph)) {
message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase());
}
}
}
return message;
@ -155,15 +149,15 @@ public enum Messages {
public String getMessageNoPrefix() {
if (isList()) {
if (exists()) {
return methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path)));
return Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path)));
} else {
return methods.color(convertList(getDefaultListMessage()));
return Methods.color(convertList(getDefaultListMessage()));
}
} else {
if (exists()) {
return methods.color(Files.MESSAGES.getFile().getString("Messages." + path));
return Methods.color(Files.MESSAGES.getFile().getString("Messages." + path));
} else {
return methods.color(getDefaultMessage());
return Methods.color(getDefaultMessage());
}
}
}
@ -172,18 +166,20 @@ public enum Messages {
String message;
if (isList()) {
if (exists()) {
message = methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders));
message = Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders));
} else {
message = methods.color(convertList(getDefaultListMessage(), placeholders));
message = Methods.color(convertList(getDefaultListMessage(), placeholders));
}
} else {
if (exists()) {
message = methods.color(Files.MESSAGES.getFile().getString("Messages." + path));
message = Methods.color(Files.MESSAGES.getFile().getString("Messages." + path));
} else {
message = methods.color(getDefaultMessage());
message = Methods.color(getDefaultMessage());
}
for (String ph : placeholders.keySet()) {
if (message.contains(ph)) message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase());
if (message.contains(ph)) {
message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase());
}
}
}
return message;
@ -212,4 +208,5 @@ public enum Messages {
private List<String> getDefaultListMessage() {
return defaultListMessage;
}
}

View File

@ -0,0 +1,36 @@
package com.badbones69.crazyauctions.api;
public enum ShopType {
SELL("Sell"), BID("Bid");
private final String name;
/**
* @param name name of the Shop Type.
*/
private ShopType(String name) {
this.name = name;
}
/**
* @param name name of the Type you want.
* @return Returns the Type as an Enum.
*/
public static ShopType getFromName(String name) {
for (ShopType type : ShopType.values()) {
if (type.getName().equalsIgnoreCase(name)) {
return type;
}
}
return null;
}
/**
* @return Returns the type name as a string.
*/
public String getName() {
return name;
}
}

View File

@ -0,0 +1,128 @@
package com.badbones69.crazyauctions.api;
import org.bukkit.Bukkit;
public enum Version {
TOO_OLD(-1),
v1_7_R1(171), v1_7_R2(172), v1_7_R3(173), v1_7_R4(174),
v1_8_R1(181), v1_8_R2(182), v1_8_R3(183),
v1_9_R1(191), v1_9_R2(192),
v1_10_R1(1101),
v1_11_R1(1111),
v1_12_R1(1121),
v1_13_R2(1132),
v1_14_R1(1141),
v1_15_R1(1151),
v1_16_R1(1161), v1_16_R2(1162), v1_16_R3(1163),
TOO_NEW(-2);
private static Version currentVersion;
private static Version latest;
private final int versionInteger;
private Version(int versionInteger) {
this.versionInteger = versionInteger;
}
/**
*
* @return Get the server's Minecraft version.
*/
public static Version getCurrentVersion() {
if (currentVersion == null) {
String ver = Bukkit.getServer().getClass().getPackage().getName();
int v = Integer.parseInt(ver.substring(ver.lastIndexOf('.') + 1).replace("_", "").replace("R", "").replace("v", ""));
for (Version version : values()) {
if (version.getVersionInteger() == v) {
currentVersion = version;
break;
}
}
if (v > Version.getLatestVersion().getVersionInteger()) {
currentVersion = Version.getLatestVersion();
}
if (currentVersion == null) {
currentVersion = Version.TOO_NEW;
}
}
return currentVersion;
}
/**
* Get the latest version allowed by the Version class.
* @return The latest version.
*/
public static Version getLatestVersion() {
if (latest == null) {
Version v = Version.TOO_OLD;
for (Version version : values()) {
if (version.comparedTo(v) == 1) {
v = version;
}
}
return v;
} else {
return latest;
}
}
/**
*
* @return The server's minecraft version as an integer.
*/
public int getVersionInteger() {
return this.versionInteger;
}
/**
* This checks if the current version is older, newer, or is the checked version.
* @param version The version you are checking.
* @return -1 if older, 0 if the same, and 1 if newer.
*/
public int comparedTo(Version version) {
int result = -1;
int current = this.getVersionInteger();
int check = version.getVersionInteger();
if (current > check || check == -2) {// check is newer then current
result = 1;
} else if (current == check) {// check is the same as current
result = 0;
} else if (check == -1) {// check is older then current
result = -1;
}
return result;
}
/**
* Checks to see if the current version is newer then the checked version.
* @param version The version you are checking.
* @return True if newer then the checked version and false if the same or older.
*/
public static boolean isNewer(Version version) {
if (currentVersion == null) getCurrentVersion();
return currentVersion.versionInteger > version.versionInteger || currentVersion.versionInteger == -2;
}
/**
* Checks to see if the current version is the same as the checked version.
* @param version The version you are checking.
* @return True if both the current and checked version is the same and false if otherwise.
*/
public static boolean isSame(Version version) {
if (currentVersion == null) getCurrentVersion();
return currentVersion.versionInteger == version.versionInteger;
}
/**
* Checks to see if the current version is older than the checked version.
* @param version The version you are checking.
* @return True if older than the checked version and false if the same or newer.
*/
public static boolean isOlder(Version version) {
if (currentVersion == null) getCurrentVersion();
return currentVersion.versionInteger < version.versionInteger || currentVersion.versionInteger == -1;
}
}

View File

@ -1,48 +0,0 @@
package com.badbones69.crazyauctions.api.economy;
public enum Currency {
VAULT("Vault"),
XP_LEVEL("XP_Level"),
XP_TOTAL("XP_Total");
private final String name;
Currency(String name) {
this.name = name;
}
/**
* Checks if it is a compatible currency.
* @param currency The currency name you are checking.
* @return True if it is supported and false if not.
*/
public static boolean isCurrency(String currency) {
for (Currency value : Currency.values()) {
if (currency.equalsIgnoreCase(value.getName())) return true;
}
return false;
}
/**
* Get a currency enum.
* @param currency The currency you want.
* @return The currency enum.
*/
public static Currency getCurrency(String currency) {
for (Currency value : Currency.values()) {
if (currency.equalsIgnoreCase(value.getName())) return value;
}
return null;
}
/**
* Get the name of the currency.
* @return The name of the currency.
*/
public String getName() {
return name;
}
}

View File

@ -1,158 +0,0 @@
package com.badbones69.crazyauctions.api.economy;
import com.badbones69.crazyauctions.CrazyAuctions;
import com.badbones69.crazyauctions.api.economy.vault.VaultSupport;
import com.badbones69.crazyauctions.api.enums.ShopCategories;
import org.bukkit.entity.Player;
public class CurrencyAPI {
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private final VaultSupport vaultSupport = plugin.getStarter().getVaultSupport();
/**
* Get the amount that a player has from a specific currency.
* @param player The player you wish to get the amount from.
* @param currency The currency you wish to get from.
* @return The amount that the player has of that currency.
*/
public int getCurrency(Player player, Currency currency) {
try {
switch (currency) {
case VAULT:
vaultSupport.getVault().getBalance(player);
break;
case XP_LEVEL:
player.getLevel();
break;
case XP_TOTAL:
getTotalExperience(player);
break;
}
} catch (Exception | NoClassDefFoundError ignored) {}
return 0;
}
/**
* Take an amount from a player's currency.
* @param player The player you wish to take from.
* @param option The ShopOption you wish to use.
*/
public void takeCurrency(Player player, ShopCategories option) {
// takeCurrency(player, option.getCurrency(), option.getCost());
}
/**
* Take an amount from a player's currency.
* @param player The player you wish to take from.
* @param currency The currency you wish to use.
* @param amount The amount you want to take.
*/
public void takeCurrency(Player player, Currency currency, int amount) {
try {
switch (currency) {
case VAULT:
vaultSupport.getVault().withdrawPlayer(player, amount);
break;
case XP_LEVEL:
player.setLevel(player.getLevel() - amount);
break;
case XP_TOTAL:
takeTotalExperience(player, amount);
break;
}
} catch (Exception | NoClassDefFoundError ignored) {}
}
/**
* Give an amount to a player's currency.
* @param player The player you are giving to.
* @param currency The currency you want to use.
* @param amount The amount you are giving to the player.
*/
public void giveCurrency(Player player, Currency currency, int amount) {
try {
switch (currency) {
case VAULT:
vaultSupport.getVault().depositPlayer(player, amount);
break;
case XP_LEVEL:
player.setLevel(player.getLevel() + amount);
break;
case XP_TOTAL:
takeTotalExperience(player, -amount);
break;
}
} catch (Exception | NoClassDefFoundError ignored) {}
}
/**
* Checks if the player has enough of a currency.
* @param player The player you are checking.
* @param option The ShopOption you wish to check.
* @return True if they have enough to buy it or false if they don't.
*/
public boolean canBuy(Player player, ShopCategories option) {
return canBuy(player, option.getCurrency(), option.getCost());
}
/**
* Checks if the player has enough of a currency.
* @param player The player you are checking.
* @param currency The currency you wish to check.
* @param cost The cost of the item you are checking.
* @return True if they have enough to buy it or false if they don't.
*/
public boolean canBuy(Player player, Currency currency, int cost) {
return getCurrency(player, currency) >= cost;
}
private void takeTotalExperience(Player player, int amount) {
int total = getTotalExperience(player) - amount;
player.setTotalExperience(0);
player.setTotalExperience(total);
player.setLevel(0);
player.setExp(0);
while (total > player.getExpToLevel()) {
total -= player.getExpToLevel();
player.setLevel(player.getLevel() + 1);
}
float xp = (float) total / (float) player.getExpToLevel();
player.setExp(xp);
}
private int getTotalExperience(Player player) { // https://www.spigotmc.org/threads/72804
int experience;
int level = player.getLevel();
if (level >= 0 && level <= 15) {
experience = (int) Math.ceil(Math.pow(level, 2) + (6 * level));
int requiredExperience = 2 * level + 7;
double currentExp = Double.parseDouble(Float.toString(player.getExp()));
experience += Math.ceil(currentExp * requiredExperience);
return experience;
} else if (level > 15 && level <= 30) {
experience = (int) Math.ceil((2.5 * Math.pow(level, 2) - (40.5 * level) + 360));
int requiredExperience = 5 * level - 38;
double currentExp = Double.parseDouble(Float.toString(player.getExp()));
experience += Math.ceil(currentExp * requiredExperience);
return experience;
} else {
experience = (int) Math.ceil((4.5 * Math.pow(level, 2) - (162.5 * level) + 2220));
int requiredExperience = 9 * level - 158;
double currentExp = Double.parseDouble(Float.toString(player.getExp()));
experience += Math.ceil(currentExp * requiredExperience);
return experience;
}
}
/**
* Loads the vault currency if it is on the server.
*/
public void loadCurrency() {
vaultSupport.loadVault();
}
}

View File

@ -1,25 +0,0 @@
package com.badbones69.crazyauctions.api.economy.vault;
import com.badbones69.crazyauctions.CrazyAuctions;
import com.badbones69.crazyauctions.utils.func.PluginSupport;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.plugin.RegisteredServiceProvider;
public class VaultSupport {
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private Economy vault = null;
public Economy getVault() {
return vault;
}
public void loadVault() {
if (PluginSupport.VAULT.isPluginLoaded()) {
RegisteredServiceProvider<Economy> rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp != null) vault = rsp.getProvider();
}
}
}

View File

@ -10,4 +10,5 @@ public enum CancelledReason {
* Cancelled by the player them self.
*/
PLAYER_FORCE_CANCEL()
}

View File

@ -1,92 +0,0 @@
package com.badbones69.crazyauctions.api.enums;
import com.badbones69.crazyauctions.api.economy.Currency;
import com.badbones69.crazyauctions.utils.ItemBuilder;
import java.util.HashMap;
public enum ShopCategories {
SELL("Sell"),
BID("Bid");
private final String name;
private final HashMap<ShopCategories, Options> shopCategories = new HashMap<>();
/**
* @param name name of the Shop Type.
*/
ShopCategories(String name) {
this.name = name;
}
/**
* @param name name of the Type you want.
* @return Returns the Type as an Enum.
*/
public static ShopCategories getFromName(String name) {
for (ShopCategories type : ShopCategories.values()) {
if (type.getName().equalsIgnoreCase(name)) return type;
}
return null;
}
public Currency getCurrency() {
return shopCategories.get(this).currency;
}
public int getCost() {
return shopCategories.get(this).cost;
}
/**
* @return Returns the type name as a string.
*/
public String getName() {
return name;
}
private static class Options {
private final ItemBuilder itemBuilder;
private final int slot;
private final boolean inMenu;
private int cost;
private final Currency currency;
public Options(ItemBuilder itemBuilder, int slot, boolean inMenu, int cost, Currency currency) {
this.itemBuilder = itemBuilder;
this.slot = slot;
this.inMenu = inMenu;
this.cost = cost;
this.currency = currency;
}
public ItemBuilder getItemBuilder() {
return itemBuilder;
}
public int getSlot() {
return slot;
}
public int getCost() {
return cost;
}
public Currency getCurrency() {
return currency;
}
public boolean isInMenu() {
return inMenu;
}
public void setCost(int cost) {
this.cost = cost;
}
}
}

View File

@ -6,18 +6,21 @@ import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
/**
*
* @author BadBones69
*
* This event is fired when a player buys something from the selling auction house.
*
*/
public class AuctionBuyEvent extends Event {
private final HandlerList handlers = new HandlerList();
private final Player player;
private final long price;
private final ItemStack item;
private static final HandlerList handlers = new HandlerList();
private Player player;
private long price;
private ItemStack item;
/**
*
* @param player The player who bought the item.
* @param item The item that was bought.
* @param price The price of the item.
@ -27,7 +30,11 @@ public class AuctionBuyEvent extends Event {
this.item = item;
this.price = price;
}
public static HandlerList getHandlerList() {
return handlers;
}
public HandlerList getHandlers() {
return handlers;
}
@ -43,4 +50,5 @@ public class AuctionBuyEvent extends Event {
public long getPrice() {
return price;
}
}

View File

@ -8,20 +8,23 @@ import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
/**
*
* @author BadBones69
*
* This event is fired when a player's item is cancelled.
*
*/
public class AuctionCancelledEvent extends Event {
private final HandlerList handlers = new HandlerList();
private static final HandlerList handlers = new HandlerList();
private OfflinePlayer offlinePlayer;
private Player onlinePlayer;
private final boolean isOnline;
private final ItemStack item;
private final CancelledReason reason;
private boolean isOnline;
private ItemStack item;
private CancelledReason reason;
/**
*
* @param offlinePlayer The player whose item is cancelled.
* @param item The item that is cancelled.
*/
@ -33,6 +36,7 @@ public class AuctionCancelledEvent extends Event {
}
/**
*
* @param onlinePlayer The player whose item is cancelled.
* @param item The item that is cancelled.
*/
@ -43,6 +47,10 @@ public class AuctionCancelledEvent extends Event {
this.reason = reason;
}
public static HandlerList getHandlerList() {
return handlers;
}
public HandlerList getHandlers() {
return handlers;
}
@ -66,4 +74,5 @@ public class AuctionCancelledEvent extends Event {
public CancelledReason getReason() {
return reason;
}
}

View File

@ -7,19 +7,22 @@ import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
/**
*
* @author BadBones69
*
* This event is fired when a player item expires.
*
*/
public class AuctionExpireEvent extends Event {
private final HandlerList handlers = new HandlerList();
private static final HandlerList handlers = new HandlerList();
private OfflinePlayer offlinePlayer;
private Player onlinePlayer;
private final boolean isOnline;
private final ItemStack item;
private boolean isOnline;
private ItemStack item;
/**
*
* @param offlinePlayer The player whose item is expiring.
* @param item The item that is expiring.
*/
@ -30,6 +33,7 @@ public class AuctionExpireEvent extends Event {
}
/**
*
* @param onlinePlayer The player whose item is expiring.
* @param item The item that is expiring.
*/
@ -39,6 +43,10 @@ public class AuctionExpireEvent extends Event {
this.isOnline = true;
}
public static HandlerList getHandlerList() {
return handlers;
}
public HandlerList getHandlers() {
return handlers;
}
@ -58,4 +66,5 @@ public class AuctionExpireEvent extends Event {
public ItemStack getItem() {
return item;
}
}

View File

@ -1,37 +1,44 @@
package com.badbones69.crazyauctions.api.events;
import com.badbones69.crazyauctions.api.enums.ShopCategories;
import com.badbones69.crazyauctions.api.ShopType;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
/**
*
* @author BadBones69
*
* This event is fired when a new item is listed onto the auction house.
*
*/
public class AuctionListEvent extends Event {
private final HandlerList handlers = new HandlerList();
private final Player player;
private final long price;
private final ShopCategories shop;
private final ItemStack item;
private static final HandlerList handlers = new HandlerList();
private Player player;
private long price;
private ShopType shop;
private ItemStack item;
/**
*
* @param player The player who is listing the item.
* @param shop The shop type the item is being listed to.
* @param item The item being listed.
* @param price The price the item is being listed for.
*/
public AuctionListEvent(Player player, ShopCategories shop, ItemStack item, long price) {
public AuctionListEvent(Player player, ShopType shop, ItemStack item, long price) {
this.player = player;
this.shop = shop;
this.item = item;
this.price = price;
}
public static HandlerList getHandlerList() {
return handlers;
}
public HandlerList getHandlers() {
return handlers;
}
@ -40,7 +47,7 @@ public class AuctionListEvent extends Event {
return player;
}
public ShopCategories getShopType() {
public ShopType getShopType() {
return shop;
}
@ -51,4 +58,5 @@ public class AuctionListEvent extends Event {
public long getPrice() {
return price;
}
}

View File

@ -6,16 +6,18 @@ import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
/**
*
* This event is fired when a player places a new bid onto an item in the auction house.
*/
public class AuctionNewBidEvent extends Event {
private final HandlerList handlers = new HandlerList();
private final Player player;
private final long bid;
private final ItemStack item;
private static final HandlerList handlers = new HandlerList();
private Player player;
private long bid;
private ItemStack item;
/**
*
* @param player The player who placed the bid.
* @param item The item that was bid on.
* @param bid The amount of money that was bid.
@ -26,6 +28,10 @@ public class AuctionNewBidEvent extends Event {
this.bid = bid;
}
public static HandlerList getHandlerList() {
return handlers;
}
public HandlerList getHandlers() {
return handlers;
}
@ -41,4 +47,5 @@ public class AuctionNewBidEvent extends Event {
public long getBid() {
return bid;
}
}

View File

@ -6,18 +6,21 @@ import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
/**
*
* @author BadBones69
*
* This event is fired when a bidding item's time has run out and so a player wins the item.
*
*/
public class AuctionWinBidEvent extends Event {
private final HandlerList handlers = new HandlerList();
private final Player player;
private final long bid;
private final ItemStack item;
private static final HandlerList handlers = new HandlerList();
private Player player;
private long bid;
private ItemStack item;
/**
*
* @param player The player who won the item.
* @param item The item that was won.
* @param bid The bid that was placed on the item.
@ -28,6 +31,10 @@ public class AuctionWinBidEvent extends Event {
this.bid = bid;
}
public static HandlerList getHandlerList() {
return handlers;
}
public HandlerList getHandlers() {
return handlers;
}
@ -43,4 +50,5 @@ public class AuctionWinBidEvent extends Event {
public long getBid() {
return bid;
}
}

View File

@ -0,0 +1,22 @@
package com.badbones69.crazyauctions.controllers;
import com.badbones69.crazyauctions.api.FileManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class DupePatch implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPreCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
boolean macro = FileManager.Files.CONFIG.getFile().getBoolean("Settings.Patches.Macro-Dupe", true);
if (!macro) return;
if (!player.isOnline() || player.isDead()) event.setCancelled(true);
}
}

View File

@ -0,0 +1,950 @@
package com.badbones69.crazyauctions.controllers;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.*;
import com.badbones69.crazyauctions.api.FileManager.Files;
import com.badbones69.crazyauctions.api.enums.CancelledReason;
import com.badbones69.crazyauctions.api.events.AuctionBuyEvent;
import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent;
import com.badbones69.crazyauctions.api.events.AuctionNewBidEvent;
import com.badbones69.crazyauctions.currency.CurrencyManager;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
public class GUI implements Listener {
private static HashMap<Player, Integer> bidding = new HashMap<>();
private static HashMap<Player, String> biddingID = new HashMap<>();
private static HashMap<Player, ShopType> shopType = new HashMap<>(); // Shop Type
private static HashMap<Player, Category> shopCategory = new HashMap<>(); // Category Type
private static HashMap<Player, List<Integer>> List = new HashMap<>();
private static HashMap<Player, String> IDs = new HashMap<>();
private static CrazyAuctions crazyAuctions = CrazyAuctions.getInstance();
private static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions");
public static void openShop(Player player, ShopType sell, Category cat, int page) {
Methods.updateAuction();
FileConfiguration config = Files.CONFIG.getFile();
FileConfiguration data = Files.DATA.getFile();
List<ItemStack> items = new ArrayList<>();
List<Integer> ID = new ArrayList<>();
if (!data.contains("Items")) {
data.set("Items.Clear", null);
Files.DATA.saveFile();
}
if (cat != null) {
shopCategory.put(player, cat);
} else {
shopCategory.put(player, Category.NONE);
}
if (data.contains("Items")) {
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
List<String> lore = new ArrayList<>();
if (data.getItemStack("Items." + i + ".Item") != null && (cat.getItems().contains(data.getItemStack("Items." + i + ".Item").getType()) || cat == Category.NONE)) {
if (data.getBoolean("Items." + i + ".Biddable")) {
if (sell == ShopType.BID) {
String seller = data.getString("Items." + i + ".Seller");
String topbidder = data.getString("Items." + i + ".TopBidder");
for (String l : config.getStringList("Settings.GUISettings.Bidding")) {
lore.add(l.replace("%TopBid%", Methods.getPrice(i, false)).replace("%topbid%", Methods.getPrice(i, false)).replace("%Seller%", seller).replace("%seller%", seller).replace("%TopBidder%", topbidder).replace("%topbidder%", topbidder).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))));
}
items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore));
ID.add(data.getInt("Items." + i + ".StoreID"));
}
} else {
if (sell == ShopType.SELL) {
for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) {
lore.add(l.replace("%Price%", String.format(Locale.ENGLISH, "%,d", Long.parseLong(Methods.getPrice(i, false)))).replace("%price%", String.format(Locale.ENGLISH, "%,d", Long.parseLong(Methods.getPrice(i, false)))).replace("%Seller%", data.getString("Items." + i + ".Seller")).replace("%seller%", data.getString("Items." + i + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))));
}
items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore));
ID.add(data.getInt("Items." + i + ".StoreID"));
}
}
}
}
}
int maxPage = Methods.getMaxPage(items);
for (; page > maxPage; page--) ;
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page));
List<String> options = new ArrayList<>();
options.add("SellingItems");
options.add("Cancelled/ExpiredItems");
options.add("PreviousPage");
options.add("Refesh");
options.add("NextPage");
options.add("Category1");
options.add("Category2");
if (sell == ShopType.SELL) {
shopType.put(player, ShopType.SELL);
if (crazyAuctions.isBiddingEnabled()) {
options.add("Bidding/Selling.Selling");
}
options.add("WhatIsThis.SellingShop");
}
if (sell == ShopType.BID) {
shopType.put(player, ShopType.BID);
if (crazyAuctions.isSellingEnabled()) {
options.add("Bidding/Selling.Bidding");
}
options.add("WhatIsThis.BiddingShop");
}
for (String o : options) {
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) {
if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) {
continue;
}
}
String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item");
String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name");
List<String> lore = new ArrayList<>();
int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot");
String cName = Methods.color(config.getString("Settings.GUISettings.Category-Settings." + shopCategory.get(player).getName() + ".Name"));
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) {
for (String l : config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")) {
lore.add(l.replace("%Category%", cName).replace("%category%", cName));
}
inv.setItem(slot - 1, Methods.makeItem(id, 1, name, lore));
} else {
inv.setItem(slot - 1, Methods.makeItem(id, 1, name));
}
}
for (ItemStack item : Methods.getPage(items, page)) {
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
List<Integer> Id = new ArrayList<>(Methods.getPageInts(ID, page));
List.put(player, Id);
player.openInventory(inv);
}
public static void openCategories(Player player, ShopType shop) {
Methods.updateAuction();
FileConfiguration config = Files.CONFIG.getFile();
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Categories")));
List<String> options = new ArrayList<>();
options.add("OtherSettings.Back");
options.add("OtherSettings.WhatIsThis.Categories");
options.add("Category-Settings.Armor");
options.add("Category-Settings.Weapons");
options.add("Category-Settings.Tools");
options.add("Category-Settings.Food");
options.add("Category-Settings.Potions");
options.add("Category-Settings.Blocks");
options.add("Category-Settings.Other");
options.add("Category-Settings.None");
for (String o : options) {
if (config.contains("Settings.GUISettings." + o + ".Toggle")) {
if (!config.getBoolean("Settings.GUISettings." + o + ".Toggle")) {
continue;
}
}
String id = config.getString("Settings.GUISettings." + o + ".Item");
String name = config.getString("Settings.GUISettings." + o + ".Name");
int slot = config.getInt("Settings.GUISettings." + o + ".Slot");
if (config.contains("Settings.GUISettings." + o + ".Lore")) {
inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings." + o + ".Lore")));
} else {
inv.setItem(slot - 1, Methods.makeItem(id, 1, name));
}
}
shopType.put(player, shop);
player.openInventory(inv);
}
public static void openPlayersCurrentList(Player player, int page) {
Methods.updateAuction();
FileConfiguration config = Files.CONFIG.getFile();
FileConfiguration data = Files.DATA.getFile();
List<ItemStack> items = new ArrayList<>();
List<Integer> ID = new ArrayList<>();
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Players-Current-Items")));
List<String> options = new ArrayList<>();
options.add("Back");
options.add("WhatIsThis.CurrentItems");
for (String o : options) {
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) {
if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) {
continue;
}
}
String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item");
String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name");
int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot");
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) {
inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")));
} else {
inv.setItem(slot - 1, Methods.makeItem(id, 1, name));
}
}
if (data.contains("Items")) {
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) {
List<String> lore = new ArrayList<>();
for (String l : config.getStringList("Settings.GUISettings.CurrentLore")) {
lore.add(l.replace("%Price%", Methods.getPrice(i, false)).replace("%price%", Methods.getPrice(i, false)).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))));
}
items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore));
ID.add(data.getInt("Items." + i + ".StoreID"));
}
}
}
for (ItemStack item : Methods.getPage(items, page)) {
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
List<Integer> Id = new ArrayList<>(Methods.getPageInts(ID, page));
List.put(player, Id);
player.openInventory(inv);
}
public static void openPlayersExpiredList(Player player, int page) {
Methods.updateAuction();
FileConfiguration config = Files.CONFIG.getFile();
FileConfiguration data = Files.DATA.getFile();
List<ItemStack> items = new ArrayList<>();
List<Integer> ID = new ArrayList<>();
if (data.contains("OutOfTime/Cancelled")) {
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
if (data.getString("OutOfTime/Cancelled." + i + ".Seller") != null) {
if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getName())) {
List<String> lore = new ArrayList<>();
for (String l : config.getStringList("Settings.GUISettings.Cancelled/ExpiredLore")) {
lore.add(l.replace("%Price%", Methods.getPrice(i, true)).replace("%price%", Methods.getPrice(i, true)).replace("%Time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time"))).replace("%time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time"))));
}
items.add(Methods.addLore(data.getItemStack("OutOfTime/Cancelled." + i + ".Item").clone(), lore));
ID.add(data.getInt("OutOfTime/Cancelled." + i + ".StoreID"));
}
}
}
}
int maxPage = Methods.getMaxPage(items);
for (; page > maxPage; page--) ;
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Cancelled/Expired-Items") + " #" + page));
List<String> options = new ArrayList<>();
options.add("Back");
options.add("PreviousPage");
options.add("Return");
options.add("NextPage");
options.add("WhatIsThis.Cancelled/ExpiredItems");
for (String o : options) {
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) {
if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) {
continue;
}
}
String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item");
String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name");
int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot");
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) {
inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")));
} else {
inv.setItem(slot - 1, Methods.makeItem(id, 1, name));
}
}
for (ItemStack item : Methods.getPage(items, page)) {
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
List<Integer> Id = new ArrayList<>(Methods.getPageInts(ID, page));
List.put(player, Id);
player.openInventory(inv);
}
public static void openBuying(Player player, String ID) {
Methods.updateAuction();
FileConfiguration config = Files.CONFIG.getFile();
FileConfiguration data = Files.DATA.getFile();
if (!data.contains("Items." + ID)) {
openShop(player, ShopType.SELL, shopCategory.get(player), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
return;
}
Inventory inv = Bukkit.createInventory(null, 9, Methods.color(config.getString("Settings.Buying-Item")));
List<String> options = new ArrayList<>();
options.add("Confirm");
options.add("Cancel");
for (String o : options) {
String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item");
String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name");
ItemStack item;
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) {
item = Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore"));
} else {
item = Methods.makeItem(id, 1, name);
}
if (o.equals("Confirm")) {
inv.setItem(0, item);
inv.setItem(1, item);
inv.setItem(2, item);
inv.setItem(3, item);
}
if (o.equals("Cancel")) {
inv.setItem(5, item);
inv.setItem(6, item);
inv.setItem(7, item);
inv.setItem(8, item);
}
}
ItemStack item = data.getItemStack("Items." + ID + ".Item");
List<String> lore = new ArrayList<>();
for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) {
lore.add(l.replace("%Price%", Methods.getPrice(ID, false)).replace("%price%", Methods.getPrice(ID, false)).replace("%Seller%", data.getString("Items." + ID + ".Seller")).replace("%seller%", data.getString("Items." + ID + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + l + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + l + ".Time-Till-Expire"))));
}
inv.setItem(4, Methods.addLore(item.clone(), lore));
IDs.put(player, ID);
player.openInventory(inv);
}
public static void openBidding(Player player, String ID) {
Methods.updateAuction();
FileConfiguration config = Files.CONFIG.getFile();
FileConfiguration data = Files.DATA.getFile();
if (!data.contains("Items." + ID)) {
openShop(player, ShopType.BID, shopCategory.get(player), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
return;
}
Inventory inv = Bukkit.createInventory(null, 27, Methods.color(config.getString("Settings.Bidding-On-Item")));
if (!bidding.containsKey(player)) bidding.put(player, 0);
if (Version.isNewer(Version.v1_12_R1)) {
inv.setItem(9, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+1"));
inv.setItem(10, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+10"));
inv.setItem(11, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+100"));
inv.setItem(12, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+1000"));
inv.setItem(14, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-1000"));
inv.setItem(15, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-100"));
inv.setItem(16, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-10"));
inv.setItem(17, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-1"));
} else {
inv.setItem(9, Methods.makeItem("160:5", 1, "&a+1"));
inv.setItem(10, Methods.makeItem("160:5", 1, "&a+10"));
inv.setItem(11, Methods.makeItem("160:5", 1, "&a+100"));
inv.setItem(12, Methods.makeItem("160:5", 1, "&a+1000"));
inv.setItem(14, Methods.makeItem("160:14", 1, "&c-1000"));
inv.setItem(15, Methods.makeItem("160:14", 1, "&c-100"));
inv.setItem(16, Methods.makeItem("160:14", 1, "&c-10"));
inv.setItem(17, Methods.makeItem("160:14", 1, "&c-1"));
}
inv.setItem(13, getBiddingGlass(player, ID));
inv.setItem(22, Methods.makeItem(config.getString("Settings.GUISettings.OtherSettings.Bid.Item"), 1, config.getString("Settings.GUISettings.OtherSettings.Bid.Name"), config.getStringList("Settings.GUISettings.OtherSettings.Bid.Lore")));
inv.setItem(4, getBiddingItem(player, ID));
player.openInventory(inv);
}
public static void openViewer(Player player, String other, int page) {
Methods.updateAuction();
FileConfiguration config = Files.CONFIG.getFile();
FileConfiguration data = Files.DATA.getFile();
List<ItemStack> items = new ArrayList<>();
List<Integer> ID = new ArrayList<>();
if (!data.contains("Items")) {
data.set("Items.Clear", null);
Files.DATA.saveFile();
}
if (data.contains("Items")) {
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(other)) {
List<String> lore = new ArrayList<>();
if (data.getBoolean("Items." + i + ".Biddable")) {
String seller = data.getString("Items." + i + ".Seller");
String topbidder = data.getString("Items." + i + ".TopBidder");
for (String l : config.getStringList("Settings.GUISettings.Bidding")) {
lore.add(l.replace("%TopBid%", Methods.getPrice(i, false)).replace("%topbid%", Methods.getPrice(i, false)).replace("%Seller%", seller).replace("%seller%", seller).replace("%TopBidder%", topbidder).replace("%topbidder%", topbidder).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))));
}
} else {
for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) {
lore.add(l.replace("%Price%", Methods.getPrice(i, false)).replace("%price%", Methods.getPrice(i, false)).replace("%Seller%", data.getString("Items." + i + ".Seller")).replace("%seller%", data.getString("Items." + i + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))));
}
}
items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore));
ID.add(data.getInt("Items." + i + ".StoreID"));
}
}
}
int maxPage = Methods.getMaxPage(items);
for (; page > maxPage; page--) ;
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page));
List<String> options = new ArrayList<>();
options.add("WhatIsThis.Viewing");
for (String o : options) {
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) {
if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) {
continue;
}
}
String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item");
String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name");
int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot");
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) {
inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")));
} else {
inv.setItem(slot - 1, Methods.makeItem(id, 1, name));
}
}
for (ItemStack item : Methods.getPage(items, page)) {
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
List.put(player, new ArrayList<>(Methods.getPageInts(ID, page)));
player.openInventory(inv);
}
public static ItemStack getBiddingGlass(Player player, String ID) {
FileConfiguration config = Files.CONFIG.getFile();
String id = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name");
ItemStack item;
int bid = bidding.get(player);
if (config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
List<String> lore = new ArrayList<>();
for (String l : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
lore.add(l.replace("%Bid%", bid + "").replace("%bid%", bid + "").replace("%TopBid%", Methods.getPrice(ID, false)).replace("%topbid%", Methods.getPrice(ID, false)));
}
item = Methods.makeItem(id, 1, name, lore);
} else {
item = Methods.makeItem(id, 1, name);
}
return item;
}
public static ItemStack getBiddingItem(Player player, String ID) {
FileConfiguration config = Files.CONFIG.getFile();
FileConfiguration data = Files.DATA.getFile();
String seller = data.getString("Items." + ID + ".Seller");
String topbidder = data.getString("Items." + ID + ".TopBidder");
ItemStack item = data.getItemStack("Items." + ID + ".Item");
List<String> lore = new ArrayList<>();
for (String l : config.getStringList("Settings.GUISettings.Bidding")) {
lore.add(l.replace("%TopBid%", Methods.getPrice(ID, false)).replace("%topbid%", Methods.getPrice(ID, false)).replace("%Seller%", seller).replace("%seller%", seller).replace("%TopBidder%", topbidder).replace("%topbidder%", topbidder).replace("%Time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire"))));
}
return Methods.addLore(item.clone(), lore);
}
private static void playClick(Player player) {
if (Files.CONFIG.getFile().contains("Settings.Sounds.Toggle")) {
if (Files.CONFIG.getFile().getBoolean("Settings.Sounds.Toggle")) {
String sound = Files.CONFIG.getFile().getString("Settings.Sounds.Sound");
try {
player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1);
} catch (Exception e) {
if (Methods.getVersion() >= 191) {
player.playSound(player.getLocation(), Sound.valueOf("UI_BUTTON_CLICK"), 1, 1);
} else {
player.playSound(player.getLocation(), Sound.valueOf("CLICK"), 1, 1);
}
Bukkit.getLogger().log(Level.WARNING, "[Crazy Auctions]>> You set the sound to " + sound + " and this is not a sound for your minecraft version. " + "Please go to the config and set a correct sound or turn the sound off in the toggle setting.");
}
}
} else {
if (Methods.getVersion() >= 191) {
player.playSound(player.getLocation(), Sound.valueOf("UI_BUTTON_CLICK"), 1, 1);
} else {
player.playSound(player.getLocation(), Sound.valueOf("CLICK"), 1, 1);
}
}
}
@EventHandler
public void onInvClose(InventoryCloseEvent e) {
FileConfiguration config = Files.CONFIG.getFile();
Inventory inv = e.getInventory();
Player player = (Player) e.getPlayer();
if (inv != null) {
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) {
bidding.remove(player);
}
}
}
@EventHandler
public void onInvClick(InventoryClickEvent e) {
FileConfiguration config = Files.CONFIG.getFile();
FileConfiguration data = Files.DATA.getFile();
Player player = (Player) e.getWhoClicked();
final Inventory inv = e.getInventory();
if (inv != null) {
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Categories")))) {
e.setCancelled(true);
int slot = e.getRawSlot();
if (slot <= inv.getSize()) {
if (e.getCurrentItem() != null) {
ItemStack item = e.getCurrentItem();
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
for (Category cat : Category.values()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.Category-Settings." + cat.getName() + ".Name")))) {
openShop(player, shopType.get(player), cat, 1);
playClick(player);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) {
openShop(player, shopType.get(player), shopCategory.get(player), 1);
playClick(player);
return;
}
}
}
}
}
}
}
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) {
e.setCancelled(true);
int slot = e.getRawSlot();
if (slot <= inv.getSize()) {
if (e.getCurrentItem() != null) {
ItemStack item = e.getCurrentItem();
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bid.Name")))) {
String ID = biddingID.get(player);
int bid = bidding.get(player);
String topBidder = data.getString("Items." + ID + ".TopBidder");
if (CurrencyManager.getMoney(player) < bid) {
HashMap<String, String> placeholders = new HashMap<>();
placeholders.put("%Money_Needed%", (bid - CurrencyManager.getMoney(player)) + "");
placeholders.put("%money_needed%", (bid - CurrencyManager.getMoney(player)) + "");
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders));
return;
}
if (data.getLong("Items." + ID + ".Price") > bid) {
player.sendMessage(Messages.BID_MORE_MONEY.getMessage());
return;
}
if (data.getLong("Items." + ID + ".Price") >= bid && !topBidder.equalsIgnoreCase("None")) {
player.sendMessage(Messages.BID_MORE_MONEY.getMessage());
return;
}
Bukkit.getPluginManager().callEvent(new AuctionNewBidEvent(player, data.getItemStack("Items." + ID + ".Item"), bid));
data.set("Items." + ID + ".Price", bid);
data.set("Items." + ID + ".TopBidder", player.getName());
HashMap<String, String> placeholders = new HashMap<>();
placeholders.put("%Bid%", bid + "");
player.sendMessage(Messages.BID_MESSAGE.getMessage(placeholders));
Files.DATA.saveFile();
bidding.put(player, 0);
player.closeInventory();
playClick(player);
return;
}
HashMap<String, Integer> priceEdits = new HashMap<>();
priceEdits.put("&a+1", 1);
priceEdits.put("&a+10", 10);
priceEdits.put("&a+100", 100);
priceEdits.put("&a+1000", 1000);
priceEdits.put("&c-1", -1);
priceEdits.put("&c-10", -10);
priceEdits.put("&c-100", -100);
priceEdits.put("&c-1000", -1000);
for (String price : priceEdits.keySet()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(price))) {
try {
bidding.put(player, (bidding.get(player) + priceEdits.get(price)));
inv.setItem(4, getBiddingItem(player, biddingID.get(player)));
inv.setItem(13, getBiddingGlass(player, biddingID.get(player)));
playClick(player);
return;
} catch (Exception ex) {
player.closeInventory();
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
return;
}
}
}
}
}
}
}
}
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.GUIName")))) {
e.setCancelled(true);
final int slot = e.getRawSlot();
if (slot <= inv.getSize()) {
if (e.getCurrentItem() != null) {
final ItemStack item = e.getCurrentItem();
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) {
Methods.updateAuction();
int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
openShop(player, shopType.get(player), shopCategory.get(player), page + 1);
playClick(player);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) {
Methods.updateAuction();
int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
if (page == 1) page++;
openShop(player, shopType.get(player), shopCategory.get(player), page - 1);
playClick(player);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Refesh.Name")))) {
Methods.updateAuction();
int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
openShop(player, shopType.get(player), shopCategory.get(player), page);
playClick(player);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Selling.Name")))) {
openShop(player, ShopType.BID, shopCategory.get(player), 1);
playClick(player);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Bidding.Name")))) {
openShop(player, ShopType.SELL, shopCategory.get(player), 1);
playClick(player);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancelled/ExpiredItems.Name")))) {
openPlayersExpiredList(player, 1);
playClick(player);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.SellingItems.Name")))) {
openPlayersCurrentList(player, 1);
playClick(player);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category1.Name")))) {
openCategories(player, shopType.get(player));
playClick(player);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category2.Name")))) {
openCategories(player, shopType.get(player));
playClick(player);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name")))) {
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name")))) {
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name")))) {
return;
}
}
if (List.containsKey(player)) {
if (List.get(player).size() >= slot) {
int id = List.get(player).get(slot);
boolean T = false;
if (data.contains("Items")) {
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
int ID = data.getInt("Items." + i + ".StoreID");
if (id == ID) {
if (player.hasPermission("crazyAuctions.admin") || player.hasPermission("crazyauctions.force-end")) {
if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
int num = 1;
for (; data.contains("OutOfTime/Cancelled." + num); num++) ;
String seller = data.getString("Items." + i + ".Seller");
Player sellerPlayer = Methods.getPlayer(seller);
if (Methods.isOnline(seller) && sellerPlayer != null) {
sellerPlayer.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage());
}
AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Bukkit.getOfflinePlayer(seller)), data.getItemStack("Items." + i + ".Item"), CancelledReason.ADMIN_FORCE_CANCEL);
Bukkit.getPluginManager().callEvent(event);
data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller"));
data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time"));
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item"));
data.set("Items." + i, null);
Files.DATA.saveFile();
player.sendMessage(Messages.ADMIN_FORCE_CENCELLED.getMessage());
playClick(player);
int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
openShop(player, shopType.get(player), shopCategory.get(player), page);
return;
}
}
final Runnable runnable = () -> inv.setItem(slot, item);
if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) {
String it = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name");
ItemStack I;
if (config.contains("Settings.GUISettings.OtherSettings.Your-Item.Lore")) {
I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Your-Item.Lore"));
} else {
I = Methods.makeItem(it, 1, name);
}
inv.setItem(slot, I);
playClick(player);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20);
return;
}
long cost = data.getLong("Items." + i + ".Price");
if (CurrencyManager.getMoney(player) < cost) {
String it = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name");
ItemStack I;
if (config.contains("Settings.GUISettings.OtherSettings.Cant-Afford.Lore")) {
I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Cant-Afford.Lore"));
} else {
I = Methods.makeItem(it, 1, name);
}
inv.setItem(slot, I);
playClick(player);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20);
return;
}
if (data.getBoolean("Items." + i + ".Biddable")) {
if (player.getName().equalsIgnoreCase(data.getString("Items." + i + ".TopBidder"))) {
String it = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name");
ItemStack I;
if (config.contains("Settings.GUISettings.OtherSettings.Top-Bidder.Lore")) {
I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Top-Bidder.Lore"));
} else {
I = Methods.makeItem(it, 1, name);
}
inv.setItem(slot, I);
playClick(player);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20);
return;
}
playClick(player);
openBidding(player, i);
biddingID.put(player, i);
} else {
playClick(player);
openBuying(player, i);
}
return;
}
}
}
if (!T) {
playClick(player);
openShop(player, shopType.get(player), shopCategory.get(player), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
return;
}
}
}
}
}
}
}
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Buying-Item")))) {
e.setCancelled(true);
int slot = e.getRawSlot();
if (slot <= inv.getSize()) {
if (e.getCurrentItem() != null) {
ItemStack item = e.getCurrentItem();
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Confirm.Name")))) {
String ID = IDs.get(player);
long cost = data.getLong("Items." + ID + ".Price");
String seller = data.getString("Items." + ID + ".Seller");
if (!data.contains("Items." + ID)) {
playClick(player);
openShop(player, shopType.get(player), shopCategory.get(player), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
return;
}
if (Methods.isInvFull(player)) {
playClick(player);
player.closeInventory();
player.sendMessage(Messages.INVENTORY_FULL.getMessage());
return;
}
if (CurrencyManager.getMoney(player) < cost) {
playClick(player);
player.closeInventory();
HashMap<String, String> placeholders = new HashMap<>();
placeholders.put("%Money_Needed%", (cost - CurrencyManager.getMoney(player)) + "");
placeholders.put("%money_needed%", (cost - CurrencyManager.getMoney(player)) + "");
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders));
return;
}
ItemStack i = data.getItemStack("Items." + ID + ".Item");
Bukkit.getPluginManager().callEvent(new AuctionBuyEvent(player, i, cost));
CurrencyManager.removeMoney(player, cost);
CurrencyManager.addMoney(Methods.getOfflinePlayer(seller), cost);
HashMap<String, String> placeholders = new HashMap<>();
placeholders.put("%Price%", Methods.getPrice(ID, false));
placeholders.put("%price%", Methods.getPrice(ID, false));
placeholders.put("%Player%", player.getName());
placeholders.put("%player%", player.getName());
player.sendMessage(Messages.BOUGHT_ITEM.getMessage(placeholders));
if (Methods.isOnline(seller) && Methods.getPlayer(seller) != null) {
Player sell = Methods.getPlayer(seller);
sell.sendMessage(Messages.PLAYER_BOUGHT_ITEM.getMessage(placeholders));
}
player.getInventory().addItem(i);
data.set("Items." + ID, null);
Files.DATA.saveFile();
playClick(player);
openShop(player, shopType.get(player), shopCategory.get(player), 1);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancel.Name")))) {
openShop(player, shopType.get(player), shopCategory.get(player), 1);
playClick(player);
return;
}
}
}
}
}
}
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Players-Current-Items")))) {
e.setCancelled(true);
int slot = e.getRawSlot();
if (slot <= inv.getSize()) {
if (e.getCurrentItem() != null) {
ItemStack item = e.getCurrentItem();
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) {
openShop(player, shopType.get(player), shopCategory.get(player), 1);
playClick(player);
return;
}
}
if (List.containsKey(player)) {
if (List.get(player).size() >= slot) {
int id = List.get(player).get(slot);
boolean T = false;
if (data.contains("Items")) {
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
int ID = data.getInt("Items." + i + ".StoreID");
if (id == ID) {
player.sendMessage(Messages.CANCELLED_ITEM.getMessage());
AuctionCancelledEvent event = new AuctionCancelledEvent(player, data.getItemStack("Items." + i + ".Item"), CancelledReason.PLAYER_FORCE_CANCEL);
Bukkit.getPluginManager().callEvent(event);
int num = 1;
for (; data.contains("OutOfTime/Cancelled." + num); num++) ;
data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller"));
data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time"));
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item"));
data.set("Items." + i, null);
Files.DATA.saveFile();
playClick(player);
openPlayersCurrentList(player, 1);
return;
}
}
}
if (!T) {
playClick(player);
openShop(player, shopType.get(player), shopCategory.get(player), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
return;
}
}
}
}
}
}
}
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Cancelled/Expired-Items")))) {
e.setCancelled(true);
final int slot = e.getRawSlot();
if (slot <= inv.getSize()) {
if (e.getCurrentItem() != null) {
final ItemStack item = e.getCurrentItem();
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) {
Methods.updateAuction();
playClick(player);
openShop(player, shopType.get(player), shopCategory.get(player), 1);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) {
Methods.updateAuction();
int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
if (page == 1) page++;
playClick(player);
openPlayersExpiredList(player, (page - 1));
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Return.Name")))) {
Methods.updateAuction();
int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
if (data.contains("OutOfTime/Cancelled")) {
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getName())) {
if (Methods.isInvFull(player)) {
player.sendMessage(Messages.INVENTORY_FULL.getMessage());
break;
} else {
player.getInventory().addItem(data.getItemStack("OutOfTime/Cancelled." + i + ".Item"));
data.set("OutOfTime/Cancelled." + i, null);
}
}
}
}
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage());
Files.DATA.saveFile();
playClick(player);
openPlayersExpiredList(player, page);
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) {
Methods.updateAuction();
int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
playClick(player);
openPlayersExpiredList(player, (page + 1));
return;
}
}
if (List.containsKey(player)) {
if (List.get(player).size() >= slot) {
int id = List.get(player).get(slot);
boolean T = false;
if (data.contains("OutOfTime/Cancelled")) {
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
int ID = data.getInt("OutOfTime/Cancelled." + i + ".StoreID");
if (id == ID) {
if (!Methods.isInvFull(player)) {
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage());
ItemStack IT = data.getItemStack("OutOfTime/Cancelled." + i + ".Item");
player.getInventory().addItem(IT);
data.set("OutOfTime/Cancelled." + i, null);
Files.DATA.saveFile();
playClick(player);
openPlayersExpiredList(player, 1);
} else {
player.sendMessage(Messages.INVENTORY_FULL.getMessage());
}
return;
}
}
}
if (!T) {
playClick(player);
openShop(player, shopType.get(player), shopCategory.get(player), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
}
}
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,119 @@
package com.badbones69.crazyauctions.currency;
import com.badbones69.crazyauctions.api.FileManager.Files;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public enum CurrencyManager { // Currency Manager
VAULT("Vault", "Money");
private final String pluginName;
private final String name;
/**
* @param pluginname
* name of the Plugin.
* @param name
* name of the Currency.
*/
private CurrencyManager(String pluginname, String name) {
this.pluginName = pluginname;
this.name = name;
}
/**
* @param name
* name of the Type you want.
* @return Returns the Currency as a Enum.
*/
public static CurrencyManager getFromName(String name) {
for (CurrencyManager type : CurrencyManager.values()) {
if (type.getPluginName().equalsIgnoreCase(name)) {
return type;
}
}
return null;
}
/**
*
* @param player
* Player you want the currency from.
* @return Returns the amount they have of the currency
*/
public static Long getMoney(Player player) {
return Vault.getMoney(player);
}
/**
*
* @param player
* Player you want the currency from.
* @param amount
* The amount you want to take.
*/
public static void removeMoney(Player player, Long amount) {
Vault.removeMoney(player, amount);
}
/**
*
* @param player
* Player you want the currency from.
* @param amount
* The amount you want to take.
*/
public static void removeMoney(OfflinePlayer player, Long amount) {
Vault.removeMoney(player, amount);
}
/**
*
* @param player
* Player you want the currency from.
* @param amount
* The amount you want to add.
*/
public static void addMoney(Player player, Long amount) {
Vault.addMoney(player, amount);
}
/**
*
* @param player
* Player you want the currency from.
* @param amount
* The amount you want to add.
*/
public static void addMoney(OfflinePlayer player, Long amount) {
Vault.addMoney(player, amount);
}
/**
* @return Returns the Currency name as a string.
*/
public String getName() {
return name;
}
/**
* @return Returns the Currency name as a string.
*/
public String getPluginName() {
return pluginName;
}
/**
*
* @return Returns true if the server has the plugin.
*/
public Boolean hasPlugin() {
if (Bukkit.getServer().getPluginManager().getPlugin(pluginName) != null) {
return Files.CONFIG.getFile().getBoolean("Settings.Currencies." + pluginName + ".Enabled");
}
return false;
}
}

View File

@ -0,0 +1,57 @@
package com.badbones69.crazyauctions.currency;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
public class Vault {
public static Economy econ = null;
public static EconomyResponse r;
public static boolean hasVault() {
return Bukkit.getServer().getPluginManager().getPlugin("Vault") != null;
}
public static boolean setupEconomy() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
RegisteredServiceProvider<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

@ -1,275 +0,0 @@
package com.badbones69.crazyauctions.utils;
import com.badbones69.crazyauctions.CrazyAuctions;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Skull;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Base64;
import java.util.UUID;
/**
* A library for the Bukkit API to create player skulls
* from names, base64 strings, and texture URLs.
* Does not use any NMS code, and should work across all versions.
*
* @author Dean B on 12/28/2016.
*/
public class SkullCreator {
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
/**
* Creates a player skull based on a player's name.
*
* @param name The Player's name
* @return The head of the Player
*
* @deprecated names don't make for good identifiers
*/
@Deprecated
public ItemStack itemFromName(String name) {
ItemStack item = getPlayerSkullItem();
return itemWithName(item, name);
}
/**
* Creates a player skull based on a player's name.
*
* @param item The item to apply the name to
* @param name The Player's name
* @return The head of the Player
*
* @deprecated names don't make for good identifiers
*/
@Deprecated
public ItemStack itemWithName(ItemStack item, String name) {
notNull(item, "item");
notNull(name, "name");
return plugin.getServer().getUnsafe().modifyItemStack(item, "{SkullOwner:\"" + name + "\"}");
}
/**
* Creates a player skull with a UUID. 1.13 only.
*
* @param id The Player's UUID
* @return The head of the Player
*/
public ItemStack itemFromUuid(UUID id) {
ItemStack item = getPlayerSkullItem();
return itemWithUuid(item, id);
}
/**
* Creates a player skull based on a UUID. 1.13 only.
*
* @param item The item to apply the name to
* @param id The Player's UUID
* @return The head of the Player
*/
public ItemStack itemWithUuid(ItemStack item, UUID id) {
notNull(item, "item");
notNull(id, "id");
SkullMeta meta = (SkullMeta) item.getItemMeta();
meta.setOwningPlayer(plugin.getServer().getOfflinePlayer(id));
item.setItemMeta(meta);
return item;
}
/**
* Creates a player skull based on a Mojang server URL.
*
* @param url The URL of the Mojang skin
* @return The head associated with the URL
*/
public ItemStack itemFromUrl(String url) {
ItemStack item = getPlayerSkullItem();
return itemWithUrl(item, url);
}
/**
* Creates a player skull based on a Mojang server URL.
*
* @param item The item to apply the skin to
* @param url The URL of the Mojang skin
* @return The head associated with the URL
*/
public ItemStack itemWithUrl(ItemStack item, String url) {
notNull(item, "item");
notNull(url, "url");
return itemWithBase64(item, urlToBase64(url));
}
/**
* Creates a player skull based on a base64 string containing the link to the skin.
*
* @param base64 The base64 string containing the texture
* @return The head with a custom texture
*/
public ItemStack itemFromBase64(String base64) {
ItemStack item = getPlayerSkullItem();
return itemWithBase64(item, base64);
}
/**
* Applies the base64 string to the ItemStack.
*
* @param item The ItemStack to put the base64 onto
* @param base64 The base64 string containing the texture
* @return The head with a custom texture
*/
public ItemStack itemWithBase64(ItemStack item, String base64) {
notNull(item, "item");
notNull(base64, "base64");
UUID hashAsId = new UUID(base64.hashCode(), base64.hashCode());
return plugin.getServer().getUnsafe().modifyItemStack(item,
"{SkullOwner:{Id:\"" + hashAsId + "\",Properties:{textures:[{Value:\"" + base64 + "\"}]}}}"
);
}
/**
* Sets the block to a skull with the given name.
*
* @param block The block to set
* @param name The player to set it to
*
* @deprecated names don't make for good identifiers
*/
@Deprecated
public void blockWithName(Block block, String name) {
notNull(block, "block");
notNull(name, "name");
setBlockType(block);
((Skull) block.getState()).setOwningPlayer(Bukkit.getOfflinePlayer(name));
}
/**
* Sets the block to a skull with the given UUID.
*
* @param block The block to set
* @param id The player to set it to
*/
public void blockWithUuid(Block block, UUID id) {
notNull(block, "block");
notNull(id, "id");
setBlockType(block);
((Skull) block.getState()).setOwningPlayer(Bukkit.getOfflinePlayer(id));
}
/**
* Sets the block to a skull with the given UUID.
*
* @param block The block to set
* @param url The mojang URL to set it to use
*/
public void blockWithUrl(Block block, String url) {
notNull(block, "block");
notNull(url, "url");
blockWithBase64(block, urlToBase64(url));
}
/**
* Sets the block to a skull with the given UUID.
*
* @param block The block to set
* @param base64 The base64 to set it to use
*/
public void blockWithBase64(Block block, String base64) {
notNull(block, "block");
notNull(base64, "base64");
UUID hashAsId = new UUID(base64.hashCode(), base64.hashCode());
String args = String.format(
"%d %d %d %s",
block.getX(),
block.getY(),
block.getZ(),
"{Owner:{Id:\"" + hashAsId + "\",Properties:{textures:[{Value:\"" + base64 + "\"}]}}}"
);
if (newerApi()) {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "data merge block " + args);
} else {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "blockdata " + args);
}
}
private boolean newerApi() {
try {
Material.valueOf("PLAYER_HEAD");
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
private ItemStack getPlayerSkullItem() {
if (newerApi()) {
return new ItemStack(Material.valueOf("PLAYER_HEAD"));
} else {
return new ItemStack(Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
}
}
private void setBlockType(Block block) {
try {
block.setType(Material.valueOf("PLAYER_HEAD"), false);
} catch (IllegalArgumentException e) {
block.setType(Material.valueOf("SKULL"), false);
}
}
private void notNull(Object o, String name) {
if (o == null) {
throw new NullPointerException(name + " should not be null!");
}
}
private String urlToBase64(String url) {
URI actualUrl;
try {
actualUrl = new URI(url);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
String toEncode = "{\"textures\":{\"SKIN\":{\"url\":\"" + actualUrl + "\"}}}";
return Base64.getEncoder().encodeToString(toEncode.getBytes());
}
}
/* Format for skull
{
display:{
Name:"Cheese"
},
SkullOwner:{
Id:"9c919b83-f3fe-456f-a824-7d1d08cc8bd2",
Properties:{
textures:[
{
Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTU1ZDYxMWE4NzhlODIxMjMxNzQ5YjI5NjU3MDhjYWQ5NDI2NTA2NzJkYjA5ZTI2ODQ3YTg4ZTJmYWMyOTQ2In19fQ=="
}
]
}
}
}*/

View File

@ -1,27 +0,0 @@
package com.badbones69.crazyauctions.utils.func;
import com.badbones69.crazyauctions.CrazyAuctions;
public enum PluginSupport {
PLACEHOLDERAPI("PlaceholderAPI"),
HOLOGRAPHIC_DISPLAYS("HolographicDisplays"),
DECENT_HOLOGRAMS("DecentHolograms"),
VAULT("Vault");
private final String name;
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
PluginSupport(String name) {
this.name = name;
}
public String getName() {
return name;
}
public boolean isPluginLoaded() {
return plugin.getServer().getPluginManager().getPlugin(name) != null;
}
}

View File

@ -1,120 +0,0 @@
package com.badbones69.crazyauctions.utils.func;
import com.badbones69.crazyauctions.CrazyAuctions;
/**
* @author Badbones69
*/
public enum ServerProtocol {
TOO_OLD(-1),
v1_7_R1(171), v1_7_R2(172), v1_7_R3(173), v1_7_R4(174),
v1_8_R1(181), v1_8_R2(182), v1_8_R3(183),
v1_9_R1(191), v1_9_R2(192),
v1_10_R1(1101),
v1_11_R1(1111),
v1_12_R1(1121),
v1_13_R2(1132),
v1_14_R1(1141),
v1_15_R1(1151),
v1_16_R1(1161), v1_16_R2(1162), v1_16_R3(1163),
v1_17_R1(1171),
v1_18_R1(1181),
v1_18_R2(1182),
v1_19(1191),
TOO_NEW(-2);
private static ServerProtocol currentProtocol;
private static ServerProtocol latest;
private final int versionProtocol;
private static final CrazyAuctions plugin = CrazyAuctions.getPlugin();
ServerProtocol(int versionProtocol) {
this.versionProtocol = versionProtocol;
}
public static ServerProtocol getCurrentProtocol() {
String serVer = plugin.getServer().getClass().getPackage().getName();
int serProt = Integer.parseInt(
serVer.substring(
serVer.lastIndexOf('.') + 1
).replace("_", "").replace("R", "").replace("v", "")
);
for (ServerProtocol protocol : values()) {
if (protocol.versionProtocol == serProt) {
currentProtocol = protocol;
break;
}
}
if (currentProtocol == null) currentProtocol = ServerProtocol.TOO_NEW;
return currentProtocol;
}
public static boolean isLegacy() {
return isOlder(ServerProtocol.v1_18_R1);
}
public static ServerProtocol getLatestProtocol() {
if (latest != null) return latest;
ServerProtocol old = ServerProtocol.TOO_OLD;
for (ServerProtocol protocol : values()) {
if (protocol.compare(old) == 1) {
old = protocol;
}
}
return old;
}
public static boolean isAtLeast(ServerProtocol protocol) {
if (currentProtocol == null) getCurrentProtocol();
int proto = currentProtocol.versionProtocol;
return proto >= protocol.versionProtocol || proto == -2;
}
public static boolean isNewer(ServerProtocol protocol) {
if (currentProtocol == null) getCurrentProtocol();
return currentProtocol.versionProtocol > protocol.versionProtocol || currentProtocol.versionProtocol == -2;
}
public static boolean isSame(ServerProtocol protocol) {
if (currentProtocol == null) getCurrentProtocol();
return currentProtocol.versionProtocol == protocol.versionProtocol;
}
public static boolean isOlder(ServerProtocol protocol) {
if (currentProtocol == null) getCurrentProtocol();
int proto = currentProtocol.versionProtocol;
return proto < protocol.versionProtocol || proto == -1;
}
public int compare(ServerProtocol protocol) {
int result = -1;
int current = versionProtocol;
int check = protocol.versionProtocol;
if (current > check || check == -2) {
result = 1;
} else if (current == check) {
result = 0;
}
return result;
}
}

View File

@ -0,0 +1,306 @@
Settings:
Prefix: '&7[&4Crazy &bAuctions&7]: ' #Prefix of when you get Crazy Auctions Messages.
GUIName: '&4Crazy &bAuctions&8' #Name of the Main GUI.
Players-Current-Items: '&8Your Current Listings' #The Name of the Player Current Items GUI.
Cancelled/Expired-Items: '&8Cancelled/Expired Listings' #Name of the Canceled/Expired GUI.
Buying-Item: '&8Purchase Item: Are You Sure?' #Name of the Buying GUI.
Bidding-On-Item: '&8You Are Bidding On This Item.' #Name of the Bidding GUI.
Categories: '&8Categories' #Name of the Category GUI.
Sell-Time: 2d #The time that each item will sell for.
Bid-Time: 2m 30s #Time for each item that is biddable.
Full-Expire-Time: 10d #The full time the item is in the crazy auctions.
Bid-Winner-Time: 20d #The time the winner of a bid has to claim their prize.
Minimum-Sell-Price: 10 #Minimum amount you can sell an item for.
Max-Beginning-Sell-Price: 1000000 #Max amount you can sell an item for.
Minimum-Bid-Price: 100 #Minimum starting bid.
Max-Beginning-Bid-Price: 1000000 #Maximum starting bid.
Allow-Damaged-Items: False #Allow items that have been damaged.
Category-Page-Opens-First: False #If set to true the categories' page will open when they do /CA.
Feature-Toggle: #Toggle if a feature is on or off.
Selling: true #Able to use the selling part of the auction house.
Bidding: true #Able to use the bidding part of the auction house.
Patches:
Macro-Dupe: true #Turn to false if you have an issue, but it should patch the bug.
Sounds:
Toggle: False #Disable the clicking sound.
Sound: 'CLICK' #Make sure if you use 1.8 or lower you use the 1.8 sound and 1.9 and up use 1.9 sounds. The default sound is 1.8.
#1.8 sounds are found here: http://badbones69.com/javadocs/1.8.8/org/bukkit/Sound.html
#1.9 sounds are found here: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html
GUISettings: #Settings for things in the gui.
SellingItemLore: #The lore on items that are being sold.
- '&7-------------------------'
- '&aClick here to purchase.'
- ''
- '&9Price: &e$%price%'
- '&9Seller: &e%seller%'
- '&7-------------------------'
CurrentLore: #Lore on items that are in your current items GUI.
- '&7-------------------------'
- '&aClick here to cancel.'
- ''
- '&9Price: &e$%price%'
- '&9Expire: &e%time%'
- '&7-------------------------'
Cancelled/ExpiredLore: #Lore on items that are in your canceled/expired GUI.
- '&7-------------------------'
- '&aClick here to return to you.'
- ''
- '&9Full Expire: &e%time%'
- '&7-------------------------'
Bidding: #Lore on Bidding Items.
- '&7-------------------------'
- '&aClick here to bid.'
- ''
- '&9Seller: &e%seller%'
- '&9Current Bid: &e$%topbid%'
- '&9Top Bidder: &e%topbidder%'
- '&9Time Left: &e%time%'
- '&7-------------------------'
Category-Settings:
Armor:
Item: '315'
Toggle: true
Slot: 11
Name: '&6&lArmor'
Lore:
- '&7This category contains all'
- '&7armor that is currently being sold.'
Weapons:
Item: '283'
Toggle: true
Slot: 12
Name: '&6&lWeapons'
Lore:
- '&7This category contains all'
- '&7weapons that are currently being sold.'
Tools:
Item: '285'
Toggle: true
Slot: 13
Name: '&6&lTools'
Lore:
- '&7This category contains all'
- '&7tools that are currently being sold.'
Food:
Item: '322'
Toggle: true
Slot: 14
Name: '&6&lFood'
Lore:
- '&7This category contains all'
- '&7food that is currently being sold.'
Potions:
Item: '373:8227'
Toggle: true
Slot: 15
Name: '&6&lPotions'
Lore:
- '&7This category contains all'
- '&7potions that are currently being sold.'
Blocks:
Item: '2'
Toggle: true
Slot: 16
Name: '&6&lBlocks'
Lore:
- '&7This category contains all'
- '&7blocks that are currently being sold.'
Other:
Item: '371'
Toggle: true
Slot: 17
Name: '&6&lOthers'
Lore:
- '&7This category contains all the'
- '&7other items currently being sold.'
None:
Item: '166'
Toggle: true
Slot: 23
Name: '&6&lNone'
Lore:
- '&7This category contains all'
- '&7items currently being sold.'
OtherSettings: #Other Settings for the GUIs.
SellingItems: #The button for your current items.
Item: '264' #The item that this button is.
Toggle: true #If the item is in the gui or not.
Slot: 46 #The slot it is in. I recommend not changing these. If you do make sure they are still in the bottom row.
Name: '&6Items You are Selling' #Name of the item.
Lore: #Lore of the item.
- '&aClick here to view all the items you'
- '&aare currently selling on the auction.'
Cancelled/ExpiredItems: #The button for Canceled/Expired Items.
Item: '394'
Toggle: true
Slot: 47
Name: '&6Collect Expired / Canceled Items'
Lore:
- '&aClick here to view and collect all of the'
- '&aitems you have canceled or has expired.'
PreviousPage: #The button for Previous Page.
Item: '339'
Toggle: true
Slot: 49
Name: '&6Previous Page'
Lore: { }
Refesh: #The button for Refresh Page.
Item: '175'
Toggle: true
Slot: 50
Name: '&6Refresh Page'
Lore: { }
NextPage: #The button for Next Page.
Item: '339'
Toggle: true
Slot: 51
Name: '&6Next Page'
Lore: { }
Category1: #The button for Next Page.
Item: '54'
Toggle: true
Slot: 52
Name: '&6Categories'
Lore:
- '&bCurrent Category: &6%category%'
- '&aWant to see items in specific categories?'
- '&aClick here to see all categories of items.'
Category2: #The button for Next Page.
Item: '54'
Toggle: true
Slot: 48
Name: '&6Categories'
Lore:
- '&bCurrent Category: &6%category%'
- '&aWant to see items in specific categories?'
- '&aClick here to see all categories of items.'
Bidding/Selling: #Switch between Bidding and Selling.
Selling:
Item: '341'
Toggle: true
Slot: 53
Name: '&6Currently looking at items being sold.'
Lore:
- '&7&l(&6&l!&7&l) &7Click here to see items'
- '&7that you can bid on.'
Bidding:
Item: '378'
Toggle: true
Slot: 53
Name: '&6Currently looking at items that can be bid on.'
Lore:
- '&7&l(&6&l!&7&l) &7Click here to see items'
- '&7that you can buy at a price.'
WhatIsThis: #The info on all the Books buttons.
SellingShop: #The Book in the main shop.
Item: '340'
Toggle: true
Slot: 54
Name: '&6What Is This Page?'
Lore:
- '&aThis is the crazy auctions, here you can'
- '&aput items for sale, and buy items'
- '&athat others have put for sale.'
- ''
- '&aThe auction is also a great place to make'
- '&amoney by selling items that others'
- '&amay be interested in buying.'
BiddingShop: #The Book in the main shop.
Item: '340'
Toggle: true
Slot: 54
Name: '&6What Is This Page?'
Lore:
- '&aThis is the crazy auctions, here you can'
- '&aput items for sale, and bid on items'
- '&athat others have put for sale.'
- ''
- '&aThe bidding auction is also a great place to'
- '&amake money by bidding off items that others'
- '&amay be interested in bidding on.'
CurrentItems: #The Book in the Current items GUI.
Item: '340'
Toggle: true
Slot: 54
Name: '&6What Is This Page?'
Lore:
- '&aThese are your current listings, all of'
- '&athe items you currenty have listed on'
- '&acrazy auctions are displayed here.'
- ''
- '&aYou can cancel and view your listings'
- '&aexpire time here.'
Cancelled/ExpiredItems: #The Book in the Canceled/Expired Items GUI.
Item: '340'
Toggle: true
Slot: 54
Name: '&6What Is This Page?'
Lore:
- '&aThis page houses all of your cancelled and'
- '&aexpired items, when a listings is cancelled'
- '&aor expires you will be able to return that'
- '&aitem back to you from this menu.'
- ''
- '&aJust click on the item and if you have enough'
- '&ainventory space you will receive that item.'
Viewing: #The Book in the Viewing Items GUI.
Item: '340'
Toggle: true
Slot: 50
Name: '&6What Is This Page?'
Lore:
- '&aThis page shows all the items that'
- '&aa player has currently on the bidding'
- '&aand selling market. You can quickly see'
- '&awhat a specific player is selling.'
Categories: #The Book in the Viewing Items GUI.
Item: '340'
Toggle: true
Slot: 54
Name: '&6What Is This Page?'
Lore:
- '&aThis page shows all the categories'
- '&athat you can choose from. When you click'
- '&aa category it will open the gui with only'
- '&aitems that belong to that category.'
Back: #The Back Buttons.
Item: '339'
Slot: 46
Name: '&6Back'
Return: #The Return Buttons.
Item: '390'
Slot: 50
Name: '&6Return All'
Lore:
- '&aClick here to return all cancelled'
- '&aand expired items to your inventory.'
Confirm: #The Confirm Buttons.
Item: '160:5'
Name: '&aConfirm'
Cancel: #The Cancel Buttons.
Item: '160:14'
Name: '&cCancel'
Your-Item: #The item that shows when you try to buy/bid on your item.
Item: '166'
Name: '&cYou Can''t Purchase Your Own Item.'
Cant-Afford: #The item that shows when you can't afford this item.
Item: '166'
Name: '&cYou Can''t Afford This Item.'
Top-Bidder: #The item for when a player is already the top bidder.
Item: '166'
Name: '&cYou are already the top bidder.'
Bidding: #The item in the middle when bidding on an item.
Item: '160:15'
Name: '&7Bidding'
Lore:
- '&7<--&aAdd &cRemove&7-->'
- '&9Your Current Bid: &e$%bid%'
- '&9Current Top Bid: &e$%topbid%'
Bid: #The button for when you want to confirm your bid.
Item: '160:3'
Name: '&bBid Now'
Lore:
- '&7Click here to Bid Now.'
BlackList:
- '7'
- '120'

View File

@ -19,6 +19,8 @@ Settings:
Feature-Toggle: #Toggle if a feature is on or off.
Selling: true #Able to use the selling part of the auction house.
Bidding: true #Able to use the bidding part of the auction house.
Patches:
Macro-Dupe: true #Turn to false if you have an issue, but it should patch the bug.
Sounds:
Toggle: false #Disable the clicking sound.
Sound: 'CLICK' #Make sure if you use 1.8 or lower you use the 1.8 sound and 1.9 and up use 1.9 sounds. The default sound is 1.8.

View File

@ -1,16 +1,12 @@
name: "CrazyAuctions"
main: "${group}.CrazyAuctions"
authors: [BadBones69, RyderBelserion]
version: ${version}
api-version: "1.13"
description: ${description}
softdepend: [Vault]
website: https://modrinth.com/plugin/crazyauctions
name: CrazyAuctions
author: BadBones69
main: com.badbones69.crazyauctions.Main
website: https://www.spigotmc.org/resources/authors/badbones69.9719/
version: ${version}${build.number}
depend: [Vault]
api-version: 1.13
description: A plugin to auction off items globally.
commands:
crazyauctions:
description: Opens the main menu for CrazyAuctions.
ca:
description: Opens the Crazy Auctions GUI.
aliases: [crazyauction, crazyauctions, ah, hdv]