🪧 redid the entire discord webhook settings

Took 1 hour 4 minutes
This commit is contained in:
Kiran Hart 2023-02-21 19:04:11 -05:00
parent df86434f13
commit 455bca58b7
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
4 changed files with 315 additions and 166 deletions

View File

@ -19,10 +19,7 @@
package ca.tweetzy.auctionhouse.api;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.hook.MMOItemsHook;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.auction.MinItemPrice;
import ca.tweetzy.auctionhouse.auction.enums.AuctionSaleType;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.ServerVersion;
@ -51,14 +48,11 @@ import org.bukkit.util.io.BukkitObjectOutputStream;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -260,99 +254,6 @@ public class AuctionAPI {
return stack;
}
/**
* Used to send a discord message to a webhook link
*
* @param seller The Seller of the auction item
* @param buyer The Buyer of the auction item
* @param auctionItem The object of the auction item
* @param saleType The sale type, was it a bid won or an immediate purchase?
* @param isNew Is this the start of a new auction or the end of one?
* @param isBid Is this auction a bid enabled auction, or a single sale auction?
*/
public void sendDiscordMessage(String webhook, OfflinePlayer seller, OfflinePlayer buyer, AuctionedItem auctionItem, AuctionSaleType saleType, boolean isNew, boolean isBid) {
final DiscordWebhook hook = new DiscordWebhook(webhook);
hook.setUsername(Settings.DISCORD_MSG_USERNAME.getString());
hook.setAvatarUrl(Settings.DISCORD_MSG_PFP.getString());
final String color = isBid ? Settings.DISCORD_MSG_DEFAULT_COLOUR_BID.getString() : isNew ? Settings.DISCORD_MSG_DEFAULT_COLOUR.getString() : Settings.DISCORD_MSG_DEFAULT_COLOUR_SALE.getString();
final String[] possibleColours = color.split("-");
final Color colour = Settings.DISCORD_MSG_USE_RANDOM_COLOUR.getBoolean()
? Color.getHSBColor(ThreadLocalRandom.current().nextFloat() * 360F, ThreadLocalRandom.current().nextFloat() * 101F, ThreadLocalRandom.current().nextFloat() * 101F)
: Color.getHSBColor(Float.parseFloat(possibleColours[0]) / 360, Float.parseFloat(possibleColours[1]) / 100, Float.parseFloat(possibleColours[2]) / 100);
final ItemStack itemStack = auctionItem.getItem();
final String itemName = MMOItemsHook.isEnabled() ? MMOItemsHook.getItemType(itemStack) : ChatColor.stripColor(getItemName(itemStack));
final DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject();
final String playerLost = AuctionHouse.getInstance().getLocale().getMessage("discord.player_lost").getMessage();
final String notSold = AuctionHouse.getInstance().getLocale().getMessage("discord.not_sold").getMessage();
final String noBuyer = AuctionHouse.getInstance().getLocale().getMessage("discord.no_buyer").getMessage();
final String wasNotBought = AuctionHouse.getInstance().getLocale().getMessage("discord.not_bought").getMessage();
final String isBidTrue = AuctionHouse.getInstance().getLocale().getMessage("discord.is_bid_true").getMessage();
final String isBidFalse = AuctionHouse.getInstance().getLocale().getMessage("discord.is_bid_false").getMessage();
final String isBidWin = AuctionHouse.getInstance().getLocale().getMessage("discord.sale_bid_win").getMessage();
final String immediateBuy = AuctionHouse.getInstance().getLocale().getMessage("discord.sale_immediate_buy").getMessage();
embedObject.setTitle(isNew ? isBid ? Settings.DISCORD_MSG_START_TITLE_BID.getString() : Settings.DISCORD_MSG_START_TITLE.getString() : Settings.DISCORD_MSG_FINISH_TITLE.getString());
embedObject.setColor(colour);
embedObject.addField(Settings.DISCORD_MSG_FIELD_SELLER_NAME.getString(), Settings.DISCORD_MSG_FIELD_SELLER_VALUE.getString().replace("%seller%", seller.getName() != null ? seller.getName() : playerLost), Settings.DISCORD_MSG_FIELD_SELLER_INLINE.getBoolean());
embedObject.addField(Settings.DISCORD_MSG_FIELD_BUYER_NAME.getString(), isNew ? noBuyer : Settings.DISCORD_MSG_FIELD_BUYER_VALUE.getString().replace("%buyer%", buyer.getName() != null ? buyer.getName() : playerLost), Settings.DISCORD_MSG_FIELD_BUYER_INLINE.getBoolean());
embedObject.addField(Settings.DISCORD_MSG_FIELD_BUY_NOW_PRICE_NAME.getString(), Settings.DISCORD_MSG_FIELD_BUY_NOW_PRICE_VALUE.getString().replace("%buy_now_price%", this.getFriendlyNumber(auctionItem.getBasePrice())), Settings.DISCORD_MSG_FIELD_BUY_NOW_PRICE_INLINE.getBoolean());
embedObject.addField(Settings.DISCORD_MSG_FIELD_FINAL_PRICE_NAME.getString(), isNew ? notSold : Settings.DISCORD_MSG_FIELD_FINAL_PRICE_VALUE.getString().replace("%final_price%", this.getFriendlyNumber(isBid ? auctionItem.getCurrentPrice() : auctionItem.getBasePrice())), Settings.DISCORD_MSG_FIELD_FINAL_PRICE_INLINE.getBoolean());
embedObject.addField(Settings.DISCORD_MSG_FIELD_IS_BID_NAME.getString(), Settings.DISCORD_MSG_FIELD_IS_BID_VALUE.getString().replace("%is_bid%", isBid ? isBidTrue : isBidFalse), Settings.DISCORD_MSG_FIELD_IS_BID_INLINE.getBoolean());
embedObject.addField(Settings.DISCORD_MSG_FIELD_PURCHASE_TYPE_NAME.getString(), isNew ? wasNotBought : Settings.DISCORD_MSG_FIELD_PURCHASE_TYPE_VALUE.getString().replace("%purchase_type%", saleType == AuctionSaleType.USED_BIDDING_SYSTEM ? isBidWin : immediateBuy), Settings.DISCORD_MSG_FIELD_PURCHASE_INLINE.getBoolean());
embedObject.addField(Settings.DISCORD_MSG_FIELD_ITEM_NAME.getString(), Settings.DISCORD_MSG_FIELD_ITEM_VALUE.getString().replace("%item_name%", itemName), Settings.DISCORD_MSG_FIELD_ITEM_INLINE.getBoolean());
embedObject.addField(Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_NAME.getString(), Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_VALUE.getString().replace("%item_amount%", String.valueOf(itemStack.getAmount())), Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_INLINE.getBoolean());
hook.addEmbed(embedObject);
try {
hook.execute();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* A simplified version of {@link #sendDiscordMessage(String, OfflinePlayer, OfflinePlayer, AuctionedItem, AuctionSaleType, boolean, boolean)} used
* to just send bid updates
*
* @param webhook the webhook url
* @param auctionItem The object of the auction item
*/
public void sendDiscordBidMessage(String webhook, AuctionedItem auctionItem, double newBid) {
// oh boy the code repetition is high with this one
final DiscordWebhook hook = new DiscordWebhook(webhook);
hook.setUsername(Settings.DISCORD_MSG_USERNAME.getString());
hook.setAvatarUrl(Settings.DISCORD_MSG_PFP.getString());
final String[] possibleColours = Settings.DISCORD_MSG_DEFAULT_COLOUR_BID.getString().split("-");
final Color colour = Settings.DISCORD_MSG_USE_RANDOM_COLOUR.getBoolean()
? Color.getHSBColor(ThreadLocalRandom.current().nextFloat() * 360F, ThreadLocalRandom.current().nextFloat() * 101F, ThreadLocalRandom.current().nextFloat() * 101F)
: Color.getHSBColor(Float.parseFloat(possibleColours[0]) / 360, Float.parseFloat(possibleColours[1]) / 100, Float.parseFloat(possibleColours[2]) / 100);
final ItemStack itemStack = auctionItem.getItem();
final String itemName = MMOItemsHook.isEnabled() ? MMOItemsHook.getItemType(itemStack) : ChatColor.stripColor(getItemName(itemStack));
final DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject();
embedObject.setTitle(Settings.DISCORD_MSG_BID_TITLE.getString());
embedObject.setColor(colour);
embedObject.addField(Settings.DISCORD_MSG_FIELD_BIDDER_NAME.getString(), Settings.DISCORD_MSG_FIELD_BIDDER_VALUE.getString().replace("%bidder%", auctionItem.getHighestBidderName() != null ? auctionItem.getHighestBidderName() : AuctionHouse.getInstance().getLocale().getMessage("discord.player_lost").getMessage()), Settings.DISCORD_MSG_FIELD_BIDDER_INLINE.getBoolean());
embedObject.addField(Settings.DISCORD_MSG_FIELD_BID_PRICE_NAME.getString(), Settings.DISCORD_MSG_FIELD_BID_PRICE_VALUE.getString().replace("%bid_price%", formatNumber(newBid)), Settings.DISCORD_MSG_FIELD_BID_PRICE_INLINE.getBoolean());
embedObject.addField(Settings.DISCORD_MSG_FIELD_ITEM_NAME.getString(), Settings.DISCORD_MSG_FIELD_ITEM_VALUE.getString().replace("%item_name%", itemName), Settings.DISCORD_MSG_FIELD_ITEM_INLINE.getBoolean());
embedObject.addField(Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_NAME.getString(), Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_VALUE.getString().replace("%item_amount%", String.valueOf(itemStack.getAmount())), Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_INLINE.getBoolean());
hook.addEmbed(embedObject);
try {
hook.execute();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Get the name of an item stack
*

View File

@ -0,0 +1,201 @@
/*
* Auction House
* Copyright 2023 Kiran Hart
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ca.tweetzy.auctionhouse.helpers;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.DiscordWebhook;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.flight.utils.ItemUtil;
import lombok.NonNull;
import lombok.SneakyThrows;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import java.awt.*;
public final class DiscordMessageCreator {
public static enum MessageType {
NEW_AUCTION_LISTING,
NEW_BIN_LISTING,
AUCTION_LISTING_WON,
BIN_LISTING_BOUGHT,
BID_PLACED,
}
private final String webhook;
private final MessageType messageType;
private OfflinePlayer seller;
private OfflinePlayer buyer;
private OfflinePlayer bidder;
private AuctionedItem listing;
private double bidAmount;
private DiscordMessageCreator(@NonNull final String webhook, @NonNull final MessageType messageType) {
this.webhook = webhook;
this.messageType = messageType;
}
public static DiscordMessageCreator of(@NonNull final String webhook, @NonNull final MessageType messageType) {
return new DiscordMessageCreator(webhook, messageType);
}
public DiscordMessageCreator seller(@NonNull final OfflinePlayer seller) {
this.seller = seller;
return this;
}
public DiscordMessageCreator buyer(@NonNull final OfflinePlayer buyer) {
this.buyer = buyer;
return this;
}
public DiscordMessageCreator bidder(@NonNull final OfflinePlayer bidder) {
this.bidder = bidder;
return this;
}
public DiscordMessageCreator bidAmount(final double bidAmount) {
this.bidAmount = bidAmount;
return this;
}
public DiscordMessageCreator listing(@NonNull final AuctionedItem listing) {
this.listing = listing;
return this;
}
public DiscordWebhook generate() {
final DiscordWebhook hook = generateBaseHook();
DiscordWebhook.EmbedObject embed = generateBaseEmbed();
embed.addField(Settings.DISCORD_MSG_FIELD_SELLER_NAME.getString(), Settings.DISCORD_MSG_FIELD_SELLER_VALUE.getString().replace("%seller%", this.seller.getName()), Settings.DISCORD_MSG_FIELD_SELLER_INLINE.getBoolean());
embed.addField(Settings.DISCORD_MSG_FIELD_ITEM_NAME.getString(), Settings.DISCORD_MSG_FIELD_ITEM_VALUE.getString().replace("%item_name%", "x" + this.listing.getItem().getAmount() + " " + ChatColor.stripColor(ItemUtil.getStackName(this.listing.getItem()))), Settings.DISCORD_MSG_FIELD_SELLER_INLINE.getBoolean());
switch (this.messageType) {
case NEW_AUCTION_LISTING:
embed = applyAuctionInfo(embed);
break;
case NEW_BIN_LISTING:
embed = applyBinInfo(embed);
break;
case AUCTION_LISTING_WON:
embed = applyAuctionWonInfo(embed);
break;
case BIN_LISTING_BOUGHT:
embed = applyBinPurchaseInfo(embed);
break;
case BID_PLACED:
embed = applyBidInfo(embed);
break;
}
hook.addEmbed(embed);
return hook;
}
public DiscordWebhook.EmbedObject applyBinPurchaseInfo(DiscordWebhook.EmbedObject embed) {
embed = applyBinInfo(embed);
embed.addField(Settings.DISCORD_MSG_FIELD_BIN_BOUGHT_NAME.getString(), Settings.DISCORD_MSG_FIELD_BIN_BOUGHT_VALUE.getString().replace("%buyer%", this.buyer.getName()), Settings.DISCORD_MSG_FIELD_BIN_BOUGHT_INLINE.getBoolean());
return embed;
}
public DiscordWebhook.EmbedObject applyBidInfo(DiscordWebhook.EmbedObject embed) {
embed.addField(Settings.DISCORD_MSG_FIELD_AUCTION_START_PRICE_NAME.getString(), Settings.DISCORD_MSG_FIELD_AUCTION_START_PRICE_VALUE.getString().replace("%starting_price%", AuctionAPI.getInstance().formatNumber(this.listing.getBidStartingPrice())), Settings.DISCORD_MSG_FIELD_AUCTION_START_PRICE_INLINE.getBoolean());
embed.addField(Settings.DISCORD_MSG_FIELD_AUCTION_BIDDER_NAME.getString(), Settings.DISCORD_MSG_FIELD_AUCTION_BIDDER_VALUE.getString().replace("%bidder%", this.bidder.getName()), Settings.DISCORD_MSG_FIELD_AUCTION_BIDDER_INLINE.getBoolean());
embed.addField(Settings.DISCORD_MSG_FIELD_BID_AMT_NAME.getString(), Settings.DISCORD_MSG_FIELD_BID_AMT_VALUE.getString().replace("%bid_amount%", AuctionAPI.getInstance().formatNumber(this.bidAmount)), Settings.DISCORD_MSG_FIELD_BID_AMT_INLINE.getBoolean());
embed.addField(Settings.DISCORD_MSG_FIELD_AUCTION_CURRENT_PRICE_NAME.getString(), Settings.DISCORD_MSG_FIELD_AUCTION_CURRENT_PRICE_VALUE.getString().replace("%current_price%", AuctionAPI.getInstance().formatNumber(this.listing.getCurrentPrice())), Settings.DISCORD_MSG_FIELD_AUCTION_CURRENT_PRICE_INLINE.getBoolean());
return embed;
}
public DiscordWebhook.EmbedObject applyAuctionWonInfo(DiscordWebhook.EmbedObject embed) {
embed.addField(Settings.DISCORD_MSG_FIELD_AUCTION_START_PRICE_NAME.getString(), Settings.DISCORD_MSG_FIELD_AUCTION_START_PRICE_VALUE.getString().replace("%starting_price%", AuctionAPI.getInstance().formatNumber(this.listing.getBidStartingPrice())), Settings.DISCORD_MSG_FIELD_AUCTION_START_PRICE_INLINE.getBoolean());
embed.addField(Settings.DISCORD_MSG_FIELD_AUCTION_WON_NAME.getString(), Settings.DISCORD_MSG_FIELD_AUCTION_WON_VALUE.getString().replace("%final_price%", AuctionAPI.getInstance().formatNumber(this.listing.getCurrentPrice())), Settings.DISCORD_MSG_FIELD_AUCTION_WON_INLINE.getBoolean());
embed.addField(Settings.DISCORD_MSG_FIELD_AUCTION_WINNER_NAME.getString(), Settings.DISCORD_MSG_FIELD_AUCTION_WINNER_VALUE.getString().replace("%winner%", this.buyer.getName()), Settings.DISCORD_MSG_FIELD_AUCTION_WINNER_INLINE.getBoolean());
return embed;
}
public DiscordWebhook.EmbedObject applyBinInfo(DiscordWebhook.EmbedObject embed) {
embed.addField(Settings.DISCORD_MSG_FIELD_BIN_LISTING_PRICE_NAME.getString(), Settings.DISCORD_MSG_FIELD_BIN_LISTING_PRICE_VALUE.getString().replace("%item_price%", AuctionAPI.getInstance().formatNumber(this.listing.getBasePrice())), Settings.DISCORD_MSG_FIELD_BIN_LISTING_PRICE_INLINE.getBoolean());
return embed;
}
public DiscordWebhook.EmbedObject applyAuctionInfo(DiscordWebhook.EmbedObject embed) {
embed.addField(Settings.DISCORD_MSG_FIELD_AUCTION_START_PRICE_NAME.getString(), Settings.DISCORD_MSG_FIELD_AUCTION_START_PRICE_VALUE.getString().replace("%starting_price%", AuctionAPI.getInstance().formatNumber(this.listing.getBidStartingPrice())), Settings.DISCORD_MSG_FIELD_AUCTION_START_PRICE_INLINE.getBoolean());
if (this.listing.getBasePrice() != -1)
embed.addField(Settings.DISCORD_MSG_FIELD_AUCTION_BUYOUT_PRICE_NAME.getString(), Settings.DISCORD_MSG_FIELD_AUCTION_BUYOUT_PRICE_VALUE.getString().replace("%buy_now_price%", AuctionAPI.getInstance().formatNumber(this.listing.getBasePrice())), Settings.DISCORD_MSG_FIELD_AUCTION_BUYOUT_PRICE_INLINE.getBoolean());
return embed;
}
private DiscordWebhook generateBaseHook() {
final DiscordWebhook hook = new DiscordWebhook(this.webhook);
// basic settings
hook.setUsername(Settings.DISCORD_MSG_USERNAME.getString());
hook.setAvatarUrl(Settings.DISCORD_MSG_PFP.getString());
return hook;
}
private DiscordWebhook.EmbedObject generateBaseEmbed() {
final DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject();
// assign title
switch (this.messageType) {
case NEW_AUCTION_LISTING:
embed.setTitle(Settings.DISCORD_TITLE_NEW_AUCTION_LISTING.getString());
embed.setColor(extractColor(Settings.DISCORD_COLOR_NEW_AUCTION_LISTING.getString()));
break;
case NEW_BIN_LISTING:
embed.setTitle(Settings.DISCORD_TITLE_NEW_BIN_LISTING.getString());
embed.setColor(extractColor(Settings.DISCORD_COLOR_NEW_BIN_LISTING.getString()));
break;
case AUCTION_LISTING_WON:
embed.setTitle(Settings.DISCORD_TITLE_AUCTION_LISTING_WON.getString());
embed.setColor(extractColor(Settings.DISCORD_COLOR_AUCTION_LISTING_WON.getString()));
break;
case BIN_LISTING_BOUGHT:
embed.setTitle(Settings.DISCORD_TITLE_BIN_LISTING_BOUGHT.getString());
embed.setColor(extractColor(Settings.DISCORD_COLOR_BIN_LISTING_BOUGHT.getString()));
break;
case BID_PLACED:
embed.setTitle(Settings.DISCORD_TITLE_NEW_BID.getString());
embed.setColor(extractColor(Settings.DISCORD_COLOR_NEW_BID.getString()));
break;
}
return embed;
}
private Color extractColor(@NonNull final String hsbString) {
final String[] possibleColours = hsbString.split("-");
return Color.getHSBColor(Float.parseFloat(possibleColours[0]) / 360, Float.parseFloat(possibleColours[1]) / 100, Float.parseFloat(possibleColours[2]) / 100);
}
@SneakyThrows
public void send() {
generate().execute();
}
}

View File

@ -19,7 +19,6 @@
package ca.tweetzy.auctionhouse.listeners;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.events.AuctionAdminEvent;
import ca.tweetzy.auctionhouse.api.events.AuctionBidEvent;
import ca.tweetzy.auctionhouse.api.events.AuctionEndEvent;
@ -28,8 +27,10 @@ import ca.tweetzy.auctionhouse.auction.AuctionStatistic;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.auction.enums.AuctionSaleType;
import ca.tweetzy.auctionhouse.auction.enums.AuctionStatisticType;
import ca.tweetzy.auctionhouse.helpers.DiscordMessageCreator;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.auctionhouse.transaction.Transaction;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -52,21 +53,29 @@ public class AuctionListeners implements Listener {
final AuctionedItem auctionedItem = e.getAuctionItem();
new AuctionStatistic(seller.getUniqueId(), auctionedItem.isBidItem() ? AuctionStatisticType.CREATED_AUCTION : AuctionStatisticType.CREATED_BIN, 1).store(null);
if (Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_START.getBoolean()) {
AuctionHouse.newChain().async(() -> {
final AuctionAPI instance = AuctionAPI.getInstance();
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> {
instance.sendDiscordMessage(
hook,
seller,
seller,
auctionedItem,
AuctionSaleType.USED_BIDDING_SYSTEM,
true,
auctionedItem.isBidItem()
);
});
}).execute();
if (Settings.DISCORD_ENABLED.getBoolean()) {
if (Settings.DISCORD_ALERT_ON_AUCTION_START.getBoolean())
AuctionHouse.newChain().async(() -> {
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> {
DiscordMessageCreator
.of(hook, DiscordMessageCreator.MessageType.NEW_AUCTION_LISTING)
.seller(seller)
.listing(auctionedItem)
.send();
});
}).execute();
if (Settings.DISCORD_ALERT_ON_BIN_START.getBoolean())
AuctionHouse.newChain().async(() -> {
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> {
DiscordMessageCreator
.of(hook, DiscordMessageCreator.MessageType.NEW_BIN_LISTING)
.seller(seller)
.listing(auctionedItem)
.send();
});
}).execute();
}
}
@ -100,20 +109,44 @@ public class AuctionListeners implements Listener {
});
}
if (Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_FINISH.getBoolean()) {
final AuctionAPI instance = AuctionAPI.getInstance();
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> instance.sendDiscordMessage(hook, originalOwner, buyer, auctionedItem, e.getSaleType(), false, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM));
if (Settings.DISCORD_ENABLED.getBoolean()) {
if (Settings.DISCORD_ALERT_ON_AUCTION_WON.getBoolean() && e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM)
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> {
DiscordMessageCreator
.of(hook, DiscordMessageCreator.MessageType.AUCTION_LISTING_WON)
.seller(originalOwner)
.buyer(e.getBuyer())
.listing(auctionedItem)
.send();
});
if (Settings.DISCORD_ALERT_ON_BIN_BUY.getBoolean() && e.getSaleType() != AuctionSaleType.USED_BIDDING_SYSTEM)
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> {
DiscordMessageCreator
.of(hook, DiscordMessageCreator.MessageType.BIN_LISTING_BOUGHT)
.seller(originalOwner)
.buyer(e.getBuyer())
.listing(auctionedItem)
.send();
});
}
}).execute();
}
@EventHandler
public void onAuctionBid(AuctionBidEvent e) {
if (!Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_BID.getBoolean()) return;
if (!Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_BID.getBoolean()) return;
AuctionHouse.newChain().async(() -> {
final AuctionAPI instance = AuctionAPI.getInstance();
final AuctionedItem auctionedItem = e.getAuctionedItem();
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> instance.sendDiscordBidMessage(hook, auctionedItem, e.getNewBidAmount()));
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> {
DiscordMessageCreator
.of(hook, DiscordMessageCreator.MessageType.BID_PLACED)
.seller(Bukkit.getOfflinePlayer(auctionedItem.getOwner()))
.bidder(e.getBidder())
.bidAmount(e.getNewBidAmount())
.listing(auctionedItem)
.send();
});
}).execute();
}

View File

@ -19,11 +19,11 @@
package ca.tweetzy.auctionhouse.settings;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.flight.comp.enums.CompMaterial;
import ca.tweetzy.core.compatibility.XSound;
import ca.tweetzy.core.configuration.Config;
import ca.tweetzy.core.configuration.ConfigSetting;
import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.flight.comp.enums.CompMaterial;
import java.util.Arrays;
import java.util.Collections;
@ -322,66 +322,80 @@ public class Settings {
public static final ConfigSetting DATABASE_PASSWORD = new ConfigSetting(config, "database.password", "Password1.", "What is the password to the user connecting?");
public static final ConfigSetting DATABASE_CUSTOM_PARAMS = new ConfigSetting(config, "database.custom parameters", "?useUnicode=yes&characterEncoding=UTF-8&useServerPrepStmts=false&rewriteBatchedStatements=true&useSSL=true", "Leave this alone if you don't know what you're doing. Set to 'None' to use no custom connection params");
/* ===============================
* DISCORD WEBHOOK
* DISCORD WEBHOOK NEW
* ===============================*/
public static final ConfigSetting DISCORD_ENABLED = new ConfigSetting(config, "discord.enabled", false, "Should the discord webhook feature be enabled?");
public static final ConfigSetting DISCORD_ALERT_ON_AUCTION_START = new ConfigSetting(config, "discord.alert on auction start", true, "Should a message be sent to the discord server when someone lists a new auction item");
public static final ConfigSetting DISCORD_ALERT_ON_AUCTION_FINISH = new ConfigSetting(config, "discord.alert on auction finish", true, "Should a message be sent when an auction finishes?");
public static final ConfigSetting DISCORD_ALERT_ON_AUCTION_BID = new ConfigSetting(config, "discord.alert on auction bid", true, "Should a message be sent when a new bid is placed on an item?");
public static final ConfigSetting DISCORD_WEBHOOKS = new ConfigSetting(config, "discord.webhooks", Collections.singletonList("https://discord.com/api/webhooks/867470650112737311/kptC6U4rqVjDaJmquq-ijjsR41t1E4qxF94jwgp5zqYwLjbjo3a_Vqp_mhMWGbqYC-Ju"), "A list of webhook urls (channels) you want a message sent to");
public static final ConfigSetting DISCORD_MSG_USERNAME = new ConfigSetting(config, "discord.user.username", "Auction House", "The name of the user who will send the message");
public static final ConfigSetting DISCORD_MSG_PFP = new ConfigSetting(config, "discord.user.avatar picture", "https://cdn.kiranhart.com/spigot/auctionhouse/icon.png", "The avatar image of the discord user");
public static final ConfigSetting DISCORD_MSG_USE_RANDOM_COLOUR = new ConfigSetting(config, "discord.msg.use random colour", true, "colour of the message bar");
public static final ConfigSetting DISCORD_MSG_DEFAULT_COLOUR = new ConfigSetting(config, "discord.msg.default colour", "137-100-100", "The color of the embed, it needs to be in hsb format.", "Separate the numbers with a -");
public static final ConfigSetting DISCORD_MSG_DEFAULT_COLOUR_BID = new ConfigSetting(config, "discord.msg.default colour bid", "137-100-100", "The color of the embed during a bid, it needs to be in hsb format.", "Separate the numbers with a -");
public static final ConfigSetting DISCORD_MSG_DEFAULT_COLOUR_SALE = new ConfigSetting(config, "discord.msg.default colour sale", "137-100-100", "The color of the embed during a sale, it needs to be in hsb format.", "Separate the numbers with a -");
public static final ConfigSetting DISCORD_MSG_START_TITLE = new ConfigSetting(config, "discord.msg.auction start title", "New Auction Available", "The title of the message when a new auction is made");
public static final ConfigSetting DISCORD_WEBHOOKS = new ConfigSetting(config, "discord.webhooks", Collections.singletonList("https://discord.com/api/webhooks/1077667480920653840/CZbJG7DBoGhPXYICgp2--Ey_itVVmYqaQgorBfpvL7nQoQZWWMxz1TQgs1xG45Mzlpsn"), "A list of webhook urls (channels) you want a message sent to");
public static final ConfigSetting DISCORD_MSG_START_TITLE_BID = new ConfigSetting(config, "discord.msg.auction start title bid", "New Bid Item Available", "The title of the message when a new biddable auction is made");
public static final ConfigSetting DISCORD_MSG_FINISH_TITLE = new ConfigSetting(config, "discord.msg.auction finish title", "Auction Finished", "The title of the message when an auction finishes");
public static final ConfigSetting DISCORD_MSG_BID_TITLE = new ConfigSetting(config, "discord.msg.auction bid title", "New Bid Placed", "The title of the message when a new bid is placed");
// options for when the alerts should be sent
public static final ConfigSetting DISCORD_ALERT_ON_AUCTION_START = new ConfigSetting(config, "discord.alerts.new auction listing", true, "Should a message be sent when a new auction listing is made");
public static final ConfigSetting DISCORD_ALERT_ON_BIN_START = new ConfigSetting(config, "discord.alerts.new bin listing", true, "Should a message be sent when a new bin listing is made (non biddable)");
public static final ConfigSetting DISCORD_ALERT_ON_BID = new ConfigSetting(config, "discord.alerts.new bid", true, "Should a message be sent when a bid is placed on an item");
public static final ConfigSetting DISCORD_ALERT_ON_BIN_BUY = new ConfigSetting(config, "discord.alerts.bin listing bought", true, "Should a message be sent when an item is bought");
public static final ConfigSetting DISCORD_ALERT_ON_AUCTION_WON = new ConfigSetting(config, "discord.alerts.auction listing won", true, "Should a message be sent when an auction is won");
// colors for each message
public static final ConfigSetting DISCORD_COLOR_NEW_AUCTION_LISTING = new ConfigSetting(config, "discord.colors.new auction listing", "137-100-100", "The color of the embed, it needs to be in hsb format.", "Separate the numbers with a -");
public static final ConfigSetting DISCORD_COLOR_NEW_BIN_LISTING = new ConfigSetting(config, "discord.colors.new bin listing", "137-100-100", "The color of the embed, it needs to be in hsb format.", "Separate the numbers with a -");
public static final ConfigSetting DISCORD_COLOR_NEW_BID = new ConfigSetting(config, "discord.colors.new bid", "137-100-100", "The color of the embed, it needs to be in hsb format.", "Separate the numbers with a -");
public static final ConfigSetting DISCORD_COLOR_BIN_LISTING_BOUGHT = new ConfigSetting(config, "discord.colors.bin listing bought", "137-100-100", "The color of the embed, it needs to be in hsb format.", "Separate the numbers with a -");
public static final ConfigSetting DISCORD_COLOR_AUCTION_LISTING_WON = new ConfigSetting(config, "discord.colors.auction listing won", "137-100-100", "The color of the embed, it needs to be in hsb format.", "Separate the numbers with a -");
// titles for each message
public static final ConfigSetting DISCORD_TITLE_NEW_AUCTION_LISTING = new ConfigSetting(config, "discord.titles.new auction listing", "New Auction Listing");
public static final ConfigSetting DISCORD_TITLE_NEW_BIN_LISTING = new ConfigSetting(config, "discord.titles.new bin listing", "New Bin Listing");
public static final ConfigSetting DISCORD_TITLE_NEW_BID = new ConfigSetting(config, "discord.titles.new bid", "New Bid");
public static final ConfigSetting DISCORD_TITLE_BIN_LISTING_BOUGHT = new ConfigSetting(config, "discord.titles.bin listing bought", "Listing Bought");
public static final ConfigSetting DISCORD_TITLE_AUCTION_LISTING_WON = new ConfigSetting(config, "discord.titles.auction listing won", "Auction Won");
// fields
public static final ConfigSetting DISCORD_MSG_FIELD_SELLER_NAME = new ConfigSetting(config, "discord.field.seller.name", "Seller");
public static final ConfigSetting DISCORD_MSG_FIELD_SELLER_VALUE = new ConfigSetting(config, "discord.field.seller.value", "%seller%");
public static final ConfigSetting DISCORD_MSG_FIELD_SELLER_INLINE = new ConfigSetting(config, "discord.field.seller.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_SELLER_NAME = new ConfigSetting(config, "discord.msg.seller.name", "Seller");
public static final ConfigSetting DISCORD_MSG_FIELD_SELLER_VALUE = new ConfigSetting(config, "discord.msg.seller.value", "%seller%");
public static final ConfigSetting DISCORD_MSG_FIELD_SELLER_INLINE = new ConfigSetting(config, "discord.msg.seller.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_NAME = new ConfigSetting(config, "discord.field.item.name", "Item");
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_VALUE = new ConfigSetting(config, "discord.field.item.value", "%item_name%");
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_INLINE = new ConfigSetting(config, "discord.field.item.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_BUYER_NAME = new ConfigSetting(config, "discord.msg.buyer.name", "Buyer");
public static final ConfigSetting DISCORD_MSG_FIELD_BUYER_VALUE = new ConfigSetting(config, "discord.msg.buyer.value", "%buyer%");
public static final ConfigSetting DISCORD_MSG_FIELD_BUYER_INLINE = new ConfigSetting(config, "discord.msg.buyer.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_BIN_LISTING_PRICE_NAME = new ConfigSetting(config, "discord.field.bin listing price.name", "Price");
public static final ConfigSetting DISCORD_MSG_FIELD_BIN_LISTING_PRICE_VALUE = new ConfigSetting(config, "discord.field.bin listing price.value", "%item_price%");
public static final ConfigSetting DISCORD_MSG_FIELD_BIN_LISTING_PRICE_INLINE = new ConfigSetting(config, "discord.field.bin listing price.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_BIDDER_NAME = new ConfigSetting(config, "discord.msg.bidder.name", "Bidder");
public static final ConfigSetting DISCORD_MSG_FIELD_BIDDER_VALUE = new ConfigSetting(config, "discord.msg.bidder.value", "%bidder%");
public static final ConfigSetting DISCORD_MSG_FIELD_BIDDER_INLINE = new ConfigSetting(config, "discord.msg.bidder.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_AMOUNT_NAME = new ConfigSetting(config, "discord.field.item amount.name", "Quantity");
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_AMOUNT_VALUE = new ConfigSetting(config, "discord.field.item amount.value", "%item_amount%");
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_AMOUNT_INLINE = new ConfigSetting(config, "discord.field.item amount.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_BID_PRICE_NAME = new ConfigSetting(config, "discord.msg.bid price.name", "Amount Bid");
public static final ConfigSetting DISCORD_MSG_FIELD_BID_PRICE_VALUE = new ConfigSetting(config, "discord.msg.bid price.value", "%bid_price%");
public static final ConfigSetting DISCORD_MSG_FIELD_BID_PRICE_INLINE = new ConfigSetting(config, "discord.msg.bid price.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_BUYOUT_PRICE_NAME = new ConfigSetting(config, "discord.field.auction buyout price.name", "Buy Now Price");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_BUYOUT_PRICE_VALUE = new ConfigSetting(config, "discord.field.auction buyout price.value", "%buy_now_price%");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_BUYOUT_PRICE_INLINE = new ConfigSetting(config, "discord.field.auction buyout price.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_BUY_NOW_PRICE_NAME = new ConfigSetting(config, "discord.msg.buy now price.name", "Buy Now Price");
public static final ConfigSetting DISCORD_MSG_FIELD_BUY_NOW_PRICE_VALUE = new ConfigSetting(config, "discord.msg.buy now price.value", "$%buy_now_price%");
public static final ConfigSetting DISCORD_MSG_FIELD_BUY_NOW_PRICE_INLINE = new ConfigSetting(config, "discord.msg.buy now price.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_START_PRICE_NAME = new ConfigSetting(config, "discord.field.auction start price.name", "Starting Price");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_START_PRICE_VALUE = new ConfigSetting(config, "discord.field.auction start price.value", "%starting_price%");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_START_PRICE_INLINE = new ConfigSetting(config, "discord.field.auction start price.inline", false);
public static final ConfigSetting DISCORD_MSG_FIELD_FINAL_PRICE_NAME = new ConfigSetting(config, "discord.msg.final price.name", "Final Price");
public static final ConfigSetting DISCORD_MSG_FIELD_FINAL_PRICE_VALUE = new ConfigSetting(config, "discord.msg.final price.value", "$%final_price%");
public static final ConfigSetting DISCORD_MSG_FIELD_FINAL_PRICE_INLINE = new ConfigSetting(config, "discord.msg.final price.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_BIN_BOUGHT_NAME = new ConfigSetting(config, "discord.field.bin listing bought.name", "Buyer");
public static final ConfigSetting DISCORD_MSG_FIELD_BIN_BOUGHT_VALUE = new ConfigSetting(config, "discord.field.bin listing bought.value", "%buyer%");
public static final ConfigSetting DISCORD_MSG_FIELD_BIN_BOUGHT_INLINE = new ConfigSetting(config, "discord.field.bin listing bought.inline", false);
public static final ConfigSetting DISCORD_MSG_FIELD_IS_BID_NAME = new ConfigSetting(config, "discord.msg.is bid.name", "Was Bid");
public static final ConfigSetting DISCORD_MSG_FIELD_IS_BID_VALUE = new ConfigSetting(config, "discord.msg.is bid.value", "%is_bid%");
public static final ConfigSetting DISCORD_MSG_FIELD_IS_BID_INLINE = new ConfigSetting(config, "discord.msg.is bid.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_WON_NAME = new ConfigSetting(config, "discord.field.auction listing won price.name", "Final Price");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_WON_VALUE = new ConfigSetting(config, "discord.field.auction listing won price.value", "%final_price%");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_WON_INLINE = new ConfigSetting(config, "discord.field.auction listing won price.inline", false);
public static final ConfigSetting DISCORD_MSG_FIELD_PURCHASE_TYPE_NAME = new ConfigSetting(config, "discord.msg.purchase type.name", "Purchase Type");
public static final ConfigSetting DISCORD_MSG_FIELD_PURCHASE_TYPE_VALUE = new ConfigSetting(config, "discord.msg.purchase type.value", "%purchase_type%");
public static final ConfigSetting DISCORD_MSG_FIELD_PURCHASE_INLINE = new ConfigSetting(config, "discord.msg.purchase type.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_WINNER_NAME = new ConfigSetting(config, "discord.field.auction winner.name", "Winner");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_WINNER_VALUE = new ConfigSetting(config, "discord.field.auction winner.value", "%winner%");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_WINNER_INLINE = new ConfigSetting(config, "discord.field.auction winner.inline", false);
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_NAME = new ConfigSetting(config, "discord.msg.item.name", "Item Name");
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_VALUE = new ConfigSetting(config, "discord.msg.item.value", "%item_name%");
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_INLINE = new ConfigSetting(config, "discord.msg.item.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_BIDDER_NAME = new ConfigSetting(config, "discord.field.auction bidder.name", "Bidder");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_BIDDER_VALUE = new ConfigSetting(config, "discord.field.auction bidder.value", "%bidder%");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_BIDDER_INLINE = new ConfigSetting(config, "discord.field.auction bidder.inline", false);
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_AMOUNT_NAME = new ConfigSetting(config, "discord.msg.item amount.name", "Item Amount");
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_AMOUNT_VALUE = new ConfigSetting(config, "discord.msg.item amount.value", "%item_amount%");
public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_AMOUNT_INLINE = new ConfigSetting(config, "discord.msg.item amount.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_BID_AMT_NAME = new ConfigSetting(config, "discord.field.bid amount.name", "Bid Amount");
public static final ConfigSetting DISCORD_MSG_FIELD_BID_AMT_VALUE = new ConfigSetting(config, "discord.field.bid amount.value", "%bid_amount%");
public static final ConfigSetting DISCORD_MSG_FIELD_BID_AMT_INLINE = new ConfigSetting(config, "discord.field.bid amount.inline", true);
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_CURRENT_PRICE_NAME = new ConfigSetting(config, "discord.field.current auction price.name", "Current Price");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_CURRENT_PRICE_VALUE = new ConfigSetting(config, "discord.field.current auction price.value", "%current_price%");
public static final ConfigSetting DISCORD_MSG_FIELD_AUCTION_CURRENT_PRICE_INLINE = new ConfigSetting(config, "discord.field.current auction price.inline", true);
/* ===============================
* BLACK LISTED