Merge pull request #188 from Euphillya/fix-187

Fix https://github.com/Crazy-Crew/CrazyAuctions/issues/187
This commit is contained in:
Ryder Belserion 2024-11-27 18:39:18 -05:00 committed by GitHub
commit 37459fc720
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 2884 additions and 94 deletions

View File

@ -1,2 +1,26 @@
### Additions:
- Added the shield and the mace to the weapons category.
- Added {page} placeholder to inventory titles that have the ability to have multiple pages
- Previously, this was hard coded and could not be removed.
### Changes:
- Re-coded how all inventories are handled internally which fixed a large chunk of known issues.
- Improved performance with inventory handling by reducing a lot of unnecessary bloat.
- We no longer check the display name, or inventory titles for information we need.
- Clear all caches on player quit.
- Register permissions on startup.
- Updated vital api, which uses a more performant version of the file manager.
### Fixed:
- Issue with file manager not properly loading/reloading files.
- Fixed an issue where you couldn't use hex colors with buttons.
- Fixed an issue where pagination let you keep creating new pages.
- Fixed a spelling mistake in the config.yml, Refesh -> Refresh
- Old configurations will work, but please update in your `config.yml`
- Fixed an issue with blacklist materials.
### What's in the pipeline?
- Configuration overhauls.
- MiniMessage Support.
- Ability to auction custom items.
- Ability to use items as currency.
- Anything on GitHub that is a feature request

123
README.md
View File

