Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/main/java/org/garsooon/AuctionManager.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -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;
Expand All @@ -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() {
Expand All @@ -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";
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/garsooon/Commands/AuctionCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
47 changes: 29 additions & 18 deletions src/main/java/org/garsooon/Commands/AuctionResetCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +17,7 @@ public class AuctionResetCommand implements CommandExecutor {
private final AuctionPlugin plugin;
private final AuctionManager auctionManager;
private final Set<String> confirmationSet = new HashSet<>();
private boolean confirmationConsole;

public AuctionResetCommand(AuctionPlugin plugin) {
this.plugin = plugin;
Expand All @@ -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;
}
}
5 changes: 4 additions & 1 deletion src/main/java/org/garsooon/Commands/BidCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading