mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2025-02-01 23:23:20 +01:00
Mass Cancel (#191)
Add an admin command to cancel all current auction house listings.
This commit is contained in:
parent
8ab0fafd62
commit
de220918ae
@ -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."),
|
||||
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_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."),
|
||||
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."),
|
||||
|
@ -3,10 +3,8 @@ package com.badbones69.crazyauctions.commands;
|
||||
import com.badbones69.crazyauctions.CrazyAuctions;
|
||||
import com.badbones69.crazyauctions.Methods;
|
||||
import com.badbones69.crazyauctions.api.CrazyManager;
|
||||
import com.badbones69.crazyauctions.api.enums.Category;
|
||||
import com.badbones69.crazyauctions.api.enums.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.Messages;
|
||||
import com.badbones69.crazyauctions.api.enums.ShopType;
|
||||
import com.badbones69.crazyauctions.api.enums.*;
|
||||
import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent;
|
||||
import com.badbones69.crazyauctions.api.events.AuctionListEvent;
|
||||
import com.badbones69.crazyauctions.controllers.GuiListener;
|
||||
import com.ryderbelserion.vital.paper.api.files.FileManager;
|
||||
@ -92,6 +90,20 @@ public class AuctionCommand implements CommandExecutor {
|
||||
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" -> {
|
||||
if (!Methods.hasPermission(sender, "view")) {
|
||||
return true;
|
||||
@ -455,6 +467,44 @@ public class AuctionCommand implements CommandExecutor {
|
||||
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) {
|
||||
if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof BookMeta bookMeta) {
|
||||
this.plugin.getLogger().info("Checking " + item.getType() + " for illegal unicode.");
|
||||
|
@ -29,6 +29,7 @@ public class AuctionTab implements TabCompleter {
|
||||
|
||||
if (hasPermission(sender, "test")) completions.add("test");
|
||||
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, "sell")) completions.add("sell");
|
||||
if (hasPermission(sender, "bid")) completions.add("bid");
|
||||
|
@ -17,7 +17,6 @@ import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -11,6 +11,7 @@ Messages:
|
||||
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.'
|
||||
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.'
|
||||
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.'
|
||||
|
@ -29,6 +29,9 @@ permissions:
|
||||
crazyauctions.reload:
|
||||
default: op
|
||||
|
||||
crazyauctions.force-end-all:
|
||||
default: op
|
||||
|
||||
crazyauctions.bypass:
|
||||
default: false
|
||||
|
||||
@ -51,4 +54,5 @@ permissions:
|
||||
children:
|
||||
crazyauctions.test: true
|
||||
crazyauctions.reload: true
|
||||
crazyauctions.bypass: true
|
||||
crazyauctions.bypass: true
|
||||
crazyauctions.force-end-all: true
|
Loading…
Reference in New Issue
Block a user