@ -1,91 +1,60 @@
<br />
<center><div align="center">
<div align="center">
[![CrazyAuctions](https://raw.githubusercontent.com/RyderBelserion/Assets/main/crazycrew/webp/CrazyAuctionsBanner.webp)](https://modrinth.com/plugin/crazyauctions)
![CrazyAuctions](https://raw.githubusercontent.com/Crazy-Crew/Branding/main/crazyauctions/banner/webp/banner.webp)
[![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]
[![MIT License][license-shield]][license-url]
[![CodeFactor](https://www.codefactor.io/repository/github/crazy-crew/crazyauctions/badge)](https://www.codefactor.io/repository/github/crazy-crew/crazyauctions)
![Paper](https://cdn.jsdelivr.net/gh/intergrav/devins-badges/assets/compact/supported/paper_vector.svg)
![Purpur](https://cdn.jsdelivr.net/gh/intergrav/devins-badges/assets/compact/supported/purpur_vector.svg)
<big>**Auction off your items in style!**</big>
<p align="center">
A crates plugin that offers quality crates with ease!
<br />
<a href="https://docs.crazycrew.us/crazyauctions/home"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="https://github.com/Crazy-Crew/CrazyAuctions/issues/new?assignees=ryderbelserion&labels=bug&projects=&template=bugs.yml&title=%5BBug+Report%5D%3A+">Report Bug</a>
·
<a href="https://github.com/Crazy-Crew/CrazyAuctions/issues/new?assignees=&labels=feature&template=feature_request.md&title=%5BFeature%5D+">Request Feature</a>
·
<a href="https://discord.gg/badbones-s-live-chat-182615261403283459">Get Support</a>
</p>
</div>
<big>**Quick Links**</big><br>
[Request Features](https://github.com/Crazy-Crew/CrazyAuctions/issues)<br>
[Documentation](https://docs.crazycrew.us/docs/category/crazyauctions)<br>
[Developer API](https://docs.crazycrew.us/docs/plugins/crazyauctions/guides/api/intro)<br>
[Report Bugs](https://github.com/Crazy-Crew/CrazyAuctions/issues)<br>
[Trello Board](https://trello.com/b/B9exh23d/crazyauctions)
<big>**Supported Platforms**</big><br>
[![paper software](https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact-minimal/supported/paper_vector.svg)](https://papermc.io/)
[![purpur software](https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact-minimal/supported/purpur_vector.svg)](https://purpurmc.org/)
<big>**Initial Plugin Setup**</big><br>
CrazyAuctions as first install will come with a set of default files such as `config.yml`, `messages.yml`
You can simply edit these files, and configure the looks and settings then do `/crazyauctions reload`<br>
![Features Banner](https://raw.githubusercontent.com/Crazy-Crew/Branding/main/crazyauctions/banner/webp/features.webp)<br>
**Selling/buying/bidding items with ease.**<br>
**Easy to use configurations.**<br>
**Max/min bidding/buying.**<br>
**Customizable category selector.**<br>
**Blacklist items you don't want to be auctioned off.**<br>
**Cancel auctions & retrieve the item afterward.**<br>
**And much more!**<br>
![Support Banner](https://raw.githubusercontent.com/Crazy-Crew/Branding/main/crazyauctions/banner/webp/support.webp)<br>
Are you confused about something? Hop by the Discord and you might just get an answer!<br>
Please head to [crazy-auctions](https://discord.com/channels/182615261403283459/1178545378564509786) with your question and do not cross post.<br>
<!-- 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>
<summary>Support Checklist</summary>
Please check to make sure that your question wasn't asked before, You can use `Ctrl+F` on Discord to look for past conversations.<br>
Describe your issue in detail, Don't just make it a bread crumb trail that has to be questioned out of you.<br>
Plugin Version i.e. `CrazyAuctions 3.3` **LATEST DOES NOT COUNT**<br>
Server Version & Server Type i.e. `Paper 1.21.1` or `Purpur 1.21.1` **LATEST DOES NOT COUNT**<br>
Send any console errors or files you have through https://mclo.gs/ - (We don't own the website, You have to copy the link and send it.)<br>
</details>
### Resource Page
[![Hangar](https://raw.githubusercontent.com/intergrav/devins-badges/v3/assets/compact/available/hangar_46h.png)](https://hangar.papermc.io/CrazyCrew/CrazyAuctions)
[![Modrinth](https://raw.githubusercontent.com/intergrav/devins-badges/v3/assets/compact/available/modrinth_46h.png)](https://modrinth.com/user/plugin/CrazyAuctions)
<!--[![Discord](https://discord.com/api/guilds/182615261403283459/widget.png?style=banner2)](https://discord.gg/badbones-s-live-chat-182615261403283459)<br>-->
[![Discord Invite Button](https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/social/discord-plural_vector.svg)](https://discord.gg/badbones-s-live-chat-182615261403283459)
</div>
## Getting Started
How to get started with contributing / maintaining your own version of CrazyAuctions!
### Prerequisites
A list of things necessary to make sure you can build CrazyAuctions properly.
* Intellij IDEA
* > https://www.jetbrains.com/idea/download/
* Gradle
### Installation
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 clean assemble task.
```gradle
./gradlew clean assemble
```
## Roadmap
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 to the `main` branch to add your feature/fix.
## License
Distributed under the MIT License. See [`LICENSE`](/LICENSE) for more information.
[discord-shield]: https://img.shields.io/discord/182615261403283459.svg?style=flat&logo=appveyor
[discord-url]: https://discord.gg/badbones-s-live-chat-182615261403283459
![CrazyAuctions Statistics](https://bstats.org/signatures/bukkit/CrazyAuctions.svg)
</center>
[contributors-shield]: https://img.shields.io/github/contributors/Crazy-Crew/CrazyAuctions.svg?style=flat&logo=appveyor
[contributors-url]: https://github.com/Crazy-Crew/CrazyAuctions/graphs/contributors
@ -96,6 +65,4 @@ Distributed under the MIT License. See [`LICENSE`](/LICENSE) for more informatio
[issues-shield]: https://img.shields.io/github/issues/Crazy-Crew/CrazyAuctions.svg?style=flat&logo=appveyor
[issues-url]: https://github.com/Crazy-Crew/CrazyAuctions/issues
[license-shield]: https://img.shields.io/github/license/Crazy-Crew/CrazyAuctions.svg?style=flat&logo=appveyor
[license-url]: https://github.com/Crazy-Crew/CrazyAuctions/blob/master/LICENSE
[codefactor-shield]: https://img.shields.io/codefactor/grade/github/crazy-crew/CrazyAuctions/main?style=flat&logo=appveyor
[license-url]: https://github.com/Crazy-Crew/CrazyAuctions/blob/main/LICENSE

View File

@ -5,7 +5,7 @@ plugins {
val buildNumber: String? = System.getenv("BUILD_NUMBER")
rootProject.version = if (buildNumber != null) "${libs.versions.minecraft.get()}-$buildNumber" else "1.6.2"
rootProject.version = if (buildNumber != null) "${libs.versions.minecraft.get()}-$buildNumber" else "1.7"
subprojects.filter { it.name != "api" }.forEach {
it.project.version = rootProject.version

View File

@ -2,9 +2,7 @@ org.gradle.jvmargs = -Xmx3G
org.gradle.daemon = false
org.gradle.parallel = false
group = com.badbones69.crazyauctions
authors = ["Ryderbelserion, Badbones69"]
description = Auction off items in style.
website = https://modrinth.com/plugin/crazyauctions
sources = https://github.com/Crazy-Crew/CrazyAuctions
issues = https://github.com/Crazy-Crew/CrazyAuctions/issues

Binary file not shown.

7
gradlew vendored
View File

@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

94
gradlew.bat vendored Normal file
View File

@ -0,0 +1,94 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -0,0 +1,59 @@
package com.badbones69.crazyauctions.api;
import com.badbones69.crazyauctions.api.enums.Category;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.guis.types.AuctionsMenu;
import com.badbones69.crazyauctions.api.guis.types.CategoriesMenu;
import com.badbones69.crazyauctions.api.guis.types.CurrentMenu;
import com.badbones69.crazyauctions.api.guis.types.ExpiredMenu;
import com.badbones69.crazyauctions.api.guis.types.other.BidMenu;
import com.badbones69.crazyauctions.api.guis.types.other.BuyingMenu;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class GuiManager {
public static void openShop(Player player, ShopType shopType, Category category, int page) {
FileConfiguration config = Files.config.getConfiguration();
new AuctionsMenu(player, shopType, category, config.getString("Settings.GUIName", "&4Crazy &bAuctions&8 #{page}").replaceAll("\\{page}", String.valueOf(page)), 54, page).build();
}
public static void openCategories(Player player, ShopType shopType) {
FileConfiguration config = Files.config.getConfiguration();
new CategoriesMenu(player, shopType, config.getString("Settings.Categories", "N/A"), 54).build();
}
public static void openPlayersCurrentList(final Player player, int page) {
FileConfiguration config = Files.config.getConfiguration();
new CurrentMenu(player, config.getString("Settings.Players-Current-Items", "N/A"), 54, page).build();
}
public static void openPlayersExpiredList(Player player, int page) {
FileConfiguration config = Files.config.getConfiguration();
new ExpiredMenu(player, config.getString("Settings.Cancelled/Expired-Items", "&8Cancelled/Expired Listings #{page}").replaceAll("\\{page}", String.valueOf(page)), 54, page).build();
}
public static void openBuying(Player player, String id, AuctionItem auction) {
final FileConfiguration config = Files.config.getConfiguration();
new BuyingMenu(auction, player, id, config.getString("Settings.Buying-Item", "N/A")).build();
}
public static void openBidding(Player player, String id, AuctionItem auction) {
FileConfiguration config = Files.config.getConfiguration();
new BidMenu(auction, player, id, config.getString("Settings.Bidding-On-Item", "N/A")).build();
}
public static void openViewer(Player player, String other, int page) {
FileConfiguration config = Files.config.getConfiguration();
new AuctionsMenu(player, other, config.getString("Settings.GUIName", "&4Crazy &bAuctions&8 #{page}").replaceAll("\\{page}", String.valueOf(page)), 54, page).build();
}
}

View File

@ -0,0 +1,52 @@
package com.badbones69.crazyauctions.api.enums.misc;
import com.badbones69.crazyauctions.CrazyAuctions;
import com.ryderbelserion.vital.paper.api.files.FileManager;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import java.io.File;
public enum Files {
config("config.yml"),
messages("messages.yml"),
//test_file("test-file.yml"),
data("data.yml");
private final String fileName;
private final String strippedName;
private @NotNull final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private @NotNull final FileManager fileManager = this.plugin.getFileManager();
/**
* A constructor to build a file
*
* @param fileName the name of the file
*/
Files(final String fileName) {
this.fileName = fileName;
this.strippedName = this.fileName.replace(".yml", "");
}
public final YamlConfiguration getConfiguration() {
return this.fileManager.getFile(this.fileName).getConfiguration();
}
public final String getStrippedName() {
return this.strippedName;
}
public final String getFileName() {
return this.fileName;
}
public void reload() {
this.fileManager.addFile(new File(this.plugin.getDataFolder(), this.fileName));
}
public void save() {
this.fileManager.saveFile(this.fileName);
}
}

View File

@ -0,0 +1,42 @@
package com.badbones69.crazyauctions.api.enums.misc;
import com.badbones69.crazyauctions.CrazyAuctions;
import org.bukkit.NamespacedKey;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("rawtypes")
public enum Keys {
// contains the store id
auction_store_id("auction_store_id", PersistentDataType.INTEGER),
// this contains, the number for the item which can be found in the data.yml
auction_number("auction_number", PersistentDataType.STRING),
// any button in the gui
auction_button("auction_button", PersistentDataType.STRING),
auction_uuid("auction_uuid", PersistentDataType.STRING),
// contains the auction item price
auction_price("auction_price", PersistentDataType.INTEGER);
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private final String NamespacedKey;
private final PersistentDataType type;
Keys(@NotNull final String NamespacedKey, @NotNull final PersistentDataType type) {
this.NamespacedKey = NamespacedKey;
this.type = type;
}
public @NotNull final NamespacedKey getNamespacedKey() {
return new NamespacedKey(this.plugin, this.plugin.getName().toLowerCase() + "_" + this.NamespacedKey);
}
public @NotNull final PersistentDataType getType() {
return this.type;
}
}

View File

@ -0,0 +1,111 @@
package com.badbones69.crazyauctions.api.enums.other;
import com.badbones69.crazyauctions.CrazyAuctions;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;
import java.util.HashMap;
import java.util.Map;
public enum Permissions {
reload("reload", "Access to /crazyauctions reload", PermissionDefault.OP, false),
help("help", "Access to /crazyauctions help", PermissionDefault.TRUE, false),
view("view", "Access to /crazyauctions view", PermissionDefault.TRUE, false),
expired("expired", "Access to /crazyauctions expired", PermissionDefault.TRUE, false),
listed("listed", "Access to /crazyauctions listed", PermissionDefault.TRUE, false),
sell("sell", "Access to /crazyauctions sell", PermissionDefault.TRUE, false),
bid("bid", "Access to /crazyauctions bid", PermissionDefault.TRUE, false),
use("use", "Access to /crazyauctions", PermissionDefault.TRUE, false),
bypass("bypass", "Bypasses most plugin restrictions", PermissionDefault.OP, true),
access("access", "Access other portions of the plugin", PermissionDefault.TRUE, true),
player_wildcard("player.*", "Access multiple player based commands", PermissionDefault.FALSE, new HashMap<>() {{
put("crazyauctions.bid", true);
put("crazyauctions.sell", true);
put("crazyauctions.access", true);
put("crazyauctions.view", true);
}}, true),
admin_wildcard("admin", "Access multiple admin based commands", PermissionDefault.FALSE, new HashMap<>() {{
put("crazyauctions.player.*", true);
put("crazyauctions.reload", true);
put("crazyauctions.bypass", true);
put("crazyauctions.view", true);
}}, true);
private final String node;
private final String description;
private final PermissionDefault isDefault;
private final Map<String, Boolean> children;
private final boolean register;
private final PluginManager manager = CrazyAuctions.getPlugin().getServer().getPluginManager();
Permissions(String node, String description, PermissionDefault isDefault, Map<String, Boolean> children, boolean register) {
this.node = node;
this.description = description;
this.isDefault = isDefault;
this.children = children;
this.register = register;
}
Permissions(String node, String description, PermissionDefault isDefault, boolean register) {
this.node = node;
this.description = description;
this.isDefault = isDefault;
this.children = new HashMap<>();
this.register = register;
}
public final String getNode() {
return "crazyauctions." + this.node;
}
public final boolean shouldRegister() {
return this.register;
}
public final String getDescription() {
return this.description;
}
public final PermissionDefault isDefault() {
return this.isDefault;
}
public final Map<String, Boolean> getChildren() {
return this.children;
}
public final boolean hasPermission(final Player player) {
return player.hasPermission(getNode());
}
public final boolean isValid() {
return this.manager.getPermission(getNode()) != null;
}
public final Permission getPermission() {
return new Permission(getNode(), getDescription(), isDefault(), getChildren().isEmpty() ? null : getChildren());
}
public void registerPermission() {
if (isValid()) return;
this.manager.addPermission(getPermission());
}
public void unregisterPermission() {
if (!isValid()) return;
this.manager.removePermission(getNode());
}
}

View File

@ -0,0 +1,190 @@
package com.badbones69.crazyauctions.api.guis;
import com.badbones69.crazyauctions.CrazyAuctions;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.CrazyManager;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.tasks.UserManager;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import com.badbones69.crazyauctions.tasks.objects.ExpiredItem;
import com.ryderbelserion.vital.paper.api.enums.Support;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Server;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
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.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public abstract class Holder implements InventoryHolder, Listener {
protected final CrazyAuctions plugin = CrazyAuctions.getPlugin();
protected final CrazyManager crazyManager = this.plugin.getCrazyManager();
protected final UserManager userManager = this.plugin.getUserManager();
protected final Server server = this.plugin.getServer();
protected Inventory inventory;
protected ShopType shopType;
protected Player player;
protected String title;
protected int size;
protected int page;
public Holder(final Player player, final ShopType shopType, final String title, final int size, final int page) {
this.player = player;
this.shopType = shopType;
this.title = title;
this.size = size;
this.page = page;
final String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(this.player, this.title) : this.title;
this.inventory = this.server.createInventory(this, this.size, Methods.color(inventoryTitle));
}
public Holder(final Player player, final ShopType shopType, final String title, final int size) {
this(player, shopType, title, size, 1);
}
public Holder(final Player player, final String title, final int size, final int page) {
this(player, null, title, size, page);
}
public Holder(Player player, String title, int size) {
this(player, null, title, size, 1);
}
public Holder() {}
public abstract Holder build();
public abstract void run(InventoryClickEvent event);
public void setSize(final int size) {
this.size = size;
}
public final int getSize() {
return this.size - 9;
}
public void setPage(int page) {
if (page <= 0) page = 1;
this.page = page;
}
public void nextPage() {
setPage(getPage() + 1);
}
public void backPage() {
setPage(getPage() - 1);
}
public final int getPage() {
return this.page;
}
public final List<ExpiredItem> getPageItem(final List<ExpiredItem> list, int page, final int size) {
List<ExpiredItem> items = new ArrayList<>();
if (page <= 0) page = 1;
int index = page * size - size;
int endIndex = index >= list.size() ? list.size() - 1 : index + size;
for (;index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
for (;items.isEmpty(); page--) {
if (page <= 0) break;
index = page * size - size;
endIndex = index >= list.size() ? list.size() - 1 : index + size;
for (; index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
}
return items;
}
public final List<AuctionItem> getPageItems(final List<AuctionItem> list, int page, final int size) {
List<AuctionItem> items = new ArrayList<>();
if (page <= 0) page = 1;
int index = page * size - size;
int endIndex = index >= list.size() ? list.size() - 1 : index + size;
for (;index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
for (;items.isEmpty(); page--) {
if (page <= 0) break;
index = page * size - size;
endIndex = index >= list.size() ? list.size() - 1 : index + size;
for (; index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
}
return items;
}
public final int getExpiredMaxPages(final List<ExpiredItem> list) {
final int size = list.size();
return (int) Math.ceil((double) size / getSize());
}
public final int getMaxPage(final List<AuctionItem> list) {
final int size = list.size();
return (int) Math.ceil((double) size / getSize());
}
@EventHandler
public void onPlayerClick(InventoryClickEvent event) {
run(event);
}
@Override
public @NotNull final Inventory getInventory() {
return this.inventory;
}
public void click(final Player player) {
final FileConfiguration config = Files.config.getConfiguration();
if (config.getBoolean("Settings.Sounds.Toggle", false)) {
final String sound = config.getString("Settings.Sounds.Sound", "UI_BUTTON_CLICK");
try {
player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1);
} catch (Exception e) {
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1F, 1F);
}
}
}
}

View File

@ -0,0 +1,55 @@
package com.badbones69.crazyauctions.api.guis;
import com.badbones69.crazyauctions.api.enums.Category;
import com.badbones69.crazyauctions.api.enums.ShopType;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class HolderManager {
private static final Map<UUID, Integer> bidding = new HashMap<>();
private static final Map<UUID, ShopType> shopTypes = new HashMap<>();
private static final Map<UUID, Category> shopCategory = new HashMap<>();
public static void addShopCategory(final Player player, final Category category) {
shopCategory.put(player.getUniqueId(), category);
}
public static void removeShopCategory(final Player player) {
shopCategory.remove(player.getUniqueId());
}
public static Category getShopCategory(final Player player) {
return shopCategory.get(player.getUniqueId());
}
public static void addBidding(final Player player, final int amount) {
bidding.put(player.getUniqueId(), amount);
}
public static void removeBidding(final Player player) {
bidding.remove(player.getUniqueId());
}
public static int getBidding(final Player player) {
return bidding.get(player.getUniqueId());
}
public static boolean containsBidding(final Player player) {
return bidding.containsKey(player.getUniqueId());
}
public static void addShopType(final Player player, final ShopType shopType) {
shopTypes.put(player.getUniqueId(), shopType);
}
public static void removeShopType(final Player player) {
shopTypes.remove(player.getUniqueId());
}
public static ShopType getShopType(final Player player) {
return shopTypes.get(player.getUniqueId());
}
}

View File

@ -0,0 +1,381 @@
package com.badbones69.crazyauctions.api.guis.types;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.Category;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import com.badbones69.crazyauctions.api.guis.Holder;
import com.badbones69.crazyauctions.api.guis.HolderManager;
import com.badbones69.crazyauctions.api.GuiManager;
import com.badbones69.crazyauctions.currency.VaultSupport;
import com.badbones69.crazyauctions.tasks.InventoryManager;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable;
import io.papermc.paper.persistence.PersistentDataContainerView;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class AuctionsMenu extends Holder {
private List<AuctionItem> items;
private List<String> options;
private int maxPages;
private FileConfiguration config;
private FileConfiguration data;
private Category category;
public AuctionsMenu(final Player player, final ShopType shopType, final Category category, final String title, final int size, final int page) {
super(player, shopType, title, size, page);
this.items = new ArrayList<>();
this.options = new ArrayList<>();
this.config = Files.config.getConfiguration();
this.data = Files.data.getConfiguration();
if (!this.data.contains("Items")) {
this.data.set("Items.Clear", null);
Files.data.save();
}
if (category != null) {
HolderManager.addShopCategory(player, this.category = category);
}
}
private String target;
public AuctionsMenu(final Player player, final String target, final String title, final int size, final int page) {
this(player, null, null, title, size, page);
this.target = target;
}
public AuctionsMenu() {}
@Override
public final Holder build() {
if (this.target != null) {
this.options.add("WhatIsThis.Viewing");
} else {
this.options.addAll(List.of(
"SellingItems",
"Cancelled/ExpiredItems",
"PreviousPage",
"Refresh",
"Refesh",
"NextPage",
"Category1",
"Category2"
));
}
calculateItems();
HolderManager.addShopType(this.player, this.shopType);
switch (this.shopType) {
case SELL -> {
if (this.crazyManager.isSellingEnabled()) {
this.options.add("Bidding/Selling.Selling");
}
this.options.add("WhatIsThis.SellingShop");
}
case BID -> {
if (this.crazyManager.isBiddingEnabled()) {
this.options.add("Bidding/Selling.Bidding");
}
this.options.add("WhatIsThis.BiddingShop");
}
}
for (final String key : this.options) {
if (!this.config.contains("Settings.GUISettings.OtherSettings." + key)) {
continue;
}
if (!this.config.getBoolean("Settings.GUISettings.OtherSettings." + key + ".Toggle", true)) {
continue;
}
final String id = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Item");
final String name = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Name");
final List<String> lore = new ArrayList<>();
final int slot = this.config.getInt("Settings.GUISettings.OtherSettings." + key + ".Slot");
final String cName = Methods.color(this.config.getString("Settings.GUISettings.Category-Settings." + HolderManager.getShopCategory(this.player).getName() + ".Name"));
final ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1);
if (this.config.contains("Settings.GUISettings.OtherSettings." + key + ".Lore")) {
for (final String line : this.config.getStringList("Settings.GUISettings.OtherSettings." + key + ".Lore")) {
lore.add(line.replace("%Category%", cName).replace("%category%", cName));
}
}
switch (key) {
case "NextPage" -> this.inventory.setItem(slot - 1, InventoryManager.getNextButton(this.player, this).setLore(lore).build());
case "PreviousPage" -> this.inventory.setItem(slot - 1, InventoryManager.getBackButton(this.player, this).setLore(lore).build());
default -> this.inventory.setItem(slot - 1, itemBuilder.setLore(lore).addString(key, Keys.auction_button.getNamespacedKey()).build());
}
}
for (final AuctionItem item : getPageItems(this.items, getPage(), getSize())) {
int slot = this.inventory.firstEmpty();
this.inventory.setItem(slot, item.getActiveItem(this.shopType).build());
}
this.player.openInventory(this.inventory);
return this;
}
@Override
public void run(InventoryClickEvent event) {
if (!(event.getInventory().getHolder(false) instanceof AuctionsMenu menu)) return;
event.setCancelled(true);
final int slot = event.getSlot();
final Inventory inventory = menu.getInventory();
if (slot > inventory.getSize()) return;
if (event.getCurrentItem() == null) return;
final ItemStack itemStack = event.getCurrentItem();
if (itemStack == null) return;
final PersistentDataContainerView container = itemStack.getPersistentDataContainer();
final Player player = (Player) event.getWhoClicked();
FileConfiguration config = Files.config.getConfiguration();
if (container.has(Keys.auction_button.getNamespacedKey())) {
String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, menu.target == null ? "Refresh" : "");
if (menu.target == null && !type.isEmpty()) {
switch (type) {
case "Your-Item", "Top-Bidder", "Cant-Afford" -> {
menu.click(player);
return;
}
case "NextPage" -> {
menu.click(player);
if (menu.getPage() >= menu.maxPages) {
return;
}
menu.nextPage();
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), menu.getPage());
return;
}
case "PreviousPage" -> {
menu.click(player);
final int page = menu.getPage();
if (page <= 1) {
return;
}
menu.backPage();
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), menu.getPage());
return;
}
case "Refesh", "Refresh" -> {
menu.click(player);
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), menu.getPage());
return;
}
case "Bidding/Selling.Selling" -> {
menu.click(player);
GuiManager.openShop(player, ShopType.BID, HolderManager.getShopCategory(player), 1);
return;
}
case "Bidding/Selling.Bidding" -> {
menu.click(player);
GuiManager.openShop(player, ShopType.SELL, HolderManager.getShopCategory(player), 1);
return;
}
case "Cancelled/ExpiredItems" -> {
menu.click(player);
GuiManager.openPlayersExpiredList(player, 1);
return;
}
case "SellingItems" -> {
menu.click(player);
GuiManager.openPlayersCurrentList(player, 1);
return;
}
case "Category1", "Category2" -> {
menu.click(player);
GuiManager.openCategories(player, HolderManager.getShopType(player));
return;
}
}
}
}
final UUID uuid = player.getUniqueId();
final String target_uuid = container.getOrDefault(Keys.auction_uuid.getNamespacedKey(), PersistentDataType.STRING, "");
if (target_uuid.isEmpty()) return;
final AuctionItem auction = this.userManager.getAuctionItemById(UUID.fromString(target_uuid), container.getOrDefault(Keys.auction_store_id.getNamespacedKey(), PersistentDataType.STRING, ""));
if (auction == null) return;
if (uuid.toString().equalsIgnoreCase(auction.getUuid().toString())) {
String itemName = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1);
if (config.contains("Settings.GUISettings.OtherSettings.Your-Item.Lore")) {
itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings.Your-Item.Lore"));
}
inventory.setItem(slot, itemBuilder.build());
menu.click(player);
new FoliaRunnable(this.plugin.getServer().getGlobalRegionScheduler()) {
@Override
public void run() {
inventory.setItem(slot, itemStack);
}
}.runDelayed(this.plugin, 3 * 20);
return;
}
final long price = auction.getPrice();
if (price == 0L) return;
final VaultSupport support = this.plugin.getSupport();
if (support.getMoney(player) < price) {
String itemName = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1);
if (config.contains("Settings.GUISettings.OtherSettings.Cant-Afford.Lore")) {
itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings.Cant-Afford.Lore"));
}
inventory.setItem(slot, itemBuilder.build());
menu.click(player);
new FoliaRunnable(this.plugin.getServer().getGlobalRegionScheduler()) {
@Override
public void run() {
inventory.setItem(slot, itemStack);
}
}.runDelayed(this.plugin, 3 * 20);
return;
}
final String auction_id = auction.getId();
if (auction.isBiddable()) {
if (uuid.toString().equalsIgnoreCase(auction.getUuid().toString())) {
String itemName = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1);
if (config.contains("Settings.GUISettings.OtherSettings.Top-Bidder.Lore")) {
itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings.Top-Bidder.Lore"));
}
inventory.setItem(slot, itemBuilder.build());
menu.click(player);
new FoliaRunnable(this.plugin.getServer().getGlobalRegionScheduler()) {
@Override
public void run() {
inventory.setItem(slot, itemStack);
}
}.runDelayed(this.plugin, 3 * 20);
return;
}
menu.click(player);
GuiManager.openBidding(player, auction_id, auction);
return;
}
menu.click(player);
GuiManager.openBuying(player, auction_id, auction);
}
public void calculateItems() {
this.userManager.getAuctions().forEach(((uuid, auctions) -> auctions.forEach(auction -> {
final ItemBuilder itemBuilder = auction.getActiveItem(this.shopType);
if (this.category != null && this.category != Category.NONE && !this.category.getItems().contains(itemBuilder.getMaterial())) {
return;
}
this.items.add(auction);
})));
this.maxPages = getMaxPage(this.items == null ? new ArrayList<>() : this.items);
}
}

View File

@ -0,0 +1,113 @@
package com.badbones69.crazyauctions.api.guis.types;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.Category;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import com.badbones69.crazyauctions.api.guis.Holder;
import com.badbones69.crazyauctions.api.guis.HolderManager;
import com.badbones69.crazyauctions.api.GuiManager;
import io.papermc.paper.persistence.PersistentDataContainerView;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.List;
public class CategoriesMenu extends Holder {
private List<String> options;
private FileConfiguration config;
public CategoriesMenu(final Player player, final ShopType shopType, final String title, final int size) {
super(player, shopType, title, size);
this.options = new ArrayList<>();
this.config = Files.config.getConfiguration();
}
public CategoriesMenu() {}
@Override
public final Holder build() {
this.options.addAll(List.of(
"OtherSettings.Back",
"OtherSettings.WhatIsThis.Categories",
"Category-Settings.Armor",
"Category-Settings.Weapons",
"Category-Settings.Tools",
"Category-Settings.Food",
"Category-Settings.Potions",
"Category-Settings.Blocks",
"Category-Settings.Other",
"Category-Settings.None"
));
for (final String key : this.options) {
if (!this.config.contains("Settings.GUISettings." + key)) {
continue;
}
if (!this.config.getBoolean("Settings.GUISettings." + key + ".Toggle", true)) {
continue;
}
String id = this.config.getString("Settings.GUISettings." + key + ".Item");
String name = this.config.getString("Settings.GUISettings." + key + ".Name");
int slot = this.config.getInt("Settings.GUISettings." + key + ".Slot");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).addString(key, Keys.auction_button.getNamespacedKey()).setAmount(1);
if (this.config.contains("Settings.GUISettings." + key + ".Lore")) {
itemBuilder.setLore(this.config.getStringList("Settings.GUISettings." + key + ".Lore"));
}
this.inventory.setItem(slot - 1, itemBuilder.build());
}
HolderManager.addShopType(this.player, this.shopType);
this.player.openInventory(this.inventory);
return this;
}
@Override
public void run(InventoryClickEvent event) {
if (!(event.getInventory().getHolder(false) instanceof CategoriesMenu menu)) return;
event.setCancelled(true);
final int slot = event.getSlot();
final Inventory inventory = menu.getInventory();
if (slot > inventory.getSize()) return;
if (event.getCurrentItem() == null) return;
final ItemStack itemStack = event.getCurrentItem();
if (itemStack == null) return;
final PersistentDataContainerView container = itemStack.getPersistentDataContainer();
if (!container.has(Keys.auction_button.getNamespacedKey())) return;
final Player player = (Player) event.getWhoClicked();
final String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, "Category-Settings.None");
final Category category = Category.getFromName(type.replace("Category-Settings.", ""));
GuiManager.openShop(player, HolderManager.getShopType(player), category, 1);
menu.click(player);
}
}

View File

@ -0,0 +1,180 @@
package com.badbones69.crazyauctions.api.guis.types;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.Messages;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import com.badbones69.crazyauctions.api.guis.Holder;
import com.badbones69.crazyauctions.api.guis.HolderManager;
import com.badbones69.crazyauctions.api.GuiManager;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import io.papermc.paper.persistence.PersistentDataContainerView;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class CurrentMenu extends Holder {
private FileConfiguration config;
private List<String> options;
private List<AuctionItem> items;
private int maxPages;
public CurrentMenu(final Player player, final String title, final int size, final int page) {
super(player, title, size, page);
this.config = Files.config.getConfiguration();
this.options = new ArrayList<>();
this.items = new ArrayList<>();
}
public CurrentMenu() {}
@Override
public final Holder build() {
this.options.addAll(List.of(
"Back",
"PreviousPage",
"NextPage",
"WhatIsThis.CurrentItems"
));
calculateItems();
for (final String key : this.options) {
if (!this.config.contains("Settings.GUISettings.OtherSettings." + key)) {
continue;
}
if (!this.config.getBoolean("Settings.GUISettings.OtherSettings." + key + ".Toggle", true)) {
continue;
}
String id = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Item");
String name = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Name");
int slot = this.config.getInt("Settings.GUISettings.OtherSettings." + key + ".Slot");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).addString(key, Keys.auction_button.getNamespacedKey()).setAmount(1);
if (this.config.contains("Settings.GUISettings.OtherSettings." + key + ".Lore")) {
itemBuilder.setLore(this.config.getStringList("Settings.GUISettings.OtherSettings." + key + ".Lore"));
}
this.inventory.setItem(slot - 1, itemBuilder.build());
}
for (final AuctionItem item : getPageItems(this.items, getPage(), getSize())) {
int slot = this.inventory.firstEmpty();
this.inventory.setItem(slot, item.getCurrentItem().build());
}
this.player.openInventory(this.inventory);
return this;
}
@Override
public void run(InventoryClickEvent event) {
if (!(event.getInventory().getHolder(false) instanceof CurrentMenu menu)) return;
event.setCancelled(true);
final int slot = event.getSlot();
final Inventory inventory = menu.getInventory();
if (slot > inventory.getSize()) return;
if (event.getCurrentItem() == null) return;
final ItemStack itemStack = event.getCurrentItem();
if (itemStack == null) return;
final PersistentDataContainerView container = itemStack.getPersistentDataContainer();
final Player player = (Player) event.getWhoClicked();
if (container.has(Keys.auction_button.getNamespacedKey())) {
final String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, "");
if (!type.isEmpty()) {
switch (type) {
case "NextPage" -> {
menu.click(player);
if (menu.getPage() >= menu.maxPages) {
return;
}
menu.nextPage();
GuiManager.openPlayersCurrentList(player, menu.getPage());
return;
}
case "PreviousPage" -> {
menu.click(player);
final int page = menu.getPage();
if (page <= 1) {
return;
}
menu.backPage();
GuiManager.openPlayersCurrentList(player, menu.getPage());
return;
}
case "Back" -> {
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
menu.click(player);
return;
}
}
}
}
// return early, fixes npe
if (!container.has(Keys.auction_store_id.getNamespacedKey())) {
return;
}
final UUID uuid = player.getUniqueId();
final AuctionItem auction = this.userManager.getAuctionItemById(uuid, container.getOrDefault(Keys.auction_store_id.getNamespacedKey(), PersistentDataType.STRING, ""));
if (auction == null) return;
this.userManager.addExpiredItem(player, auction);
player.sendMessage(Messages.CANCELLED_ITEM.getMessage(player));
menu.click(player);
GuiManager.openPlayersCurrentList(player, menu.getPage());
}
public void calculateItems() {
final UUID uuid = this.player.getUniqueId();
if (this.userManager.hasAuction(uuid)) {
this.items = this.userManager.getAuctions(uuid);
}
this.maxPages = getMaxPage(this.items);
}
}

View File

@ -0,0 +1,245 @@
package com.badbones69.crazyauctions.api.guis.types;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.Messages;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import com.badbones69.crazyauctions.api.guis.Holder;
import com.badbones69.crazyauctions.api.guis.HolderManager;
import com.badbones69.crazyauctions.api.GuiManager;
import com.badbones69.crazyauctions.tasks.InventoryManager;
import com.badbones69.crazyauctions.tasks.objects.ExpiredItem;
import io.papermc.paper.persistence.PersistentDataContainerView;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class ExpiredMenu extends Holder {
private List<ExpiredItem> items;
private List<String> options;
private FileConfiguration config;
private int maxPages;
public ExpiredMenu(final Player player, final String title, final int size, final int page) {
super(player, title, size, page);
this.items = new ArrayList<>();
this.options = new ArrayList<>();
this.config = Files.config.getConfiguration();
}
public ExpiredMenu() {}
@Override
public final Holder build() {
this.options.addAll(List.of(
"Back",
"PreviousPage",
"Return",
"NextPage",
"WhatIsThis.Cancelled/ExpiredItems"
));
final UUID uuid = this.player.getUniqueId();
if (this.userManager.hasExpiredItem(uuid)) {
this.items = this.userManager.getExpiredItems(uuid);
}
this.maxPages = getExpiredMaxPages(this.items == null ? new ArrayList<>() : this.items);
for (final String key : this.options) {
if (!this.config.contains("Settings.GUISettings.OtherSettings." + key)) {
continue;
}
if (!this.config.getBoolean("Settings.GUISettings.OtherSettings." + key + ".Toggle", true)) {
continue;
}
String id = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Item");
String name = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Name");
int slot = this.config.getInt("Settings.GUISettings.OtherSettings." + key + ".Slot");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1);
if (this.config.contains("Settings.GUISettings.OtherSettings." + key + ".Lore")) {
itemBuilder.setLore(this.config.getStringList("Settings.GUISettings.OtherSettings." + key + ".Lore"));
}
switch (key) {
case "NextPage" -> this.inventory.setItem(slot - 1, InventoryManager.getNextButton(this.player, this).build());
case "PreviousPage" -> this.inventory.setItem(slot - 1, InventoryManager.getBackButton(this.player, this).build());
default -> this.inventory.setItem(slot - 1, itemBuilder.addString(key, Keys.auction_button.getNamespacedKey()).build());
}
}
for (final ExpiredItem item : getPageItem(this.items, getPage(), getSize())) {
int slot = this.inventory.firstEmpty();
this.inventory.setItem(slot, item.getExpiredItem().build());
}
this.player.openInventory(this.inventory);
return this;
}
@Override
public void run(InventoryClickEvent event) {
if (!(event.getInventory().getHolder(false) instanceof ExpiredMenu menu)) return;
event.setCancelled(true);
final int slot = event.getSlot();
final Inventory inventory = menu.getInventory();
if (slot > inventory.getSize()) return;
if (event.getCurrentItem() == null) return;
final ItemStack itemStack = event.getCurrentItem();
if (itemStack == null) return;
final PersistentDataContainerView container = itemStack.getPersistentDataContainer();
final Player player = (Player) event.getWhoClicked();
if (container.has(Keys.auction_button.getNamespacedKey())) {
final String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, "");
if (type.isEmpty()) return;
switch (type) {
case "Back" -> {
menu.click(player);
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
return;
}
case "PreviousPage" -> {
menu.click(player);
final int page = menu.getPage();
if (page > 1 && page <= menu.maxPages) {
return;
}
menu.backPage();
GuiManager.openPlayersExpiredList(player, menu.getPage());
return;
}
case "NextPage" -> {
menu.click(player);
if (menu.getPage() >= menu.maxPages) {
return;
}
menu.nextPage();
GuiManager.openPlayersExpiredList(player, menu.getPage());
return;
}
case "Return" -> {
if (Methods.isInvFull(player)) { // run this first obviously, just because
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
return;
}
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("expired_auctions");
if (section == null) return;
final ConfigurationSection player_section = section.getConfigurationSection(player.getUniqueId().toString());
if (player_section == null) return;
final Inventory player_inventory = player.getInventory();
for (final String key : section.getKeys(false)) {
if (Methods.isInvFull(player)) { // run this here obviously as well
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
break;
}
final ConfigurationSection auction_section = section.getConfigurationSection(key);
if (auction_section == null) continue;
final ItemStack auction_item = Methods.fromBase64(auction_section.getString("item"));
if (auction_item == null) continue;
player_inventory.addItem(auction_item);
}
this.userManager.removeExpiredItems(player);
Files.data.save();
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage(player));
menu.click(player);
GuiManager.openPlayersExpiredList(player, menu.getPage());
return;
}
}
}
if (!container.has(Keys.auction_store_id.getNamespacedKey())) { // do not run, if there is no key.
return;
}
if (Methods.isInvFull(player)) { // run this here obviously as well
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
return;
}
final UUID uuid = player.getUniqueId();
final ExpiredItem auction = this.userManager.getExpiredItemById(uuid, container.getOrDefault(Keys.auction_store_id.getNamespacedKey(), PersistentDataType.STRING, ""));
if (auction == null) return;
player.getInventory().addItem(auction.asItemStack());
this.userManager.removeExpiredItem(auction);
Files.data.save();
menu.click(player);
GuiManager.openPlayersExpiredList(player, menu.getPage());
}
}

View File

@ -0,0 +1,242 @@
package com.badbones69.crazyauctions.api.guis.types.other;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.Messages;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import com.badbones69.crazyauctions.api.events.AuctionNewBidEvent;
import com.badbones69.crazyauctions.api.guis.Holder;
import com.badbones69.crazyauctions.api.guis.HolderManager;
import com.badbones69.crazyauctions.api.GuiManager;
import com.badbones69.crazyauctions.currency.VaultSupport;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import io.papermc.paper.persistence.PersistentDataContainerView;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BidMenu extends Holder {
private FileConfiguration config;
private FileConfiguration data;
private AuctionItem auction;
private long current_bid = 0;
private String id;
public BidMenu(final AuctionItem auction, final Player player, final String id, final String title) {
super(player, title, 27);
this.auction = auction;
this.config = Files.config.getConfiguration();
this.data = Files.data.getConfiguration();
this.id = id;
}
public BidMenu() {}
@Override
public final Holder build() {
if (!this.data.contains("active_auctions." + this.auction.getUuid() + "." + this.id)) {
GuiManager.openShop(this.player, ShopType.BID, HolderManager.getShopCategory(this.player), 1);
this.player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(this.player));
this.userManager.removeAuctionItem(this.auction); // remove auction item, as it's not in the active_auctions
return this;
}
final ItemStack item = this.auction.getActiveItem(ShopType.BID).getItemStack();
final ItemBuilder builder = new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setAmount(1);
final NamespacedKey auction_button = Keys.auction_button.getNamespacedKey();
final NamespacedKey auction_price = Keys.auction_price.getNamespacedKey();
this.inventory.setItem(9, builder.addString("+1", auction_button).addInteger(1, auction_price).setName("&a+1").build());
this.inventory.setItem(10, builder.addString("+10", auction_button).addInteger(10, auction_price).setName("&a+10").build());
this.inventory.setItem(11, builder.addString("+100", auction_button).addInteger(100, auction_price).setName("&a+100").build());
this.inventory.setItem(12, builder.addString("+1000", auction_button).addInteger(1000, auction_price).setName("&a+1000").build());
this.inventory.setItem(14, builder.addString("-1000", auction_button).addInteger(-1000, auction_price).setName("&c-1000").build());
this.inventory.setItem(15, builder.addString("-100", auction_button).addInteger(-100, auction_price).setName("&c-100").build());
this.inventory.setItem(16, builder.addString("-10", auction_button).addInteger(-10, auction_price).setName("&c-10").build());
this.inventory.setItem(17, builder.addString("-1", auction_button).addInteger(-1, auction_price).setName("&c-1").build());
this.inventory.setItem(13, getGlass(null));
this.inventory.setItem(22, new ItemBuilder().setMaterial(this.config.getString("Settings.GUISettings.OtherSettings.Bid.Item")).setAmount(1).addString("bid_item", auction_button)
.setName(this.config.getString("Settings.GUISettings.OtherSettings.Bid.Name")).setLore(this.config.getStringList("Settings.GUISettings.OtherSettings.Bid.Lore")).build());
this.inventory.setItem(4, item);
this.player.openInventory(this.inventory);
return this;
}
@Override
public void run(InventoryClickEvent event) {
if (!(event.getInventory().getHolder(false) instanceof BidMenu bidMenu)) return;
event.setCancelled(true);
final int slot = event.getSlot();
final Inventory inventory = bidMenu.getInventory();
if (slot > inventory.getSize()) return;
if (event.getCurrentItem() == null) return;
final ItemStack itemStack = event.getCurrentItem();
if (itemStack == null) return;
final PersistentDataContainerView container = itemStack.getPersistentDataContainer();
if (!container.has(Keys.auction_button.getNamespacedKey())) return;
final String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, "");
if (type.isEmpty()) return;
final Player player = bidMenu.player;
final AuctionItem auction = this.userManager.getAuctionItemById(bidMenu.auction.getUuid(), bidMenu.auction.getStoreID());
if (auction == null) { // if auction is null, someone else bid it. or the person cancelled it
GuiManager.openShop(player, ShopType.BID, HolderManager.getShopCategory(player), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
return;
}
switch (type) {
case "bid_item" -> {
final VaultSupport support = this.plugin.getSupport();
final long top_bid = auction.getTopBid();
final long money = support.getMoney(player);
final String topBidder = auction.getBidderName();
if (money < top_bid) {
final Map<String, String> placeholders = new HashMap<>();
placeholders.put("%Money_Needed%", String.valueOf(top_bid - money));
placeholders.put("%money_needed%", String.valueOf(top_bid - money));
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(player, placeholders));
return;
}
final long current_bid = bidMenu.current_bid;
if (current_bid < top_bid && !topBidder.equalsIgnoreCase("None")) {
player.sendMessage(Messages.BID_MORE_MONEY.getMessage(player));
return;
}
this.server.getPluginManager().callEvent(new AuctionNewBidEvent(player, auction.asItemStack(), top_bid));
final Map<String, String> placeholders = new HashMap<>();
placeholders.put("%Bid%", String.valueOf(top_bid));
player.sendMessage(Messages.BID_MESSAGE.getMessage(player, placeholders));
auction.setBidderName(player.getName());
auction.setBidderUUID(player.getUniqueId().toString());
auction.setPrice(current_bid);
this.userManager.removeAuctionItem(auction); // remove it
final FileConfiguration data = bidMenu.data;
final String uuid = auction.getUuid().toString();
final ConfigurationSection section = data.getConfigurationSection("active_auctions." + uuid + "." + bidMenu.id);
if (section == null) { // do not add if not found in data.yml
player.closeInventory();
bidMenu.click(player);
return;
}
this.userManager.addActiveAuction(uuid, section);
player.closeInventory();
bidMenu.click(player);
}
case "+1", "+10", "+100", "+1000" -> {
final int price = container.getOrDefault(Keys.auction_price.getNamespacedKey(), PersistentDataType.INTEGER, 10);
bidMenu.current_bid = bidMenu.current_bid + price;
inventory.setItem(4, auction.getActiveItem(ShopType.BID).getItemStack());
inventory.setItem(13, getGlass(bidMenu));
}
case "-1", "-10", "-100", "-1000" -> {
final int price = container.getOrDefault(Keys.auction_price.getNamespacedKey(), PersistentDataType.INTEGER, -10);
bidMenu.current_bid = bidMenu.current_bid + price;
inventory.setItem(4, auction.getActiveItem(ShopType.BID).getItemStack());
inventory.setItem(13, getGlass(bidMenu));
}
}
}
private ItemStack getGlass(@Nullable final BidMenu bidMenu) {
FileConfiguration config = bidMenu != null ? bidMenu.config : this.config;
String item = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(item).setName(name).setAmount(1);
final AuctionItem auction = bidMenu != null ? bidMenu.auction : this.auction;
final long bid = bidMenu != null ? bidMenu.current_bid : this.current_bid;
final long topBid = auction.getTopBid();
if (config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
lore.add(" ");
for (String line : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
lore.add(line.replace("%Bid%", String.valueOf(bid))
.replace("%bid%", String.valueOf(bid))
.replace("%TopBid%", String.valueOf(topBid))
.replace("%topbid%", String.valueOf(topBid)));
}
itemBuilder.setLore(lore);
}
return itemBuilder.build();
}
}

View File

@ -0,0 +1,252 @@
package com.badbones69.crazyauctions.api.guis.types.other;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.Messages;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import com.badbones69.crazyauctions.api.events.AuctionBuyEvent;
import com.badbones69.crazyauctions.api.guis.Holder;
import com.badbones69.crazyauctions.api.guis.HolderManager;
import com.badbones69.crazyauctions.api.GuiManager;
import com.badbones69.crazyauctions.currency.VaultSupport;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import io.papermc.paper.persistence.PersistentDataContainerView;
import org.bukkit.Sound;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class BuyingMenu extends Holder {
private FileConfiguration config;
private FileConfiguration data;
private AuctionItem auction;
private List<String> options;
private String id;
public BuyingMenu(final AuctionItem auction, final Player player, final String id, final String title) {
super(player, title, 9);
this.auction = auction;
this.config = Files.config.getConfiguration();
this.data = Files.data.getConfiguration();
this.options = new ArrayList<>();
this.id = id;
}
public BuyingMenu() {}
@Override
public final Holder build() {
if (!this.data.contains("active_auctions." + this.auction.getUuid() + "." + this.id)) { // this grabs the uuid of the person who auctioned it
GuiManager.openShop(this.player, ShopType.BID, HolderManager.getShopCategory(this.player), 1);
this.player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(this.player));
this.userManager.removeAuctionItem(this.auction); // remove auction item, as it's not in the active_auctions
return this;
}
this.options.addAll(List.of(
"Confirm",
"Cancel"
));
for (final String key : this.options) {
if (!this.config.contains("Settings.GUISettings.OtherSettings." + key)) {
continue;
}
if (!this.config.getBoolean("Settings.GUISettings.OtherSettings." + key + ".Toggle", true)) {
continue;
}
final String id = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Item");
final String name = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Name");
final ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1);
if (this.config.contains("Settings.GUISettings.OtherSettings." + key + ".Lore")) {
itemBuilder.setLore(this.config.getStringList("Settings.GUISettings.OtherSettings." + key + ".Lore")).addString(key, Keys.auction_button.getNamespacedKey());
}
switch (key) {
case "Confirm" -> {
final ItemStack itemStack = itemBuilder.addString("Confirm", Keys.auction_button.getNamespacedKey()).build();
this.inventory.setItem(0, itemStack);
this.inventory.setItem(1, itemStack);
this.inventory.setItem(2, itemStack);
this.inventory.setItem(3, itemStack);
}
case "Cancel" -> {
final ItemStack itemStack = itemBuilder.addString("Cancel", Keys.auction_button.getNamespacedKey()).build();
this.inventory.setItem(5, itemStack);
this.inventory.setItem(6, itemStack);
this.inventory.setItem(7, itemStack);
this.inventory.setItem(8, itemStack);
}
}
}
this.inventory.setItem(4, this.auction.getActiveItem(ShopType.SELL).build());
this.player.openInventory(this.inventory);
return this;
}
@Override
public void run(InventoryClickEvent event) {
if (!(event.getInventory().getHolder(false) instanceof BuyingMenu buyingMenu)) return;
event.setCancelled(true);
final int slot = event.getSlot();
final Inventory inventory = buyingMenu.getInventory();
if (slot > inventory.getSize()) return;
if (event.getCurrentItem() == null) return;
final ItemStack itemStack = event.getCurrentItem();
if (itemStack == null) return;
final PersistentDataContainerView container = itemStack.getPersistentDataContainer();
if (!container.has(Keys.auction_button.getNamespacedKey())) return;
final String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, "");
if (type.isEmpty()) return;
final FileConfiguration data = buyingMenu.data;
final Player player = buyingMenu.player;
final AuctionItem auction = buyingMenu.auction;
switch (type) {
case "Confirm" -> {
final UUID uuid = auction.getUuid();
final String id = buyingMenu.id;
if (!data.contains("active_auctions." + uuid + "." + id)) {
buyingMenu.click(player);
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
this.userManager.removeAuctionItem(auction); // remove auction item, as it's not in the active_auctions
return;
}
if (Methods.isInvFull(player)) {
buyingMenu.click(player);
player.closeInventory();
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
return;
}
final long cost = auction.getPrice();
final VaultSupport support = this.plugin.getSupport();
Map<String, String> placeholders = new HashMap<>();
if (support.getMoney(player) < cost) {
buyingMenu.click(player);
player.closeInventory();
placeholders.put("%Money_Needed%", (cost - support.getMoney(player)) + "");
placeholders.put("%money_needed%", (cost - support.getMoney(player)) + "");
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(player, placeholders));
return;
}
final ItemStack item = auction.asItemStack();
this.server.getPluginManager().callEvent(new AuctionBuyEvent(player, item, cost));
if (!support.removeMoney(player, cost)) {
buyingMenu.click(player);
player.closeInventory();
placeholders.put("%Money_Needed%", (cost - support.getMoney(player)) + "");
placeholders.put("%money_needed%", (cost - support.getMoney(player)) + "");
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(player, placeholders));
return;
}
support.addMoney(Methods.getOfflinePlayer(String.valueOf(uuid)), cost);
String price = String.valueOf(auction.getPrice());
placeholders.put("%Price%", price);
placeholders.put("%price%", price);
placeholders.put("%Player%", player.getName());
placeholders.put("%player%", player.getName());
player.sendMessage(Messages.BOUGHT_ITEM.getMessage(player, placeholders));
final Player originalSeller = Methods.getPlayer(String.valueOf(uuid));
if (originalSeller != null && originalSeller.isOnline()) {
originalSeller.sendMessage(Messages.PLAYER_BOUGHT_ITEM.getMessage(player, placeholders));
FileConfiguration config = Files.config.getConfiguration();
String sound = config.getString("Settings.Sold-Item-Sound", "UI_BUTTON_CLICK");
if (sound.isEmpty()) return;
player.playSound(player.getLocation(), Sound.valueOf(sound), 1f, 1f);
}
player.getInventory().addItem(item);
//data.set("active_auctions." + uuid + "." + id, null); // removeAuctionItem already handles this.
this.userManager.removeAuctionItem(auction);
Files.data.save();
buyingMenu.click(player);
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
}
case "Cancel" -> {
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
buyingMenu.click(player);
}
}
}
}

View File

@ -0,0 +1,28 @@
package com.badbones69.crazyauctions.controllers;
import com.badbones69.crazyauctions.api.guis.HolderManager;
import com.badbones69.crazyauctions.api.guis.types.other.BidMenu;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class MiscListener implements Listener {
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();
if (event.getInventory().getHolder(false) instanceof BidMenu) HolderManager.removeBidding(player);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
HolderManager.removeBidding(player);
HolderManager.removeShopCategory(player);
HolderManager.removeShopType(player);
}
}

View File

@ -2,6 +2,7 @@ package com.badbones69.crazyauctions.currency;
import com.badbones69.crazyauctions.CrazyAuctions;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
@ -9,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
public class VaultSupport {
private final CrazyAuctions plugin = CrazyAuctions.get();
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private Economy vault = null;
@ -17,29 +18,35 @@ public class VaultSupport {
return this.vault;
}
public void loadVault() {
public boolean setupEconomy() {
RegisteredServiceProvider<Economy> serviceProvider = this.plugin.getServer().getServicesManager().getRegistration(Economy.class);
if (serviceProvider != null) this.vault = serviceProvider.getProvider();
return this.vault != null;
}
public long getMoney(@NotNull Player player) {
return (long) this.vault.getBalance(player);
}
public void removeMoney(@NotNull Player player, long amount) {
this.vault.withdrawPlayer(player, amount);
public boolean removeMoney(@NotNull Player player, long amount) {
EconomyResponse result = this.vault.withdrawPlayer(player, amount);
return result.transactionSuccess();
}
public void removeMoney(@NotNull OfflinePlayer player, long amount) {
this.vault.withdrawPlayer(player, amount);
public boolean removeMoney(@NotNull OfflinePlayer player, long amount) {
EconomyResponse result = this.vault.withdrawPlayer(player, amount);
return result.transactionSuccess();
}
public void addMoney(Player player, long amount) {
this.vault.depositPlayer(player, amount);
public boolean addMoney(Player player, long amount) {
EconomyResponse result = this.vault.depositPlayer(player, amount);
return result.transactionSuccess();
}
public void addMoney(OfflinePlayer player, long amount) {
this.vault.depositPlayer(player, amount);
public boolean addMoney(OfflinePlayer player, long amount) {
EconomyResponse result = this.vault.depositPlayer(player, amount);
return result.transactionSuccess();
}
}

View File

@ -0,0 +1,40 @@
package com.badbones69.crazyauctions.tasks;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import com.badbones69.crazyauctions.api.guis.Holder;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class InventoryManager {
private static ItemBuilder nextButton;
private static ItemBuilder backButton;
public static void loadButtons() {
FileConfiguration config = Files.config.getConfiguration();
String next = "Settings.GUISettings.OtherSettings.NextPage";
nextButton = new ItemBuilder().setMaterial(config.getString(next + ".Item"))
.setName(config.getString(next + ".Name"))
.setLore(config.getStringList(next + ".Lore"))
.addString("NextPage", Keys.auction_button.getNamespacedKey());
final String back = "Settings.GUISettings.OtherSettings.PreviousPage";
backButton = new ItemBuilder().setMaterial(config.getString(back + ".Item"))
.setName(config.getString(back + ".Name"))
.setLore(config.getStringList(back + ".Lore"))
.addString("PreviousPage", Keys.auction_button.getNamespacedKey());
}
public static ItemBuilder getNextButton(final Player player, final Holder holder) {
return nextButton.addLorePlaceholder("{page}", String.valueOf(holder.getPage() - 1)).setTarget(player);
}
public static ItemBuilder getBackButton(final Player player, final Holder holder) {
return backButton.addLorePlaceholder("{page}", String.valueOf(holder.getPage() - 1)).setTarget(player);
}
}

View File

@ -0,0 +1,409 @@
package com.badbones69.crazyauctions.tasks;
import com.badbones69.crazyauctions.CrazyAuctions;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.enums.Reasons;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import com.badbones69.crazyauctions.tasks.objects.ExpiredItem;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class UserManager {
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private final Map<UUID, List<AuctionItem>> auctions = new HashMap<>();
private final Map<UUID, List<ExpiredItem>> expired_items = new HashMap<>();
public final void updateAuctionsCache() {
this.auctions.clear();
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("active_auctions");
if (section == null) return;
for (String key : section.getKeys(false)) {
final ConfigurationSection player = section.getConfigurationSection(key);
if (player == null) continue;
for (String number : player.getKeys(false)) {
final ConfigurationSection auction = player.getConfigurationSection(number);
if (auction == null) continue;
addActiveAuction(key, auction);
}
}
}
public void addAuctionItem(final Player player, final ItemStack itemStack, final long price, final boolean isBiddable) {
final FileConfiguration data = Files.data.getConfiguration();
final FileConfiguration config = Files.config.getConfiguration();
final String uuid = player.getUniqueId().toString();
int current_auction = 1;
if (!data.contains("active_auctions." + uuid)) {
data.set("active_auctions." + uuid + "." + current_auction + ".name", player.getName());
final ConfigurationSection section = data.getConfigurationSection("active_auctions." + uuid + "." + current_auction);
if (section == null) return;
addItem(itemStack, uuid, price, isBiddable, config, section);
return;
}
for (;data.contains("active_auctions." + uuid + "." + current_auction); current_auction++);
data.set("active_auctions." + uuid + "." + current_auction + ".name", player.getName());
final ConfigurationSection section = data.getConfigurationSection("active_auctions." + uuid + "." + current_auction);
if (section == null) return;
addItem(itemStack, uuid, price, isBiddable, config, section);
}
public void removeAuctionItem(final AuctionItem auction) {
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("active_auctions");
boolean isNuked = false;
final UUID uuid = auction.getUuid();
if (section != null) {
final ConfigurationSection player_section = section.getConfigurationSection(uuid.toString());
final String id = auction.getId();
if (player_section != null && player_section.contains(id)) {
player_section.set(id, null);
isNuked = true;
}
}
if (!isNuked || !this.auctions.containsKey(uuid)) return; // only remove from the cache, if the data file removal was successful!
final List<AuctionItem> auctions = this.auctions.get(uuid);
auctions.remove(auction);
this.auctions.put(uuid, auctions);
}
public void removeActiveItems(final Player player) {
final UUID uuid = player.getUniqueId();
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("active_auctions");
boolean isNuked = false;
if (section != null) {
final ConfigurationSection player_section = section.getConfigurationSection(uuid.toString());
if (player_section != null) {
section.set(uuid.toString(), null);
isNuked = true;
}
}
if (!isNuked || !this.auctions.containsKey(uuid)) return; // only remove from cache, if successfully removed from file.
this.auctions.remove(uuid);
}
public final AuctionItem getAuctionItemById(final UUID uuid, final String store_id) {
AuctionItem key = null;
for (final AuctionItem auction : this.auctions.get(uuid)) {
if (!auction.getStoreID().equals(store_id)) continue;
key = auction;
break;
}
return key;
}
public final Map<UUID, List<AuctionItem>> getAuctions() {
return this.auctions;
}
public final boolean hasAuction(final UUID uuid) {
return this.auctions.containsKey(uuid);
}
public final List<AuctionItem> getAuctions(final UUID uuid) {
return this.auctions.get(uuid);
}
public final void updateExpiredCache() {
this.expired_items.clear();
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("expired_auctions");
if (section == null) return;
for (String key : section.getKeys(false)) {
final ConfigurationSection player = section.getConfigurationSection(key);
if (player == null) continue;
for (String number : player.getKeys(false)) {
final ConfigurationSection auction = player.getConfigurationSection(number);
if (auction == null) continue;
addExpiredAuction(key, auction);
}
}
}
public void addExpiredItem(final Player player, final AuctionItem auction) {
final AuctionCancelledEvent auctionCancelledEvent = new AuctionCancelledEvent(player, auction.asItemStack(), Reasons.PLAYER_FORCE_CANCEL);
this.plugin.getServer().getPluginManager().callEvent(auctionCancelledEvent);
final UUID uuid = player.getUniqueId();
final FileConfiguration data = Files.data.getConfiguration();
int number = 1;
for (;data.contains("expired_auctions." + uuid + "." + number); number++);
data.set("expired_auctions." + uuid + "." + number + ".name", auction.getName());
final ConfigurationSection section = data.getConfigurationSection("expired_auctions." + uuid + "." + number);
if (section == null) return;
section.set("item", auction.asBase64());
section.set("store_id", auction.getStoreID());
section.set("full_time", auction.getFullExpire());
section.set("price", auction.getPrice());
// data.set("active_auctions." + uuid + "." + auction.getId(), null);
if (data.contains("active_auctions." + uuid + "." + auction.getId())) {
removeAuctionItem(auction);
}
Files.data.save();
final ExpiredItem expiredItem = new ExpiredItem(
auction.getUuid().toString(),
auction.getName(),
String.valueOf(number),
auction.asBase64(),
auction.getStoreID(),
auction.getFullExpire(),
auction.getPrice()
);
if (this.expired_items.containsKey(uuid)) {
final List<ExpiredItem> items = this.expired_items.get(uuid);
items.add(expiredItem);
this.expired_items.put(uuid, items);
return;
}
this.expired_items.put(uuid, new ArrayList<>() {{
add(expiredItem);
}});
}
public void removeExpiredItem(final ExpiredItem expiredItem) {
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("expired_auctions");
boolean isNuked = false;
final UUID uuid = expiredItem.getUuid();
if (section != null) {
final ConfigurationSection player_section = section.getConfigurationSection(uuid.toString());
final String id = expiredItem.getId();
if (player_section != null && player_section.contains(id)) {
player_section.set(id, null);
isNuked = true;
}
}
if (!isNuked || !this.expired_items.containsKey(uuid)) return; // only remove from the cache, if the data file removal was successful!
final List<ExpiredItem> auctions = this.expired_items.get(uuid);
auctions.remove(expiredItem);
this.expired_items.put(expiredItem.getUuid(), auctions);
}
public void removeExpiredItems(final Player player) {
final UUID uuid = player.getUniqueId();
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("expired_auctions");
boolean isNuked = false;
if (section != null) {
final ConfigurationSection player_section = section.getConfigurationSection(uuid.toString());
if (player_section != null) {
section.set(uuid.toString(), null);
isNuked = true;
}
}
if (!isNuked || !this.expired_items.containsKey(uuid)) return; // only remove from cache, if successfully removed from file.
this.expired_items.remove(uuid);
}
public final ExpiredItem getExpiredItemById(final UUID uuid, final String store_id) {
ExpiredItem key = null;
for (final ExpiredItem auction : this.expired_items.get(uuid)) {
if (!auction.getStoreID().equals(store_id)) continue;
key = auction;
break;
}
return key;
}
public final Map<UUID, List<ExpiredItem>> getExpiredItems() {
return this.expired_items;
}
public final boolean hasExpiredItem(final UUID uuid) {
return this.expired_items.containsKey(uuid);
}
public final List<ExpiredItem> getExpiredItems(final UUID uuid) {
return this.expired_items.get(uuid);
}
public void addActiveAuction(final String uuid, final ConfigurationSection section) {
final AuctionItem new_auction = new AuctionItem(uuid, section.getString("name"),
section.getName(),
section.getString("item"),
section.getString("store_id"),
section.getLong("price"),
section.getLong("time.expire"),
section.getLong("time.full"),
section.getString("status.top_bidder.uuid", "None"),
section.getString("status.top_bidder.name", "None"),
section.getLong("status.top_bidder.price", 0),
section.getBoolean("status.biddable")
);
final UUID fromString = UUID.fromString(uuid);
if (this.auctions.containsKey(fromString)) {
final List<AuctionItem> auctions = this.auctions.get(fromString);
auctions.add(new_auction);
this.auctions.put(fromString, auctions);
} else {
this.auctions.put(fromString, new ArrayList<>() {{
add(new_auction);
}});
}
}
/**
* Adds an item to the configuration section
*
* @param itemStack {@link ItemStack}
* @param price the price
* @param isBiddable true or false
* @param config the config.yml
* @param section the section in the data.yml
*/
private void addItem(final ItemStack itemStack, final String uuid, final long price, final boolean isBiddable, final FileConfiguration config, final ConfigurationSection section) {
section.set("item", Methods.toBase64(itemStack));
section.set("store_id", UUID.randomUUID().toString().replace("-", "").substring(0, 8));
section.set("price", price);
if (isBiddable) {
section.set("time.expire", Methods.convertToMill(config.getString("Settings.Bid-Time", "2m 30s")));
} else {
section.set("time.expire", Methods.convertToMill(config.getString("Settings.Sell-Time", "2d")));
}
section.set("time.full", Methods.convertToMill(config.getString("Settings.Full-Expire-Time", "10d")));
section.set("status.top_bidder.uuid", "None");
section.set("status.top_bidder.name", "None");
section.set("status.top_bidder.price", 0);
section.set("status.biddable", isBiddable);
addActiveAuction(uuid, section);
Files.data.save();
}
private void addExpiredAuction(final String uuid, final ConfigurationSection section) {
final ExpiredItem expired_item = new ExpiredItem(
uuid,
section.getString("name"),
section.getName(),
section.getString("item"),
section.getString("store_id"),
section.getLong("full_time"),
section.getLong("price")
);
final UUID fromString = UUID.fromString(uuid);
if (this.expired_items.containsKey(fromString)) {
final List<ExpiredItem> auctions = this.expired_items.get(fromString);
auctions.add(expired_item);
this.expired_items.put(fromString, auctions);
} else {
this.expired_items.put(fromString, new ArrayList<>() {{
add(expired_item);
}});
}
}
}

View File

@ -0,0 +1,203 @@
package com.badbones69.crazyauctions.tasks.objects;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
@SuppressWarnings("UnusedAssignment")
public class AuctionItem {
private final UUID uuid;
private final String name;
private final String id;
private final String store_id;
private final ItemStack itemStack;
private long price;
private final long time_till_expire;
private final long full_expire;
private String bidder_uuid;
private String bidder_name;
private long topBid;
private final boolean isBiddable;
public AuctionItem(final String uuid, final String name, final String id, final String item, final String store_id, final long price, final long time_till_expire, final long full_expire, final String bidder_uuid, final String bidder_name, final long topBid, final boolean biddable) {
this.uuid = UUID.fromString(uuid);
this.name = name;
this.id = id;
this.itemStack = Methods.fromBase64(item);
this.store_id = store_id;
this.price = price;
this.time_till_expire = time_till_expire;
this.full_expire = full_expire;
this.bidder_uuid = bidder_uuid;
this.bidder_name = bidder_name;
this.topBid = topBid;
this.isBiddable = biddable;
}
public final UUID getUuid() {
return this.uuid;
}
public final String getId() {
return this.id;
}
public final String getName() {
return this.name;
}
public final String getStoreID() {
return this.store_id;
}
public final long getPrice() {
return this.price;
}
public void setPrice(final long price) {
this.price = price;
}
public final long getTimeTillExpire() {
return this.time_till_expire;
}
public final long getFullExpire() {
return this.full_expire;
}
public final String getBidderUUID() {
return this.bidder_uuid;
}
public void setBidderUUID(final String uuid) {
this.bidder_uuid = uuid;
}
public final String getBidderName() {
return this.bidder_name;
}
public void setBidderName(String name) {
this.bidder_name = name;
}
public final long getTopBid() {
return this.topBid;
}
public void setTopBid(long topBid) {
if (topBid <= 0L) topBid = this.topBid;
this.topBid = topBid;
}
public final boolean isBiddable() {
return this.isBiddable;
}
public final ItemStack asItemStack() {
return this.itemStack;
}
public final ItemBuilder asItemBuilder() {
return new ItemBuilder(this.itemStack);
}
public final String asBase64() {
return Methods.toBase64(asItemStack());
}
public final ItemBuilder getActiveItem(final ShopType shopType) {
final FileConfiguration configuration = Files.config.getConfiguration();
final ItemBuilder itemBuilder = ItemBuilder.convertItemStack(this.itemStack.clone());
final String time = Methods.convertToTime(getTimeTillExpire());
final List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
lore.add(" ");
if (shopType == ShopType.BID && isBiddable()) {
final String priceFormat = String.format(Locale.ENGLISH, "%,d", this.topBid);
for (final String line : configuration.getStringList("Settings.GUISettings.Bidding")) {
String newLine = line.replace("%TopBid%", priceFormat)
.replace("%topbid%", priceFormat);
newLine = line.replace("%Seller%", getName())
.replace("%seller%", getName());
newLine = line.replace("%TopBidder%", getBidderName())
.replace("%topbidder%", getBidderName());
lore.add(newLine.replace("%Time%", time)
.replace("%time%", time));
}
} else {
final String priceFormat = String.format(Locale.ENGLISH, "%,d", this.price);
for (final String line : configuration.getStringList("Settings.GUISettings.SellingItemLore")) {
String newLine = line.replace("%TopBid%", priceFormat)
.replace("%topbid%", priceFormat);
newLine = line.replace("%Seller%", getName())
.replace("%seller%", getName());
lore.add(newLine.replace("%Time%", time)
.replace("%time%", time)
.replace("%price%", priceFormat).replace("%Price%", priceFormat));
}
}
itemBuilder.setLore(lore)
.addString(this.id, Keys.auction_number.getNamespacedKey())
.addString(getStoreID(), Keys.auction_store_id.getNamespacedKey())
.addString(this.uuid.toString(), Keys.auction_uuid.getNamespacedKey());
return itemBuilder;
}
public final ItemBuilder getCurrentItem() {
final FileConfiguration configuration = Files.config.getConfiguration();
final ItemBuilder itemBuilder = ItemBuilder.convertItemStack(this.itemStack.clone());
final String priceFormat = String.format(Locale.ENGLISH, "%,d", this.price);
final String time = Methods.convertToTime(getTimeTillExpire());
final List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
lore.add(" ");
for (final String line : configuration.getStringList("Settings.GUISettings.CurrentLore")) {
lore.add(line.replace("%Time%", time).replace("%time%", time)
.replace("%price%", priceFormat)
.replace("%Price%", priceFormat));
}
itemBuilder.setLore(lore).addString(getStoreID(), Keys.auction_store_id.getNamespacedKey());;
return itemBuilder;
}
}

View File

@ -0,0 +1,95 @@
package com.badbones69.crazyauctions.tasks.objects;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
public class ExpiredItem {
private final UUID uuid;
private final String name;
private final String id;
private final String store_id;
private final ItemStack itemStack;
private final long full_expire;
private final long price;
public ExpiredItem(final String uuid, final String name, final String id, final String item, final String store_id, final long full_expire, final long price) {
this.uuid = UUID.fromString(uuid);
this.name = name;
this.id = id;
this.itemStack = Methods.fromBase64(item);
this.store_id = store_id;
this.full_expire = full_expire;
this.price = price;
}
public final UUID getUuid() {
return this.uuid;
}
public final String getId() {
return this.id;
}
public final String getName() {
return this.name;
}
public final String getStoreID() {
return this.store_id;
}
public final long getFullExpire() {
return this.full_expire;
}
public final ItemStack asItemStack() {
return this.itemStack;
}
public final long getPrice() {
return this.price;
}
public final String asBase64() {
return Methods.toBase64(asItemStack());
}
public final ItemBuilder getExpiredItem() {
final FileConfiguration configuration = Files.config.getConfiguration();
final ItemBuilder itemBuilder = ItemBuilder.convertItemStack(this.itemStack.clone());
final String priceFormat = String.format(Locale.ENGLISH, "%,d", this.price);
final String time = Methods.convertToTime(getFullExpire());
final List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
lore.add(" ");
for (final String line : configuration.getStringList("Settings.GUISettings.Cancelled/ExpiredLore")) {
lore.add(line.replace("%Time%", time).replace("%time%", time)
.replace("%price%", priceFormat)
.replace("%Price%", priceFormat));
}
itemBuilder.setLore(lore)
.addString(getStoreID(), Keys.auction_store_id.getNamespacedKey());;
return itemBuilder;
}
}