mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-01-22 15:11:20 +01:00
2.20.0 - Fixed a bug regarding the sell gui that caused the duplication of the item being sold. Added a new gui for admin options.
This commit is contained in:
parent
64bd512322
commit
42e7faf7b4
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>ca.tweetzy</groupId>
|
||||
<artifactId>auctionhouse</artifactId>
|
||||
<version>2.19.0</version>
|
||||
<version>2.20.0</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -25,8 +25,11 @@ import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -273,7 +276,7 @@ public class AuctionAPI {
|
||||
/**
|
||||
* Used to match patterns
|
||||
*
|
||||
* @param pattern is the keyword being searched for
|
||||
* @param pattern is the keyword being searched for
|
||||
* @param sentence is the sentence you're checking
|
||||
* @return whether the keyword is found
|
||||
*/
|
||||
@ -284,9 +287,8 @@ public class AuctionAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pattern is the keyword that you're currently searching for
|
||||
* @param lines is the lines being checked for the keyword
|
||||
* @param lines is the lines being checked for the keyword
|
||||
* @return whether the keyword was found in any of the lines provided
|
||||
*/
|
||||
public boolean match(String pattern, List<String> lines) {
|
||||
@ -312,8 +314,8 @@ public class AuctionAPI {
|
||||
/**
|
||||
* Used to replace the last portion of a string
|
||||
*
|
||||
* @param string is the string being edited
|
||||
* @param substring is the to replace word/phrase
|
||||
* @param string is the string being edited
|
||||
* @param substring is the to replace word/phrase
|
||||
* @param replacement is the keyword(s) you're replacing the old substring with
|
||||
* @return the updated string
|
||||
*/
|
||||
@ -343,7 +345,7 @@ public class AuctionAPI {
|
||||
* Get the total amount of an item in the player's inventory
|
||||
*
|
||||
* @param player is the player being checked
|
||||
* @param stack is the item you want to find
|
||||
* @param stack is the item you want to find
|
||||
* @return the total count of the item(s)
|
||||
*/
|
||||
public int getItemCountInPlayerInventory(Player player, ItemStack stack) {
|
||||
@ -383,7 +385,7 @@ public class AuctionAPI {
|
||||
* Removes a set amount of a specific item from the player inventory
|
||||
*
|
||||
* @param player is the player you want to remove the item from
|
||||
* @param stack is the item that you want to remove
|
||||
* @param stack is the item that you want to remove
|
||||
* @param amount is the amount of items you want to remove.
|
||||
*/
|
||||
public void removeSpecificItemQuantityFromPlayer(Player player, ItemStack stack, int amount) {
|
||||
@ -412,7 +414,7 @@ public class AuctionAPI {
|
||||
|
||||
public ItemStack createBundledItem(ItemStack baseItem, ItemStack... items) {
|
||||
Objects.requireNonNull(items, "Cannot create a bundled item with no items");
|
||||
ItemStack item = ConfigurationItemHelper.createConfigurationItem(Settings.ITEM_BUNDLE_ITEM.getString(), Settings.ITEM_BUNDLE_NAME.getString(), Settings.ITEM_BUNDLE_LORE.getStringList(), new HashMap<String, Object>(){{
|
||||
ItemStack item = ConfigurationItemHelper.createConfigurationItem(Settings.ITEM_BUNDLE_ITEM.getString(), Settings.ITEM_BUNDLE_NAME.getString(), Settings.ITEM_BUNDLE_LORE.getStringList(), new HashMap<String, Object>() {{
|
||||
put("%item_name%", getItemName(baseItem));
|
||||
}});
|
||||
|
||||
@ -427,4 +429,9 @@ public class AuctionAPI {
|
||||
ItemUtils.addGlow(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||
Set<Object> seen = ConcurrentHashMap.newKeySet();
|
||||
return t -> seen.add(keyExtractor.apply(t));
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,14 @@ package ca.tweetzy.auctionhouse.commands;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.auctionhouse.api.AuctionAPI;
|
||||
import ca.tweetzy.auctionhouse.guis.GUISellItem;
|
||||
import ca.tweetzy.auctionhouse.helpers.PlayerHelper;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.core.commands.AbstractCommand;
|
||||
import ca.tweetzy.core.compatibility.XMaterial;
|
||||
import ca.tweetzy.core.utils.PlayerUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -61,6 +65,12 @@ public class CommandAdmin extends AbstractCommand {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "opensell":
|
||||
if (args.length < 2) return ReturnType.FAILURE;
|
||||
Player player = PlayerUtils.findPlayer(args[1]);
|
||||
if (player == null) return ReturnType.FAILURE;
|
||||
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellItem(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()), PlayerHelper.getHeldItem(player)));
|
||||
break;
|
||||
}
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
|
@ -13,8 +13,10 @@ import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.core.commands.AbstractCommand;
|
||||
import ca.tweetzy.core.compatibility.CompatibleHand;
|
||||
import ca.tweetzy.core.compatibility.XMaterial;
|
||||
import ca.tweetzy.core.input.ChatPrompt;
|
||||
import ca.tweetzy.core.utils.NumberUtils;
|
||||
import ca.tweetzy.core.utils.PlayerUtils;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import ca.tweetzy.core.utils.nms.NBTEditor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -62,7 +64,6 @@ public class CommandSell extends AbstractCommand {
|
||||
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellItem(auctionPlayer, itemToSell));
|
||||
AuctionHouse.getInstance().getAuctionPlayerManager().addItemToSellHolding(player.getUniqueId(), itemToSell);
|
||||
PlayerUtils.takeActiveItem(player, CompatibleHand.MAIN_HAND, itemToSell.getAmount());
|
||||
|
||||
}
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
|
57
src/main/java/ca/tweetzy/auctionhouse/guis/GUIAdminItem.java
Normal file
57
src/main/java/ca/tweetzy/auctionhouse/guis/GUIAdminItem.java
Normal file
@ -0,0 +1,57 @@
|
||||
package ca.tweetzy.auctionhouse.guis;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.auctionhouse.api.AuctionAPI;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionItem;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
|
||||
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.core.gui.Gui;
|
||||
import ca.tweetzy.core.utils.PlayerUtils;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: July 14 2021
|
||||
* Time Created: 3:04 p.m.
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
||||
*/
|
||||
public class GUIAdminItem extends Gui {
|
||||
|
||||
private final AuctionPlayer auctionPlayer;
|
||||
private final AuctionItem auctionItem;
|
||||
|
||||
public GUIAdminItem(AuctionPlayer auctionPlayer, AuctionItem auctionItem) {
|
||||
this.auctionPlayer = auctionPlayer;
|
||||
this.auctionItem = auctionItem;
|
||||
setTitle(TextUtils.formatText(Settings.GUI_ITEM_ADMIN_TITLE.getString()));
|
||||
setDefaultItem(Settings.GUI_ITEM_ADMIN_BG_ITEM.getMaterial().parseItem());
|
||||
setRows(3);
|
||||
setAcceptsItems(false);
|
||||
setUseLockedCells(true);
|
||||
|
||||
setOnClose(close -> close.manager.showGUI(close.player, new GUIAuctionHouse(this.auctionPlayer)));
|
||||
draw();
|
||||
}
|
||||
|
||||
private void draw() {
|
||||
setButton(1, 2, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_ITEM.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_NAME.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_LORE.getStringList(), null), e -> {
|
||||
this.auctionItem.setRemainingTime(0);
|
||||
this.auctionItem.setExpired(true);
|
||||
e.gui.close();
|
||||
});
|
||||
|
||||
setButton(1, 4, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_ITEM.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_NAME.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_LORE.getStringList(), null), e -> {
|
||||
ItemStack item = AuctionAPI.getInstance().deserializeItem(this.auctionItem.getRawItem());
|
||||
PlayerUtils.giveItem(e.player, item);
|
||||
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(this.auctionItem);
|
||||
e.gui.close();
|
||||
});
|
||||
|
||||
setButton(1, 6, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_ITEM_ADMIN_ITEMS_DELETE_ITEM.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_DELETE_NAME.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_DELETE_LORE.getStringList(), null), e -> {
|
||||
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(this.auctionItem);
|
||||
e.gui.close();
|
||||
});
|
||||
}
|
||||
}
|
@ -67,9 +67,9 @@ public class GUIAuctionHouse extends Gui {
|
||||
drawItems();
|
||||
}
|
||||
|
||||
// TODO FIX VISUAL BUG THAT MAKES IT LOOK THERE IS A DUPLICATED ITEM
|
||||
private void drawItems() {
|
||||
AuctionHouse.newChain().asyncFirst(() -> {
|
||||
// this.items = new ArrayList<>(AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems()).stream().filter(item -> !item.isExpired() && item.getRemainingTime() >= 1 && !AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().contains(item)).collect(Collectors.toList());
|
||||
this.items = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<UUID, AuctionItem> entry : AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().entrySet()) {
|
||||
@ -79,7 +79,6 @@ public class GUIAuctionHouse extends Gui {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (this.searchPhrase != null && this.searchPhrase.length() != 0) {
|
||||
this.items = this.items.stream().filter(item -> checkSearchCriteria(this.searchPhrase, item)).collect(Collectors.toList());
|
||||
}
|
||||
@ -205,14 +204,8 @@ public class GUIAuctionHouse extends Gui {
|
||||
|
||||
private void handleItemRemove(AuctionItem auctionItem, GuiClickEvent e) {
|
||||
if (e.player.isOp() || e.player.hasPermission("auctionhouse.admin")) {
|
||||
if (Settings.SEND_REMOVED_ITEM_BACK_TO_PLAYER.getBoolean()) {
|
||||
AuctionHouse.getInstance().getAuctionItemManager().getItem(auctionItem.getKey()).setExpired(true);
|
||||
} else {
|
||||
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(auctionItem);
|
||||
}
|
||||
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
e.manager.showGUI(e.player, new GUIAdminItem(this.auctionPlayer, auctionItem));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
|
||||
import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
|
||||
import ca.tweetzy.auctionhouse.managers.SoundManager;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.core.commands.AbstractCommand;
|
||||
import ca.tweetzy.core.compatibility.XMaterial;
|
||||
import ca.tweetzy.core.gui.Gui;
|
||||
import ca.tweetzy.core.gui.events.GuiClickEvent;
|
||||
@ -56,6 +57,14 @@ public class GUISellItem extends Gui {
|
||||
setRows(5);
|
||||
draw();
|
||||
|
||||
setOnOpen(open -> {
|
||||
// Check if they are already using a sell gui
|
||||
if (ChatPrompt.isRegistered(open.player)) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.finishenteringprice").sendPrefixedMessage(open.player);
|
||||
open.gui.exit();
|
||||
}
|
||||
});
|
||||
|
||||
setOnClose(close -> {
|
||||
ItemStack toGiveBack = AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().get(close.player.getUniqueId());
|
||||
if (toGiveBack != null && toGiveBack.getType() != XMaterial.AIR.parseMaterial()) {
|
||||
@ -93,6 +102,7 @@ public class GUISellItem extends Gui {
|
||||
}}), ClickType.LEFT, e -> {
|
||||
setTheItemToBeListed();
|
||||
e.gui.exit();
|
||||
|
||||
ChatPrompt.showPrompt(AuctionHouse.getInstance(), this.auctionPlayer.getPlayer(), TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter new buy now price").getMessage()), chat -> {
|
||||
String msg = chat.getMessage();
|
||||
if (validateChatNumber(msg, Settings.MIN_AUCTION_PRICE.getDouble())) {
|
||||
|
@ -37,6 +37,7 @@ public class LocaleSettings {
|
||||
languageNodes.put("general.entersearchphrase", "&aEnter a search phrase into chat");
|
||||
languageNodes.put("general.filteritemaddedalready", "&cThat item already exists within that category's filter whitelist.");
|
||||
languageNodes.put("general.addeditemtofilterwhitelist", "&aAdded &2%item_name%&a to the &2%filter_category%&a's whitelist");
|
||||
languageNodes.put("general.finishenteringprice", "&cPlease finish entering the new price first.");
|
||||
|
||||
|
||||
languageNodes.put("pricing.minbaseprice", "&cThe minimum base price must be &a$%price%");
|
||||
|
@ -586,7 +586,7 @@ public class Settings {
|
||||
/* ===============================
|
||||
* ITEM SELL/LIST GUI
|
||||
* ===============================*/
|
||||
public static final ConfigSetting GUI_SELL_TITLE = new ConfigSetting(config, "gui.sell.title", "&7Auction House - &eSelling Itm");
|
||||
public static final ConfigSetting GUI_SELL_TITLE = new ConfigSetting(config, "gui.sell.title", "&7Auction House - &eSelling Item");
|
||||
public static final ConfigSetting GUI_SELL_BG_ITEM = new ConfigSetting(config, "gui.sell.bg item", XMaterial.BLACK_STAINED_GLASS_PANE.name());
|
||||
|
||||
public static final ConfigSetting GUI_SELL_ITEMS_BUY_NOW_ITEM = new ConfigSetting(config, "gui.sell.items.buy now.item", XMaterial.SUNFLOWER.name());
|
||||
@ -631,6 +631,25 @@ public class Settings {
|
||||
public static final ConfigSetting GUI_SELL_ITEMS_BUY_NOW_DISABLED_LORE = new ConfigSetting(config, "gui.sell.items.buy now disabled.lore", Collections.singletonList("&7Click to &aEnable &7buy now"));
|
||||
|
||||
|
||||
/* ===============================
|
||||
* ITEM ADMIN GUI
|
||||
* ===============================*/
|
||||
public static final ConfigSetting GUI_ITEM_ADMIN_TITLE = new ConfigSetting(config, "gui.item admin.title", "&7Auction House - &eAdmin Item");
|
||||
public static final ConfigSetting GUI_ITEM_ADMIN_BG_ITEM = new ConfigSetting(config, "gui.item admin.bg item", XMaterial.BLACK_STAINED_GLASS_PANE.name());
|
||||
|
||||
public static final ConfigSetting GUI_ITEM_ADMIN_ITEMS_RETURN_ITEM = new ConfigSetting(config, "gui.item admin.items.send to player.item", XMaterial.ENDER_CHEST.name());
|
||||
public static final ConfigSetting GUI_ITEM_ADMIN_ITEMS_RETURN_NAME = new ConfigSetting(config, "gui.item admin.items.send to player.name", "&a&lReturn to player");
|
||||
public static final ConfigSetting GUI_ITEM_ADMIN_ITEMS_RETURN_LORE = new ConfigSetting(config, "gui.item admin.items.send to player.lore", Collections.singletonList("&7Click to return this item to the seller"));
|
||||
|
||||
public static final ConfigSetting GUI_ITEM_ADMIN_ITEMS_CLAIM_ITEM = new ConfigSetting(config, "gui.item admin.items.claim item.item", XMaterial.HOPPER.name());
|
||||
public static final ConfigSetting GUI_ITEM_ADMIN_ITEMS_CLAIM_NAME = new ConfigSetting(config, "gui.item admin.items.claim item.name", "&a&lClaim Item");
|
||||
public static final ConfigSetting GUI_ITEM_ADMIN_ITEMS_CLAIM_LORE = new ConfigSetting(config, "gui.item admin.items.claim item.lore", Collections.singletonList("&7Click to claim this item as yours"));
|
||||
|
||||
public static final ConfigSetting GUI_ITEM_ADMIN_ITEMS_DELETE_ITEM = new ConfigSetting(config, "gui.item admin.items.delete item.item", XMaterial.BARRIER.name());
|
||||
public static final ConfigSetting GUI_ITEM_ADMIN_ITEMS_DELETE_NAME = new ConfigSetting(config, "gui.item admin.items.delete item.name", "&a&lDelete Item");
|
||||
public static final ConfigSetting GUI_ITEM_ADMIN_ITEMS_DELETE_LORE = new ConfigSetting(config, "gui.item admin.items.delete item.lore", Collections.singletonList("&7Click to delete this item"));
|
||||
|
||||
|
||||
/* ===============================
|
||||
* AUCTION STACKS
|
||||
* ===============================*/
|
||||
|
Loading…
Reference in New Issue
Block a user