mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-02-02 17:01:23 +01:00
✨ added option to delay sending new auction/bin listing discord messages
Took 26 minutes
This commit is contained in:
parent
141b17e590
commit
fa931c1027
@ -28,6 +28,7 @@ import ca.tweetzy.auctionhouse.listeners.*;
|
||||
import ca.tweetzy.auctionhouse.managers.*;
|
||||
import ca.tweetzy.auctionhouse.model.manager.BanManager;
|
||||
import ca.tweetzy.auctionhouse.model.manager.CurrencyManager;
|
||||
import ca.tweetzy.auctionhouse.model.manager.ListingManager;
|
||||
import ca.tweetzy.auctionhouse.model.manager.PaymentsManager;
|
||||
import ca.tweetzy.auctionhouse.settings.LocaleSettings;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
@ -85,6 +86,7 @@ public class AuctionHouse extends TweetyPlugin {
|
||||
private final CurrencyManager currencyManager = new CurrencyManager();
|
||||
private final CommandManager commandManager = new CommandManager(this);
|
||||
private final GuiManager guiManager = new GuiManager(this);
|
||||
private final ListingManager listingManager = new ListingManager();
|
||||
|
||||
private final AuctionPlayerManager auctionPlayerManager = new AuctionPlayerManager();
|
||||
private final AuctionItemManager auctionItemManager = new AuctionItemManager();
|
||||
@ -96,6 +98,8 @@ public class AuctionHouse extends TweetyPlugin {
|
||||
private final PaymentsManager paymentsManager = new PaymentsManager();
|
||||
|
||||
|
||||
|
||||
|
||||
// the default vault economy
|
||||
private Economy economy = null;
|
||||
|
||||
@ -318,6 +322,8 @@ public class AuctionHouse extends TweetyPlugin {
|
||||
|
||||
shutdownDataManager(this.dataManager);
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
// send out remaining webhooks
|
||||
// this.listingManager.sendPendingDiscordWebhooks();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -394,6 +400,10 @@ public class AuctionHouse extends TweetyPlugin {
|
||||
return getInstance().currencyManager;
|
||||
}
|
||||
|
||||
public static ListingManager getListingManager() {
|
||||
return getInstance().listingManager;
|
||||
}
|
||||
|
||||
public static Economy getEconomy() {
|
||||
return getInstance().economy;
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ public class GUIActiveAuctions extends AuctionUpdatingPagedGUI<AuctionedItem> {
|
||||
continue;
|
||||
|
||||
if (item.isRequest()) {
|
||||
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(item);
|
||||
AuctionHouse.getAuctionItemManager().sendToGarbage(item);
|
||||
} else {
|
||||
item.setExpired(true);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import ca.tweetzy.auctionhouse.events.AuctionAdminEvent;
|
||||
import ca.tweetzy.auctionhouse.events.AuctionBidEvent;
|
||||
import ca.tweetzy.auctionhouse.events.AuctionEndEvent;
|
||||
import ca.tweetzy.auctionhouse.events.AuctionStartEvent;
|
||||
import ca.tweetzy.auctionhouse.helpers.discord.DiscordMessageCreator;
|
||||
import ca.tweetzy.auctionhouse.model.discord.DiscordMessageCreator;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.auctionhouse.transaction.Transaction;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -62,20 +62,32 @@ public class AuctionListeners implements Listener {
|
||||
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> {
|
||||
final boolean isBid = e.getAuctionItem().isBidItem();
|
||||
|
||||
if (isBid && Settings.DISCORD_ALERT_ON_AUCTION_START.getBoolean())
|
||||
DiscordMessageCreator
|
||||
if (isBid && Settings.DISCORD_ALERT_ON_AUCTION_START.getBoolean()) {
|
||||
DiscordMessageCreator webhook = DiscordMessageCreator
|
||||
.of(hook, DiscordMessageCreator.MessageType.NEW_AUCTION_LISTING)
|
||||
.seller(seller)
|
||||
.listing(auctionedItem)
|
||||
.send();
|
||||
.listing(auctionedItem);
|
||||
|
||||
if (!isBid && Settings.DISCORD_ALERT_ON_BIN_START.getBoolean())
|
||||
DiscordMessageCreator
|
||||
if (Settings.DISCORD_DELAY_LISTINGS.getBoolean()) {
|
||||
AuctionHouse.getListingManager().addListingWebhook(auctionedItem.getId(), webhook);
|
||||
return;
|
||||
}
|
||||
|
||||
webhook.send();
|
||||
}
|
||||
|
||||
if (!isBid && Settings.DISCORD_ALERT_ON_BIN_START.getBoolean()) {
|
||||
DiscordMessageCreator webhook = DiscordMessageCreator
|
||||
.of(hook, DiscordMessageCreator.MessageType.NEW_BIN_LISTING)
|
||||
.seller(seller)
|
||||
.listing(auctionedItem)
|
||||
.send();
|
||||
.listing(auctionedItem);
|
||||
|
||||
if (Settings.DISCORD_DELAY_LISTINGS.getBoolean()) {
|
||||
AuctionHouse.getListingManager().addListingWebhook(auctionedItem.getId(), webhook);
|
||||
return;
|
||||
}
|
||||
webhook.send();
|
||||
}
|
||||
});
|
||||
}).execute();
|
||||
|
||||
@ -94,18 +106,18 @@ public class AuctionListeners implements Listener {
|
||||
new AuctionStatistic(originalOwnerUUID, AuctionStatisticType.MONEY_EARNED, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM ? auctionedItem.getCurrentPrice() : auctionedItem.getBasePrice()).store(null);
|
||||
}
|
||||
|
||||
AuctionHouse.getListingManager().cancelListingWebhook(auctionedItem.getId());
|
||||
new AuctionStatistic(buyerUUID, AuctionStatisticType.MONEY_SPENT, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM ? auctionedItem.getCurrentPrice() : auctionedItem.getBasePrice()).store(null);
|
||||
|
||||
AuctionHouse.newChain().async(() -> {
|
||||
if (Settings.RECORD_TRANSACTIONS.getBoolean()) {
|
||||
final AuctionHouse instance = AuctionHouse.getInstance();
|
||||
|
||||
double price = auctionedItem.getBasePrice();
|
||||
if (e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM) {
|
||||
price = auctionedItem.getCurrentPrice();
|
||||
}
|
||||
|
||||
instance.getDataManager().insertTransaction(new Transaction(
|
||||
AuctionHouse.getDataManager().insertTransaction(new Transaction(
|
||||
UUID.randomUUID(),
|
||||
originalOwnerUUID,
|
||||
buyerUUID,
|
||||
@ -117,7 +129,7 @@ public class AuctionListeners implements Listener {
|
||||
price
|
||||
), (error, transaction) -> {
|
||||
if (error == null) {
|
||||
instance.getTransactionManager().addTransaction(transaction);
|
||||
AuctionHouse.getTransactionManager().addTransaction(transaction);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -166,6 +178,7 @@ public class AuctionListeners implements Listener {
|
||||
@EventHandler
|
||||
public void onAdminAction(AuctionAdminEvent event) {
|
||||
if (!Settings.LOG_ADMIN_ACTIONS.getBoolean()) return;
|
||||
AuctionHouse.getInstance().getDataManager().insertLog(event.getAuctionAdminLog());
|
||||
AuctionHouse.getListingManager().cancelListingWebhook(event.getAuctionAdminLog().getItemId());
|
||||
AuctionHouse.getDataManager().insertLog(event.getAuctionAdminLog());
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.helpers.discord;
|
||||
package ca.tweetzy.auctionhouse.model.discord;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.auctionhouse.api.AuctionAPI;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
|
||||
import ca.tweetzy.auctionhouse.helpers.AuctionCreator;
|
||||
@ -197,6 +198,7 @@ public final class DiscordMessageCreator {
|
||||
|
||||
@SneakyThrows
|
||||
public void send() {
|
||||
generate().execute();
|
||||
final DiscordWebhook hook = generate();
|
||||
hook.execute();
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.helpers.discord;
|
||||
package ca.tweetzy.auctionhouse.model.discord;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.awt.*;
|
@ -1,18 +1,43 @@
|
||||
package ca.tweetzy.auctionhouse.model.manager;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.auctionhouse.api.auction.Auction;
|
||||
import ca.tweetzy.auctionhouse.api.manager.KeyValueManager;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
|
||||
import ca.tweetzy.auctionhouse.model.discord.DiscordMessageCreator;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.flight.collection.expiringmap.ExpiringMap;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class ListingManager extends KeyValueManager<UUID, Auction> {
|
||||
|
||||
private final ExpiringMap<UUID, DiscordMessageCreator> PENDING_DISCORD_WEBHOOKS = ExpiringMap.builder().variableExpiration().build();
|
||||
|
||||
public ListingManager() {
|
||||
super("Listing");
|
||||
this.PENDING_DISCORD_WEBHOOKS.addAsyncExpirationListener((id, hookCreator) -> {
|
||||
final AuctionedItem item = AuctionHouse.getAuctionItemManager().getItem(id);
|
||||
if (item == null || item.isExpired()) return;
|
||||
|
||||
hookCreator.send();
|
||||
});
|
||||
}
|
||||
|
||||
public void addListingWebhook(UUID uuid, DiscordMessageCreator hook) {
|
||||
this.PENDING_DISCORD_WEBHOOKS.put(uuid, hook, Settings.DISCORD_DELAY_LISTING_TIME.getInt(), TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void cancelListingWebhook(UUID uuid) {
|
||||
this.PENDING_DISCORD_WEBHOOKS.remove(uuid);
|
||||
}
|
||||
|
||||
public void sendPendingDiscordWebhooks() {
|
||||
this.PENDING_DISCORD_WEBHOOKS.keySet().forEach(id -> this.PENDING_DISCORD_WEBHOOKS.setExpiration(id, 1L, TimeUnit.NANOSECONDS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -390,6 +390,8 @@ public class Settings {
|
||||
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_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_DELAY_LISTINGS = new ConfigSetting(config, "discord.delay options.delay listing", false, "If true AuctionHouse will delay sending new listing messages by the specified seconds.");
|
||||
public static final ConfigSetting DISCORD_DELAY_LISTING_TIME = new ConfigSetting(config, "discord.delay options.delay listing time", 10, "How many seconds should Auction House wait to send the discord message for new listings");
|
||||
|
||||
// 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");
|
||||
|
Loading…
Reference in New Issue
Block a user