2.43.0 - Bundles are no longer item dependant, short format for player balance, prefix no longer adds a space if empty, and added option to prevent the listing of damaged items.

This commit is contained in:
Kiran Hart 2021-11-22 13:53:46 -05:00
parent eda660c682
commit 678fa8ecd7
11 changed files with 217 additions and 12 deletions

27
pom.xml
View File

@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.tweetzy</groupId>
<artifactId>auctionhouse</artifactId>
<version>2.42.0</version>
<version>2.43.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -117,6 +117,29 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-files-on-build</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>C:\Dev\Minecraft\latest\plugins</outputDirectory>
<resources>
<resource>
<directory>C:\Users\Kiran\Documents\Development\Minecraft\Active\Auction House 2.0\target</directory>
<include>Auction House-${project.version}.jar</include>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
@ -167,7 +190,7 @@
<dependency>
<groupId>ca.tweetzy</groupId>
<artifactId>tweetycore</artifactId>
<version>2.9.3</version>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.gmail.nossr50.mcMMO</groupId>

View File

@ -12,6 +12,7 @@ import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.CompatibleHand;
import ca.tweetzy.core.compatibility.ServerVersion;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.utils.PlayerUtils;
@ -29,6 +30,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.Plugin;
@ -76,6 +78,8 @@ public class AuctionAPI {
* @return a user friendly number to read
*/
public String getFriendlyNumber(double value) {
if (value <= 0) return "0";
int power;
String suffix = " KMBTQ";
String formattedNumber = "";
@ -585,6 +589,18 @@ public class AuctionAPI {
}
}
public boolean isDamaged(final ItemStack item) {
if (item.hasItemMeta() && item.getItemMeta() instanceof Damageable) {
final Damageable damageable = (Damageable) item.getItemMeta();
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
return damageable.getDamage() > 0;
}
return damageable.hasDamage();
}
return false;
}
public void listAuction(Player seller, AuctionedItem item, boolean bundle, boolean requiresHandRemove) {
listAuction(seller, item.getItem(), item.getItem(), (int) ((item.getExpiresAt() - System.currentTimeMillis()) / 1000), item.getBasePrice(), item.getBidStartingPrice(), item.getBidIncrementPrice(), item.getCurrentPrice(), item.isBidItem(), bundle, requiresHandRemove);
}
@ -609,6 +625,11 @@ public class AuctionAPI {
return;
}
if (!Settings.ALLOW_SALE_OF_DAMAGED_ITEMS.getBoolean() && isDamaged(item)) {
AuctionHouse.getInstance().getLocale().getMessage("general.cannot list damaged item").sendPrefixedMessage(seller);
return;
}
AuctionedItem auctionedItem = new AuctionedItem();
auctionedItem.setId(UUID.randomUUID());
auctionedItem.setOwner(seller.getUniqueId());
@ -643,12 +664,14 @@ public class AuctionAPI {
ItemStack finalItemToSell = item.clone();
int totalOriginal = isUsingBundle ? AuctionAPI.getInstance().getItemCountInPlayerInventory(seller, original) : finalItemToSell.getAmount();
if (isUsingBundle) {
AuctionAPI.getInstance().removeSpecificItemQuantityFromPlayer(seller, original, totalOriginal);
} else {
// if (isUsingBundle) {
// AuctionAPI.getInstance().removeSpecificItemQuantityFromPlayer(seller, original, totalOriginal);
// } else {
// }
if (requiresHandRemove)
PlayerUtils.takeActiveItem(seller, CompatibleHand.MAIN_HAND, totalOriginal);
}
SoundManager.getInstance().playSound(seller, Settings.SOUNDS_LISTED_ITEM_ON_AUCTION_HOUSE.getString(), 1.0F, 1.0F);
String NAX = AuctionHouse.getInstance().getLocale().getMessage("auction.biditemwithdisabledbuynow").getMessage();

View File

@ -9,6 +9,7 @@ import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.compatibility.CompatibleHand;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.utils.PlayerUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -55,6 +56,9 @@ public class CommandAdmin extends AbstractCommand {
case "clearall":
// Don't tell ppl that this exists
AuctionHouse.getInstance().getAuctionItemManager().getItems().clear();
case "durabilitystatus":
Bukkit.broadcastMessage("damaged: " + AuctionAPI.getInstance().isDamaged(PlayerHelper.getHeldItem((Player) sender)));
break;
case "opensell":
if (args.length < 2) return ReturnType.FAILURE;
Player player = PlayerUtils.findPlayer(args[1]);

View File

@ -4,6 +4,7 @@ import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
import ca.tweetzy.auctionhouse.guis.GUIBundleCreation;
import ca.tweetzy.auctionhouse.guis.GUISellItem;
import ca.tweetzy.auctionhouse.guis.confirmation.GUIConfirmListing;
import ca.tweetzy.auctionhouse.helpers.PlayerHelper;
@ -228,6 +229,18 @@ public final class CommandSell extends AbstractCommand {
// update the listing time to the max allowed time if it wasn't set using the command flag
allowedTime = auctionPlayer.getAllowedSellTime(isBiddingItem ? AuctionSaleType.USED_BIDDING_SYSTEM : AuctionSaleType.WITHOUT_BIDDING_SYSTEM);
if (isBundle) {
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIBundleCreation(
auctionPlayer,
allowedTime,
buyNowAllow,
isBiddingItem,
buyNowAllow ? buyNowPrice : -1,
isBiddingItem ? startingBid : 0,
isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0
));
return ReturnType.SUCCESS;
}
if (Settings.ASK_FOR_LISTING_CONFIRMATION.getBoolean()) {
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIConfirmListing(

View File

@ -380,7 +380,7 @@ public class GUIAuctionHouse extends Gui {
if (Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_ENABLED.getBoolean()) {
setButton(Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_SLOT.getInt(), ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_LORE.getStringList(), new HashMap<String, Object>() {{
put("%active_player_auctions%", auctionPlayer.getItems(false).size());
put("%player_balance%", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(auctionPlayer.getPlayer())));
put("%player_balance%", Settings.USE_SHORT_NUMBERS_ON_PLAYER_BALANCE.getBoolean() ? AuctionAPI.getInstance().getFriendlyNumber(EconomyManager.getBalance(auctionPlayer.getPlayer())) : AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(auctionPlayer.getPlayer())));
}}), e -> {
cleanup();
e.manager.showGUI(e.player, new GUIActiveAuctions(this.auctionPlayer));

View File

@ -0,0 +1,125 @@
package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.gui.Gui;
import ca.tweetzy.core.utils.PlayerUtils;
import me.TechsCode.UltraEconomy.base.legacy.Common;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
* Date Created: November 22 2021
* Time Created: 1:11 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public final class GUIBundleCreation extends Gui {
public GUIBundleCreation(AuctionPlayer player, int allowedTime, boolean buyNowAllow, boolean isBiddingItem, Double buyNowPrice, Double startingBid, Double bidIncrement) {
setTitle(Settings.GUI_CREATE_BUNDLE_TITLE.getString());
setRows(6);
setAllowDrops(false);
setAllowShiftClick(true);
setAcceptsItems(true);
setUnlockedRange(0, 44);
setOnClose(close -> {
for (int i = 0; i < 44; i++) {
final ItemStack item = getItem(i);
if (item == null || item.getType() == XMaterial.AIR.parseMaterial()) continue;
PlayerUtils.giveItem(player.getPlayer(), item);
}
});
setButton(49, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_CREATE_BUNDLE_CONFIRM_ITEM.getString(), Settings.GUI_CREATE_BUNDLE_CONFIRM_NAME.getString(), Settings.GUI_CREATE_BUNDLE_CONFIRM_LORE.getStringList(), new HashMap<>()), e -> {
ItemStack firstItem = null;
List<ItemStack> validItems = new ArrayList<>();
for (int i = 0; i < 44; i++) {
final ItemStack item = getItem(i);
if (item == null || item.getType() == XMaterial.AIR.parseMaterial()) continue;
if (Settings.MAKE_BLOCKED_ITEMS_A_WHITELIST.getBoolean()) {
if (!Settings.BLOCKED_ITEMS.getStringList().contains(item.getType().name())) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockeditem").processPlaceholder("item", item.getType().name()).sendPrefixedMessage(e.player);
continue;
}
} else {
if (Settings.BLOCKED_ITEMS.getStringList().contains(item.getType().name())) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockeditem").processPlaceholder("item", item.getType().name()).sendPrefixedMessage(e.player);
continue;
}
}
boolean blocked = false;
String itemName = ChatColor.stripColor(AuctionAPI.getInstance().getItemName(item).toLowerCase());
List<String> itemLore = AuctionAPI.getInstance().getItemLore(item).stream().map(line -> ChatColor.stripColor(line.toLowerCase())).collect(Collectors.toList());
// Check for blocked names and lore
for (String s : Settings.BLOCKED_ITEM_NAMES.getStringList()) {
if (AuctionAPI.getInstance().match(s, itemName)) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockedname").sendPrefixedMessage(e.player);
blocked = true;
}
}
if (!itemLore.isEmpty() && !blocked) {
for (String s : Settings.BLOCKED_ITEM_LORES.getStringList()) {
for (String line : itemLore) {
if (AuctionAPI.getInstance().match(s, line)) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockedlore").sendPrefixedMessage(e.player);
blocked = true;
}
}
}
}
if (blocked) continue;
if (firstItem == null)
firstItem = item;
validItems.add(item);
}
// are they even allowed to sell more items
if (player.isAtSellLimit()) {
AuctionHouse.getInstance().getLocale().getMessage("general.sellinglimit").sendPrefixedMessage(e.player);
return;
}
if (validItems.size() == 0) return;
final ItemStack bundle = AuctionAPI.getInstance().createBundledItem(firstItem, validItems.toArray(new ItemStack[0]));
AuctionAPI.getInstance().listAuction(
player.getPlayer(),
firstItem,
bundle,
allowedTime,
/* buy now price */ buyNowAllow ? buyNowPrice : -1,
/* start bid price */ isBiddingItem ? startingBid : !buyNowAllow ? buyNowPrice : 0,
/* bid inc price */ isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0,
/* current price */ isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice,
isBiddingItem || !buyNowAllow,
true,
false
);
e.gui.exit();
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) {
e.manager.showGUI(e.player, new GUIAuctionHouse(player));
}
});
}
}

