mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2024-09-21 03:21:02 +02:00
add new inventory builders
This commit is contained in:
parent
f903db5af5
commit
c9c9cf2880
@ -0,0 +1,134 @@
|
||||
package com.badbones69.crazyauctions.api.builders.gui;
|
||||
|
||||
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
|
||||
import com.badbones69.crazyauctions.configs.impl.gui.AuctionKeys;
|
||||
import com.ryderbelserion.vital.paper.api.builders.gui.interfaces.Gui;
|
||||
import com.ryderbelserion.vital.paper.api.builders.gui.interfaces.GuiItem;
|
||||
import com.ryderbelserion.vital.paper.api.builders.gui.types.PaginatedGui;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class DynamicInventoryBuilder extends InventoryBuilder {
|
||||
|
||||
private final PaginatedGui gui;
|
||||
|
||||
public DynamicInventoryBuilder(final Player player, final String title, final int rows) {
|
||||
super(player);
|
||||
|
||||
this.gui = Gui.paginated().setTitle(title).setRows(rows).disableInteractions().create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the {@link PaginatedGui}.
|
||||
*/
|
||||
public void open() {
|
||||
open(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the {@link PaginatedGui}.
|
||||
*
|
||||
* @param consumer {@link Consumer(DynamicInventoryBuilder)}
|
||||
*/
|
||||
public void open(@Nullable final Consumer<DynamicInventoryBuilder> consumer) {
|
||||
if (consumer != null) {
|
||||
consumer.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Player}.
|
||||
*
|
||||
* @return {@link Player}
|
||||
*/
|
||||
public final Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link PaginatedGui}.
|
||||
*
|
||||
* @return {@link PaginatedGui}
|
||||
*/
|
||||
public final PaginatedGui getGui() {
|
||||
return this.gui;
|
||||
}
|
||||
|
||||
// Adds the back button
|
||||
public void setBackButton(final int row, final int column) {
|
||||
if (this.gui.getCurrentPageNumber() <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.gui.setItem(row, column, new ItemBuilder().withType(Material.ARROW).asGuiItem(event -> {
|
||||
event.setCancelled(true);
|
||||
|
||||
this.gui.previous();
|
||||
|
||||
final int page = this.gui.getCurrentPageNumber();
|
||||
|
||||
if (page <= 1) {
|
||||
this.gui.removeItem(row, column);
|
||||
|
||||
this.gui.setItem(row, column, new GuiItem(Material.BLACK_STAINED_GLASS_PANE));
|
||||
} else {
|
||||
setBackButton(row, column);
|
||||
}
|
||||
|
||||
if (page < this.gui.getMaxPages()) {
|
||||
setNextButton(6, 6);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// Adds the next button
|
||||
public void setNextButton(final int row, final int column) {
|
||||
if (this.gui.getCurrentPageNumber() >= this.gui.getMaxPages()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.gui.setItem(row, column, new ItemBuilder().withType(Material.ARROW).asGuiItem(event -> {
|
||||
event.setCancelled(true);
|
||||
|
||||
this.gui.next();
|
||||
|
||||
final int page = this.gui.getCurrentPageNumber();
|
||||
|
||||
if (page >= this.gui.getMaxPages()) {
|
||||
this.gui.removeItem(row, column);
|
||||
|
||||
this.gui.setItem(row, column, new GuiItem(Material.BLACK_STAINED_GLASS_PANE));
|
||||
} else {
|
||||
setNextButton(row, column);
|
||||
}
|
||||
|
||||
if (page <= 1) {
|
||||
this.gui.removeItem(6, 4);
|
||||
|
||||
this.gui.setItem(6, 4, new GuiItem(Material.BLACK_STAINED_GLASS_PANE));
|
||||
} else {
|
||||
setBackButton(6, 4);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bidding item
|
||||
*/
|
||||
public void setBiddingItem() {
|
||||
this.auctions.getProperty(AuctionKeys.bidding_item_button).setItem(event -> {
|
||||
setSellingItem();
|
||||
}, this.gui);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selling item
|
||||
*/
|
||||
public void setSellingItem() {
|
||||
this.auctions.getProperty(AuctionKeys.selling_item_button).setItem(event -> {
|
||||
setBiddingItem();
|
||||
}, this.gui);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.badbones69.crazyauctions.api.builders.gui;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import com.badbones69.crazyauctions.CrazyAuctions;
|
||||
import com.badbones69.crazyauctions.api.CrazyManager;
|
||||
import com.badbones69.crazyauctions.configs.ConfigManager;
|
||||
import com.badbones69.crazyauctions.configs.enums.Files;
|
||||
import com.ryderbelserion.vital.paper.api.enums.Support;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class InventoryBuilder {
|
||||
|
||||
protected final CrazyAuctions plugin = CrazyAuctions.getPlugin();
|
||||
protected final CrazyManager crazyManager = this.plugin.getCrazyManager();
|
||||
protected final Server server = this.plugin.getServer();
|
||||
|
||||
protected final SettingsManager config = ConfigManager.getConfig();
|
||||
|
||||
protected final SettingsManager auctions = ConfigManager.getCustomConfig(Files.auctions.getFileName());
|
||||
|
||||
protected final Player player;
|
||||
|
||||
public InventoryBuilder(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public final String parse(final Player player, final String title) {
|
||||
return Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(player, title) : title;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.badbones69.crazyauctions.api.builders.gui;
|
||||
|
||||
import com.ryderbelserion.vital.paper.api.builders.gui.interfaces.Gui;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class StaticInventoryBuilder extends InventoryBuilder {
|
||||
|
||||
private final Player player;
|
||||
|
||||
private final Gui gui;
|
||||
|
||||
/**
|
||||
* Builds an inventory with a set title/rows
|
||||
*
|
||||
* @param player {@link Player}
|
||||
* @param title {@link String}
|
||||
* @param rows {@link Integer}
|
||||
*/
|
||||
public StaticInventoryBuilder(final Player player, final String title, final int rows) {
|
||||
super(player);
|
||||
|
||||
this.gui = Gui.gui().setTitle(parse(player, title)).setRows(rows).disableInteractions().create();
|
||||
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public abstract void open();
|
||||
|
||||
/**
|
||||
* Gets the {@link Player}.
|
||||
*
|
||||
* @return {@link Player}
|
||||
*/
|
||||
public final Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the title of the gui.
|
||||
*
|
||||
* @return the title of the gui
|
||||
*/
|
||||
public final String getTitle() {
|
||||
return this.gui.getTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the title contains a message.
|
||||
*
|
||||
* @param message the message to check
|
||||
* @return true or false
|
||||
*/
|
||||
public final boolean contains(final String message) {
|
||||
return getTitle().contains(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Gui}.
|
||||
*
|
||||
* @return {@link Gui}
|
||||
*/
|
||||
public final Gui getGui() {
|
||||
return this.gui;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.badbones69.crazyauctions.api.builders.types;
|
||||
|
||||
import com.badbones69.crazyauctions.api.builders.gui.DynamicInventoryBuilder;
|
||||
import com.badbones69.crazyauctions.api.enums.misc.Files;
|
||||
import com.badbones69.crazyauctions.configs.impl.ConfigKeys;
|
||||
import com.badbones69.crazyauctions.configs.impl.gui.AuctionKeys;
|
||||
import com.badbones69.crazyauctions.utils.AuctionUtils;
|
||||
import com.badbones69.crazyauctions.utils.MiscUtils;
|
||||
import com.ryderbelserion.vital.paper.api.builders.gui.types.PaginatedGui;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AuctionMenu extends DynamicInventoryBuilder {
|
||||
|
||||
public AuctionMenu(final Player player, final String title, final int rows) {
|
||||
super(player, title, rows);
|
||||
}
|
||||
|
||||
private final Player player = getPlayer();
|
||||
private final PaginatedGui gui = getGui();
|
||||
|
||||
@Override
|
||||
public void open() { // put the category option here maybe?
|
||||
if (this.config.getProperty(ConfigKeys.category_page_opens_first)) {
|
||||
//todo() open gui with specific category.
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.gui.setDefaultTopClickAction(event -> MiscUtils.play(player, player.getLocation(), this.config.getProperty(ConfigKeys.click_item_sound), Sound.Source.PLAYER));
|
||||
|
||||
final YamlConfiguration configuration = Files.data.getConfiguration();
|
||||
|
||||
AuctionUtils.getItems(configuration.getConfigurationSection("Items")).forEach(itemStack -> {
|
||||
this.gui.addItem(itemStack.asGuiItem(event -> {
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
this.auctions.getProperty(AuctionKeys.expired_item_button).setItem(event -> {
|
||||
}, this.gui);
|
||||
|
||||
// add selling item
|
||||
setSellingItem();
|
||||
|
||||
this.auctions.getProperty(AuctionKeys.sold_item_button).setItem(event -> {
|
||||
|
||||
}, this.gui);
|
||||
|
||||
this.gui.open(this.player);
|
||||
}
|
||||
}
|
@ -1,21 +1,12 @@
|
||||
package com.badbones69.crazyauctions.commands.v2;
|
||||
|
||||
import com.badbones69.crazyauctions.api.enums.misc.Files;
|
||||
import com.badbones69.crazyauctions.api.builders.types.AuctionMenu;
|
||||
import com.badbones69.crazyauctions.api.enums.other.Permissions;
|
||||
import com.badbones69.crazyauctions.configs.impl.ConfigKeys;
|
||||
import com.badbones69.crazyauctions.configs.impl.gui.AuctionKeys;
|
||||
import com.badbones69.crazyauctions.utils.AuctionUtils;
|
||||
import com.badbones69.crazyauctions.utils.MiscUtils;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import com.ryderbelserion.vital.paper.api.builders.gui.interfaces.Gui;
|
||||
import com.ryderbelserion.vital.paper.api.builders.gui.interfaces.GuiItem;
|
||||
import com.ryderbelserion.vital.paper.api.builders.gui.types.PaginatedGui;
|
||||
import com.ryderbelserion.vital.paper.commands.context.PaperCommandInfo;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BaseCommand extends AbstractCommand {
|
||||
@ -28,50 +19,7 @@ public class BaseCommand extends AbstractCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = info.getPlayer();
|
||||
|
||||
if (this.config.getProperty(ConfigKeys.category_page_opens_first)) {
|
||||
//todo() open gui with specific category.
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
final @NotNull PaginatedGui builder = Gui.paginated()
|
||||
.pageSize(54)
|
||||
.setRows(6)
|
||||
.disableInteractions()
|
||||
.setTitle(this.auctions.getProperty(AuctionKeys.gui_name)).create();
|
||||
|
||||
final YamlConfiguration configuration = Files.data.getConfiguration();
|
||||
|
||||
AuctionUtils.getItems(configuration.getConfigurationSection("Items")).forEach(itemStack -> {
|
||||
builder.addItem(new GuiItem(itemStack, consumer -> {
|
||||
|
||||
MiscUtils.play(player, player.getLocation(), this.config.getProperty(ConfigKeys.click_item_sound), Sound.Source.PLAYER);
|
||||
}));
|
||||
});
|
||||
|
||||
this.auctions.getProperty(AuctionKeys.expired_item_button).setItem(consumer -> {
|
||||
|
||||
MiscUtils.play(player, player.getLocation(), this.config.getProperty(ConfigKeys.click_item_sound), Sound.Source.PLAYER);
|
||||
}, builder);
|
||||
|
||||
this.auctions.getProperty(AuctionKeys.selling_item_button).setItem(consumer -> {
|
||||
|
||||
MiscUtils.play(player, player.getLocation(), this.config.getProperty(ConfigKeys.click_item_sound), Sound.Source.PLAYER);
|
||||
}, builder);
|
||||
|
||||
this.auctions.getProperty(AuctionKeys.bidding_item_button).setItem(consumer -> {
|
||||
|
||||
MiscUtils.play(player, player.getLocation(), this.config.getProperty(ConfigKeys.click_item_sound), Sound.Source.PLAYER);
|
||||
}, builder);
|
||||
|
||||
this.auctions.getProperty(AuctionKeys.sold_item_button).setItem(consumer -> {
|
||||
|
||||
MiscUtils.play(player, player.getLocation(), this.config.getProperty(ConfigKeys.click_item_sound), Sound.Source.PLAYER);
|
||||
}, builder);
|
||||
|
||||
builder.open(player);
|
||||
new AuctionMenu(info.getPlayer(), this.auctions.getProperty(AuctionKeys.gui_name), 6).open();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ButtonProperty {
|
||||
|
||||
@ -28,36 +27,36 @@ public class ButtonProperty {
|
||||
public final ButtonProperty populate(final String buttonName) {
|
||||
switch (buttonName) {
|
||||
case "expired-item" -> {
|
||||
this.displayName = "<gold>Expired Items";
|
||||
this.displayName = "<bold><gray>(<gold>!<gray>)</bold> <gold>Expired Items";
|
||||
this.displayLore = List.of(
|
||||
"<bold><gray>(<gold>!<gray>)</bold> <gray>Click here to view, and collect all items that have expired."
|
||||
"<gray>Click to view items that have expired."
|
||||
);
|
||||
this.material = "poisonous_potato";
|
||||
this.slot = 46;
|
||||
}
|
||||
|
||||
case "selling-item" -> {
|
||||
this.displayName = "<gold>Currently looking at items being sold";
|
||||
this.displayName = "<bold><gray>(<gold>!<gray>)</bold> <gold>Items that are being sold";
|
||||
this.displayLore = List.of(
|
||||
"<bold><gray>(<gold>!<gray>)</bold> <gray>Click here to see items that you can bid on."
|
||||
"<gray>Click to see items to bid on."
|
||||
);
|
||||
this.material = "emerald";
|
||||
this.slot = 49;
|
||||
}
|
||||
|
||||
case "bidding-item" -> {
|
||||
this.displayName = "<gold>Currently looking at items that can be bid on";
|
||||
this.displayName = "<bold><gray>(<gold>!<gray>)</bold> <gold>Items that can be bid on";
|
||||
this.displayLore = List.of(
|
||||
"<bold><gray>(<gold>!<gray>)</bold> <gray>Click here to see items that you can buy at a price."
|
||||
"<gray>Click to see items that can be bought."
|
||||
);
|
||||
this.material = "magma_cream";
|
||||
this.slot = 49;
|
||||
}
|
||||
|
||||
case "sold-item" -> {
|
||||
this.displayName = "<gold>Items you are currently selling";
|
||||
this.displayName = "<bold><gray>(<gold>!<gray>)</bold> <gold>Items you are currently selling";
|
||||
this.displayLore = List.of(
|
||||
"<bold><gray>(<gold>!<gray>)</bold> <gray>Click to view all the items you, currently up for auction."
|
||||
"<gray>Click to view all items you have up for auction."
|
||||
);
|
||||
this.material = "gold_ingot";
|
||||
this.slot = 52;
|
||||
|
@ -1,22 +1,19 @@
|
||||
package com.badbones69.crazyauctions.utils;
|
||||
|
||||
import com.ryderbelserion.vital.paper.util.ItemUtil;
|
||||
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AuctionUtils {
|
||||
|
||||
public static List<ItemStack> getItems(final ConfigurationSection section) {
|
||||
public static List<ItemBuilder> getItems(final ConfigurationSection section) {
|
||||
if (section == null) return List.of();
|
||||
|
||||
final List<ItemStack> itemStacks = new ArrayList<>();
|
||||
final List<ItemBuilder> itemStacks = new ArrayList<>();
|
||||
|
||||
for (final String key : section.getKeys(false)) {
|
||||
final ItemStack builder = ItemUtil.fromBase64(section.getString(key + ".Item", ""));
|
||||
|
||||
itemStacks.add(builder);
|
||||
itemStacks.add(new ItemBuilder().fromBase64(section.getString(key + ".Item", "")));
|
||||
}
|
||||
|
||||
return itemStacks;
|
||||
|
Loading…
Reference in New Issue
Block a user