From 40795decff7844a9404a5eb463ade71cb882f4d3 Mon Sep 17 00:00:00 2001 From: svgaming234 Date: Fri, 23 Jan 2026 21:27:16 +0100 Subject: [PATCH] fix auctionreset not working from console, add error for bid from console, log auction messages to console --- .../java/org/garsooon/AuctionManager.java | 27 +++++++---- .../org/garsooon/Commands/AuctionCommand.java | 5 +- .../Commands/AuctionResetCommand.java | 47 ++++++++++++------- .../org/garsooon/Commands/BidCommand.java | 5 +- 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/garsooon/AuctionManager.java b/src/main/java/org/garsooon/AuctionManager.java index 2b666ba..6dd7851 100644 --- a/src/main/java/org/garsooon/AuctionManager.java +++ b/src/main/java/org/garsooon/AuctionManager.java @@ -1,5 +1,6 @@ package org.garsooon; +import org.bukkit.craftbukkit.CraftServer; import org.garsooon.Economy.Method; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -124,12 +125,12 @@ public boolean startAuction(Player seller, ItemStack item, double price, String durabilityInfo = durColor + " [" + remaining + "/" + maxDur + " durability]"; } - Bukkit.broadcastMessage(ChatColor.GREEN + seller.getName() + " is auctioning " + ChatColor.YELLOW + item.getAmount() + "x " + getItemDisplayName(item) + durabilityInfo + ChatColor.GREEN + " starting at $" + startPrice); + broadcast(ChatColor.GREEN + seller.getName() + " is auctioning " + ChatColor.YELLOW + item.getAmount() + "x " + getItemDisplayName(item) + durabilityInfo + ChatColor.GREEN + " starting at $" + startPrice); if (percentBidIncrement > 0.0) { - Bukkit.broadcastMessage(ChatColor.GRAY + "Minimum bid increase is set to " + percentBidIncrement + "%"); + broadcast(ChatColor.GRAY + "Minimum bid increase is set to " + percentBidIncrement + "%"); } else { - Bukkit.broadcastMessage(ChatColor.GRAY + "Minimum bid increase is set to $" + minBidIncrement); + broadcast(ChatColor.GRAY + "Minimum bid increase is set to $" + minBidIncrement); } scheduleAuctionEnd(); @@ -225,7 +226,7 @@ public boolean bid(Player bidder, double amount) { highestBid = amount; highestBidder = bidder; - Bukkit.broadcastMessage(ChatColor.AQUA + bidder.getName() + " bids $" + amount); + broadcast(ChatColor.AQUA + bidder.getName() + " bids $" + amount); int timeAddPerBid = 10; Object bidAddObj = plugin.getCustomConfig().get("time_add_per_bid"); @@ -247,7 +248,7 @@ public boolean bid(Player bidder, double amount) { if (countdownTaskId != -1) Bukkit.getScheduler().cancelTask(countdownTaskId); scheduleAuctionEnd(); - Bukkit.broadcastMessage(ChatColor.GRAY + "Auction time extended. " + (newRemaining / 1000) + " seconds remain."); + broadcast(ChatColor.GRAY + "Auction time extended. " + (newRemaining / 1000) + " seconds remain."); return true; } @@ -270,7 +271,7 @@ public void run() { } long timeLeft = (auctionEndTime - System.currentTimeMillis()) / 1000L; if ((timeLeft == 10 || timeLeft == 5) && lastAnnounced != (int) timeLeft) { - Bukkit.broadcastMessage(ChatColor.GOLD + "Auction ends in " + timeLeft + " seconds!"); + broadcast(ChatColor.GOLD + "Auction ends in " + timeLeft + " seconds!"); lastAnnounced = (int) timeLeft; } if (timeLeft <= 0) Bukkit.getScheduler().cancelTask(countdownTaskId); @@ -290,7 +291,7 @@ public void endAuction() { highestBidder.sendMessage(ChatColor.YELLOW + "Your inventory was full! The auction item was dropped at your feet."); } - Bukkit.broadcastMessage(ChatColor.GOLD + highestBidder.getName() + " won the auction for $" + highestBid); + broadcast(ChatColor.GOLD + highestBidder.getName() + " won the auction for $" + highestBid); if (economy != null) { Method.MethodAccount sellerAccount = economy.getAccount(currentSeller.getName(), currentSeller.getWorld()); @@ -308,7 +309,7 @@ public void endAuction() { currentSeller.sendMessage(ChatColor.YELLOW + "Your inventory was full! The item was dropped at your feet."); } - Bukkit.broadcastMessage(ChatColor.RED + "Auction ended with no bids."); + broadcast(ChatColor.RED + "Auction ended with no bids."); } currentItem = null; @@ -327,7 +328,7 @@ public void forceEnd() { this.percentBidIncrement = 0.0; this.minBidIncrement = 1.0; - Bukkit.broadcastMessage(ChatColor.RED + "The current auction has been forcibly reset by an admin."); + broadcast(ChatColor.RED + "The current auction has been forcibly reset by an admin."); } public void cleanupStuckAuction() { @@ -343,12 +344,18 @@ public void cleanupStuckAuction() { long gracePeriodEnd = auctionEndTime + (maxAuctionTime * 1000L); if (now > gracePeriodEnd && auctionStartTime < (now - (maxAuctionTime * 1000L))) { - Bukkit.broadcastMessage(ChatColor.RED + "Stuck auction forcibly reset due to timeout."); + broadcast(ChatColor.RED + "Stuck auction forcibly reset due to timeout."); getLogger().warning("[Auctioneer] An auction was forcibly reset due to timeout."); forceEnd(); } } + public void broadcast(String message) { + // Broadcast to console and all players + ((CraftServer) Bukkit.getServer()).getServer().console.sendMessage(message); + Bukkit.broadcastMessage(message); + } + public String getCurrentItemDisplayName() { return currentItem != null ? getItemDisplayName(currentItem) : "Unknown Item"; } diff --git a/src/main/java/org/garsooon/Commands/AuctionCommand.java b/src/main/java/org/garsooon/Commands/AuctionCommand.java index 77b0a91..c795d30 100644 --- a/src/main/java/org/garsooon/Commands/AuctionCommand.java +++ b/src/main/java/org/garsooon/Commands/AuctionCommand.java @@ -16,7 +16,10 @@ public AuctionCommand(AuctionPlugin plugin) { } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) return true; + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "Only players can use this command."); + return true; + } Player player = (Player) sender; diff --git a/src/main/java/org/garsooon/Commands/AuctionResetCommand.java b/src/main/java/org/garsooon/Commands/AuctionResetCommand.java index 6a53ce2..dce19fc 100644 --- a/src/main/java/org/garsooon/Commands/AuctionResetCommand.java +++ b/src/main/java/org/garsooon/Commands/AuctionResetCommand.java @@ -4,6 +4,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.garsooon.AuctionPlugin; import org.garsooon.AuctionManager; @@ -16,6 +17,7 @@ public class AuctionResetCommand implements CommandExecutor { private final AuctionPlugin plugin; private final AuctionManager auctionManager; private final Set confirmationSet = new HashSet<>(); + private boolean confirmationConsole; public AuctionResetCommand(AuctionPlugin plugin) { this.plugin = plugin; @@ -24,30 +26,39 @@ public AuctionResetCommand(AuctionPlugin plugin) { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "Only players can use this command."); - return true; - } - - Player player = (Player) sender; + if (sender instanceof Player) { + Player player = (Player) sender; - if (!player.hasPermission("auctioneer.admin")) { - player.sendMessage(ChatColor.RED + "You do not have permission to use this command."); - return true; - } + if (!player.hasPermission("auctioneer.admin")) { + player.sendMessage(ChatColor.RED + "You do not have permission to use this command."); + return true; + } - String name = player.getName(); + String name = player.getName(); - if (!confirmationSet.contains(name)) { - confirmationSet.add(name); - player.sendMessage(ChatColor.RED + "This will reset the current auction and NOT give items or"); - player.sendMessage(ChatColor.RED + "money back! Run the command again to confirm."); - return true; + if (!confirmationSet.contains(name)) { + confirmationSet.add(name); + sender.sendMessage(ChatColor.RED + "This will reset the current auction and NOT give items or"); + sender.sendMessage(ChatColor.RED + "money back! Run the command again to confirm."); + return true; + } + confirmationSet.remove(name); + } + else if (sender instanceof ConsoleCommandSender) { + if (!confirmationConsole) { + confirmationConsole = true; + sender.sendMessage(ChatColor.RED + "This will reset the current auction and NOT give items or"); + sender.sendMessage(ChatColor.RED + "money back! Run the command again to confirm."); + return true; + } + confirmationConsole = false; + } + else { + return false; } - confirmationSet.remove(name); auctionManager.forceEnd(); - player.sendMessage(ChatColor.GREEN + "Auction forcibly reset."); + sender.sendMessage(ChatColor.GREEN + "Auction forcibly reset."); return true; } } \ No newline at end of file diff --git a/src/main/java/org/garsooon/Commands/BidCommand.java b/src/main/java/org/garsooon/Commands/BidCommand.java index 3e1fe28..c14ee36 100644 --- a/src/main/java/org/garsooon/Commands/BidCommand.java +++ b/src/main/java/org/garsooon/Commands/BidCommand.java @@ -15,7 +15,10 @@ public BidCommand(AuctionPlugin plugin) { } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) return true; + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "Only players can use this command."); + return true; + } Player player = (Player) sender;