mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2024-11-10 10:10:22 +01:00
Added new AuctionExpireEvent
This commit is contained in:
parent
a33ccb28e9
commit
8a0d0b9dfd
@ -4,6 +4,7 @@ import me.badbones69.crazyauctions.api.FileManager;
|
||||
import me.badbones69.crazyauctions.api.FileManager.Files;
|
||||
import me.badbones69.crazyauctions.api.Messages;
|
||||
import me.badbones69.crazyauctions.api.Version;
|
||||
import me.badbones69.crazyauctions.api.events.AuctionExpireEvent;
|
||||
import me.badbones69.crazyauctions.api.events.AuctionWinBidEvent;
|
||||
import me.badbones69.crazyauctions.currency.CurrencyManager;
|
||||
import org.bukkit.*;
|
||||
@ -185,7 +186,7 @@ public class Methods {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void setItemInHand(Player player, ItemStack item) {
|
||||
if(Methods.getVersion() >= 191) {
|
||||
if(getVersion() >= 191) {
|
||||
player.getInventory().setItemInMainHand(item);
|
||||
}else {
|
||||
player.setItemInHand(item);
|
||||
@ -374,24 +375,24 @@ public class Methods {
|
||||
if(cal.after(expireTime)) {
|
||||
int num = 1;
|
||||
for(; data.contains("OutOfTime/Cancelled." + num); num++) ;
|
||||
if(data.getBoolean("Items." + i + ".Biddable") && !data.getString("Items." + i + ".TopBidder").equalsIgnoreCase("None") && CurrencyManager.getMoney(Methods.getPlayer(data.getString("Items." + i + ".TopBidder"))) >= data.getInt("Items." + i + ".Price")) {
|
||||
if(data.getBoolean("Items." + i + ".Biddable") && !data.getString("Items." + i + ".TopBidder").equalsIgnoreCase("None") && CurrencyManager.getMoney(getPlayer(data.getString("Items." + i + ".TopBidder"))) >= data.getInt("Items." + i + ".Price")) {
|
||||
String winner = data.getString("Items." + i + ".TopBidder");
|
||||
String seller = data.getString("Items." + i + ".Seller");
|
||||
Long price = data.getLong("Items." + i + ".Price");
|
||||
CurrencyManager.addMoney(Methods.getOfflinePlayer(seller), price);
|
||||
CurrencyManager.removeMoney(Methods.getOfflinePlayer(winner), price);
|
||||
CurrencyManager.addMoney(getOfflinePlayer(seller), price);
|
||||
CurrencyManager.removeMoney(getOfflinePlayer(winner), price);
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("%Price%", getPrice(i, false));
|
||||
placeholders.put("%price%", getPrice(i, false));
|
||||
placeholders.put("%Player%", winner);
|
||||
placeholders.put("%player%", winner);
|
||||
if(Methods.isOnline(winner)) {
|
||||
Player player = Methods.getPlayer(winner);
|
||||
if(isOnline(winner)) {
|
||||
Player player = getPlayer(winner);
|
||||
Bukkit.getPluginManager().callEvent(new AuctionWinBidEvent(player, data.getItemStack("Items." + i + ".Item"), price));
|
||||
player.sendMessage(Messages.WIN_BIDDING.getMessage(placeholders));
|
||||
}
|
||||
if(Methods.isOnline(seller)) {
|
||||
Player player = Methods.getPlayer(seller);
|
||||
if(isOnline(seller)) {
|
||||
Player player = getPlayer(seller);
|
||||
player.sendMessage(Messages.SOMEONE_WON_PLAYERS_BID.getMessage(placeholders));
|
||||
}
|
||||
data.set("OutOfTime/Cancelled." + num + ".Seller", winner);
|
||||
@ -400,10 +401,12 @@ public class Methods {
|
||||
data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item"));
|
||||
}else {
|
||||
String seller = data.getString("Items." + i + ".Seller");
|
||||
if(Methods.isOnline(seller)) {
|
||||
Player player = Methods.getPlayer(seller);
|
||||
Player player = getPlayer(seller);
|
||||
if(isOnline(seller)) {
|
||||
player.sendMessage(Messages.ITEM_HAS_EXPIRED.getMessage());
|
||||
}
|
||||
AuctionExpireEvent event = new AuctionExpireEvent((player != null ? player : Bukkit.getOfflinePlayer(seller)), data.getItemStack("Items." + i + ".Item"));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis());
|
||||
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
|
||||
|
@ -0,0 +1,70 @@
|
||||
package me.badbones69.crazyauctions.api.events;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BadBones69
|
||||
*
|
||||
* This event is fired when a player item expires.
|
||||
*
|
||||
*/
|
||||
public class AuctionExpireEvent extends Event {
|
||||
|
||||
private OfflinePlayer offlinePlayer;
|
||||
private Player onlinePlayer;
|
||||
private boolean isOnline;
|
||||
private ItemStack item;
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param offlinePlayer The player who's item is expiring.
|
||||
* @param item The item that is expiring.
|
||||
*/
|
||||
public AuctionExpireEvent(OfflinePlayer offlinePlayer, ItemStack item) {
|
||||
this.offlinePlayer = offlinePlayer;
|
||||
this.item = item;
|
||||
this.isOnline = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param onlinePlayer The player who's item is expiring.
|
||||
* @param item The item that is expiring.
|
||||
*/
|
||||
public AuctionExpireEvent(Player onlinePlayer, ItemStack item) {
|
||||
this.onlinePlayer = onlinePlayer;
|
||||
this.item = item;
|
||||
this.isOnline = true;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public OfflinePlayer getOfflinePlayer() {
|
||||
return offlinePlayer;
|
||||
}
|
||||
|
||||
public Player getOnlinePlayer() {
|
||||
return onlinePlayer;
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return isOnline;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user