View File

@ -191,6 +191,7 @@ public class GUISellItem extends Gui {
builder.sendValueMessage(TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter new buy now price").getMessage()));
builder.toCancel("cancel");
builder.onCancel(p -> reopen(e));
builder.onCommand(p -> reopen(e));
builder.setValue((p, value) -> Double.parseDouble(ChatColor.stripColor(value)));
builder.onFinish((p, value) -> {
this.buyNowPrice = value;
@ -218,6 +219,7 @@ public class GUISellItem extends Gui {
builder.sendValueMessage(TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter new starting bid").getMessage()));
builder.toCancel("cancel");
builder.onCancel(p -> reopen(e));
builder.onCommand(p -> reopen(e));
builder.setValue((p, value) -> Double.parseDouble(ChatColor.stripColor(value)));
builder.onFinish((p, value) -> {
this.bidStartPrice = value;
@ -244,6 +246,7 @@ public class GUISellItem extends Gui {
builder.sendValueMessage(TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter new bid increment").getMessage()));
builder.toCancel("cancel");
builder.onCancel(p -> reopen(e));
builder.onCommand(p -> reopen(e));
builder.setValue((p, value) -> Double.parseDouble(ChatColor.stripColor(value)));
builder.onFinish((p, value) -> {
this.bidIncrementPrice = value;

View File

@ -40,7 +40,7 @@ public class ConfigurationItemHelper {
}
meta.setDisplayName(TextUtils.formatText(title));
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_POTION_EFFECTS);
meta.setLore(lore.stream().map(TextUtils::formatText).collect(Collectors.toList()));
stack.setItemMeta(meta);
if (nbtData != null) {

View File

@ -48,6 +48,7 @@ public class LocaleSettings {
languageNodes.put("general.wait_to_list", "&cPlease wait &4%time%&cs before listing another item");
languageNodes.put("general.please_enter_at_least_one_number", "&cPlease enter at least 1 valid number!");
languageNodes.put("general.mcmmo_ability_active", "&cCannot list item when mcMMO ability is active!");
languageNodes.put("general.cannot list damaged item", "&cCannot list a damaged item!");
languageNodes.put("pricing.minbaseprice", "&cThe minimum base price must be &a$%price%");

View File

@ -45,8 +45,10 @@ public class Settings {
public static final ConfigSetting OWNER_CAN_BID_OWN_ITEM = new ConfigSetting(config, "auction setting.purchase.owner can bid on own item", false, "Should the owner of an auction be able to bid on it?", "This probably should be set to false...");
public static final ConfigSetting AUTO_REFRESH_AUCTION_PAGES = new ConfigSetting(config, "auction setting.auto refresh auction pages", true, "Should auction pages auto refresh?");
public static final ConfigSetting USE_SHORT_NUMBERS_ON_ITEMS = new ConfigSetting(config, "auction setting.use short numbers", false, "Should numbers be shortened into a prefixed form?");
public static final ConfigSetting USE_SHORT_NUMBERS_ON_PLAYER_BALANCE = new ConfigSetting(config, "auction setting.use short numbers on balance", false, "Should numbers be shortened into a prefixed form for the player balance?");
public static final ConfigSetting INCREASE_TIME_ON_BID = new ConfigSetting(config, "auction setting.increase time on bid", true, "Should the remaining time be increased when a bid is placed?");
public static final ConfigSetting TIME_TO_INCREASE_BY_ON_BID = new ConfigSetting(config, "auction setting.time to increase by on the bid", 20, "How many seconds should be added to the remaining time?");
public static final ConfigSetting ALLOW_SALE_OF_DAMAGED_ITEMS = new ConfigSetting(config, "auction setting.allow sale of damaged items", true, "If true, player's can sell items that are damaged (not max durability)");
public static final ConfigSetting TICK_UPDATE_TIME = new ConfigSetting(config, "auction setting.tick auctions every", 1, "How many seconds should pass before the plugin updates all the times on items?");
public static final ConfigSetting CLAIM_MS_DELAY = new ConfigSetting(config, "auction setting.item claim delay", 100, "How many ms should a player wait before being allowed to claim an item?, Ideally you don't wanna change this. It's meant to prevent auto clicker dupe claims");
@ -88,7 +90,10 @@ public class Settings {
public static final ConfigSetting BASE_PRICE_MUST_BE_HIGHER_THAN_BID_START = new ConfigSetting(config, "auction setting.base price must be higher than bid start", true, "Should the base price (buy now price) be higher than the initial bid starting price?");
public static final ConfigSetting SYNC_BASE_PRICE_TO_HIGHEST_PRICE = new ConfigSetting(config, "auction setting.sync the base price to the current price", true, "Ex. If the buy now price was 100, and the current price exceeds 100 to say 200, the buy now price will become 200.");
public static final ConfigSetting CURRENCY_FORMAT = new ConfigSetting(config, "auction setting.currency format", "%,.2f");
// public static final ConfigSetting CURRENCY_DECIMAL_FORMAT = new ConfigSetting(config, "auction setting.currency decimal format", "#,###.#", "Primarily used for the short number format");
public static final ConfigSetting USE_ALTERNATE_CURRENCY_FORMAT = new ConfigSetting(config, "auction setting.use alternate currency format", false, "If true, $123,456.78 will become $123.456,78");
public static final ConfigSetting USE_FLAT_NUMBER_FORMAT = new ConfigSetting(config, "auction setting.use flat number format", false, "If true, $123,456.78 will become $12345678");
public static final ConfigSetting DATE_FORMAT = new ConfigSetting(config, "auction setting.date format", "MMM dd, yyyy hh:mm aa", "You can learn more about date formats by googling SimpleDateFormat patterns or visiting this link", "https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html");
@ -819,6 +824,14 @@ public class Settings {
public static final ConfigSetting GUI_BIDDING_ITEMS_CUSTOM_NAME = new ConfigSetting(config, "gui.bidding.items.custom amount.name", "&a&lCustom Amount");
public static final ConfigSetting GUI_BIDDING_ITEMS_CUSTOM_LORE = new ConfigSetting(config, "gui.bidding.items.custom amount.lore", Collections.singletonList("&7Click to bid a custom amount"));
/* ===============================
* BUNDLES GUI
* ===============================*/
public static final ConfigSetting GUI_CREATE_BUNDLE_TITLE = new ConfigSetting(config, "gui.create bundle.title", "&7Auction House - &eBundle Items");
public static final ConfigSetting GUI_CREATE_BUNDLE_CONFIRM_ITEM = new ConfigSetting(config, "gui.create bundle.items.confirm.item", XMaterial.LIME_STAINED_GLASS_PANE.name());
public static final ConfigSetting GUI_CREATE_BUNDLE_CONFIRM_NAME = new ConfigSetting(config, "gui.create bundle.items.confirm.name", "&a&LConfirm");
public static final ConfigSetting GUI_CREATE_BUNDLE_CONFIRM_LORE = new ConfigSetting(config, "gui.create bundle.items.confirm.lore", Collections.singletonList("&7Click to confirm listing"));
/* ===============================
* AUCTION STACKS
* ===============================*/

View File

@ -38,9 +38,9 @@ public class Test {
//
// System.out.println(getSecondsFromString(arguments));
long future = System.currentTimeMillis() + 1000L * 10;
// long future = System.currentTimeMillis() + 1000L * 10;
System.out.println((future - System.currentTimeMillis()) / 1000);
System.out.println("16".compareTo(System.getProperty("java.version")) <= 0);
}
public static long getSecondsFromString(String time) {