Mass Cancel (#191)

Add an admin command to cancel all current auction house listings.
This commit is contained in:
TrueDarkLord 2025-01-01 19:18:47 -07:00 committed by GitHub
parent 8ab0fafd62
commit de220918ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 62 additions and 6 deletions

View File

@ -25,6 +25,7 @@ public enum Messages {
CANCELLED_ITEM("Cancelled-Item", "&7You have cancelled an item on the auction list, return your items with /ah expired."), CANCELLED_ITEM("Cancelled-Item", "&7You have cancelled an item on the auction list, return your items with /ah expired."),
ITEM_HAS_EXPIRED("Item-Has-Expired", "&7An item you have in the Crazy Auctions has just expired."), ITEM_HAS_EXPIRED("Item-Has-Expired", "&7An item you have in the Crazy Auctions has just expired."),
ADMIN_FORCE_CANCELLED("Admin-Force-Cancelled", "&7You have just force cancelled a sale."), ADMIN_FORCE_CANCELLED("Admin-Force-Cancelled", "&7You have just force cancelled a sale."),
ADMIN_FORCE_CANCELLED_ALL("Admin-Force-Cancelled-All", "&7You have just force cancelled all sales."),
ADMIN_FORCE_CANCELLED_TO_PLAYER("Admin-Force-Cancelled-To-Player", "&cOne of your items was just force cancelled by an Admin."), ADMIN_FORCE_CANCELLED_TO_PLAYER("Admin-Force-Cancelled-To-Player", "&cOne of your items was just force cancelled by an Admin."),
ITEM_DOESNT_EXIST("Item-Doesnt-Exist", "&cThat item isnt in the crazy auctions any more."), ITEM_DOESNT_EXIST("Item-Doesnt-Exist", "&cThat item isnt in the crazy auctions any more."),
MAX_ITEMS("Max-Items", "&cYou cant list any more items to the Crazy Auctions."), MAX_ITEMS("Max-Items", "&cYou cant list any more items to the Crazy Auctions."),

View File

@ -3,10 +3,8 @@ package com.badbones69.crazyauctions.commands;
import com.badbones69.crazyauctions.CrazyAuctions; import com.badbones69.crazyauctions.CrazyAuctions;
import com.badbones69.crazyauctions.Methods; import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.CrazyManager; import com.badbones69.crazyauctions.api.CrazyManager;
import com.badbones69.crazyauctions.api.enums.Category; import com.badbones69.crazyauctions.api.enums.*;
import com.badbones69.crazyauctions.api.enums.Files; import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent;
import com.badbones69.crazyauctions.api.enums.Messages;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.events.AuctionListEvent; import com.badbones69.crazyauctions.api.events.AuctionListEvent;
import com.badbones69.crazyauctions.controllers.GuiListener; import com.badbones69.crazyauctions.controllers.GuiListener;
import com.ryderbelserion.vital.paper.api.files.FileManager; import com.ryderbelserion.vital.paper.api.files.FileManager;
@ -92,6 +90,20 @@ public class AuctionCommand implements CommandExecutor {
return true; return true;
} }
case "force_end_all" -> {
if (!Methods.hasPermission(sender, "force-end-all")) {
return true;
}
if (!(sender instanceof Player player)) {
sender.sendMessage(Messages.PLAYERS_ONLY.getMessage(sender));
return true;
}
forceEndAll(player);
return true;
}
case "view" -> { case "view" -> {
if (!Methods.hasPermission(sender, "view")) { if (!Methods.hasPermission(sender, "view")) {
return true; return true;
@ -455,6 +467,44 @@ public class AuctionCommand implements CommandExecutor {
return ma; return ma;
} }
/**
* Force ends all current listed items from the auction house.
* @param player The {@link Player} that initiated the cancellation.
* @see AuctionCancelledEvent
*/
private void forceEndAll(Player player) {
FileConfiguration data = Files.data.getConfiguration();
int num = 1;
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
while (data.contains("OutOfTime/Cancelled." + num)) num++;
String seller = data.getString("Items." + i + ".Seller");
Player sellerPlayer = Methods.getPlayer(seller);
if (Methods.isOnline(seller) && sellerPlayer != null) {
sellerPlayer.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage(player));
}
AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Methods.getOfflinePlayer(seller)), Methods.fromBase64(data.getString("Items." + i + ".Item")), Reasons.ADMIN_FORCE_CANCEL);
plugin.getServer().getPluginManager().callEvent(event);
data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller"));
data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time"));
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
data.set("OutOfTime/Cancelled." + num + ".Item", data.getString("Items." + i + ".Item"));
data.set("Items." + i, null);
}
Files.data.save();
player.sendMessage(Messages.ADMIN_FORCE_CANCELLED_ALL.getMessage(player));
}
/*private boolean allowBook(ItemStack item) { /*private boolean allowBook(ItemStack item) {
if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof BookMeta bookMeta) { if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof BookMeta bookMeta) {
this.plugin.getLogger().info("Checking " + item.getType() + " for illegal unicode."); this.plugin.getLogger().info("Checking " + item.getType() + " for illegal unicode.");

View File

@ -29,6 +29,7 @@ public class AuctionTab implements TabCompleter {
if (hasPermission(sender, "test")) completions.add("test"); if (hasPermission(sender, "test")) completions.add("test");
if (hasPermission(sender, "admin")) completions.add("reload"); if (hasPermission(sender, "admin")) completions.add("reload");
if (hasPermission(sender, "force-end-all")) completions.add("force_end_all");
if (hasPermission(sender, "view")) completions.add("view"); if (hasPermission(sender, "view")) completions.add("view");
if (hasPermission(sender, "sell")) completions.add("sell"); if (hasPermission(sender, "sell")) completions.add("sell");
if (hasPermission(sender, "bid")) completions.add("bid"); if (hasPermission(sender, "bid")) completions.add("bid");

View File

@ -17,7 +17,6 @@ import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;

View File

@ -11,6 +11,7 @@ Messages:
Cancelled-Item: '&7You have canceled an item on the auction list, return your items with /ah expired.' Cancelled-Item: '&7You have canceled an item on the auction list, return your items with /ah expired.'
Item-Has-Expired: '&7An item you have in the Crazy Auctions has expired.' Item-Has-Expired: '&7An item you have in the Crazy Auctions has expired.'
Admin-Force-Cancelled: '&7You have force canceled a sale.' Admin-Force-Cancelled: '&7You have force canceled a sale.'
Admin-Force-Cancelled-All: '&7You have force canceled all sales.'
Admin-Force-Cancelled-To-Player: '&cOne of your items was force canceled by an Admin.' Admin-Force-Cancelled-To-Player: '&cOne of your items was force canceled by an Admin.'
Item-Doesnt-Exist: '&cThat item isn''t in the crazy auctions any more.' Item-Doesnt-Exist: '&cThat item isn''t in the crazy auctions any more.'
Max-Items: '&cYou can''t list any more items to the Crazy Auctions.' Max-Items: '&cYou can''t list any more items to the Crazy Auctions.'

View File

@ -29,6 +29,9 @@ permissions:
crazyauctions.reload: crazyauctions.reload:
default: op default: op
crazyauctions.force-end-all:
default: op
crazyauctions.bypass: crazyauctions.bypass:
default: false default: false
@ -51,4 +54,5 @@ permissions:
children: children:
crazyauctions.test: true crazyauctions.test: true
crazyauctions.reload: true crazyauctions.reload: true
crazyauctions.bypass: true crazyauctions.bypass: true
crazyauctions.force-end-all: true