mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2024-11-29 13:05:59 +01:00
Added new AuctionCancelledEvent.
This commit is contained in:
parent
0a9e4b3eed
commit
a33ccb28e9
@ -0,0 +1,14 @@
|
||||
package me.badbones69.crazyauctions.api.enums;
|
||||
|
||||
public enum CancelledReason {
|
||||
|
||||
/**
|
||||
* Cancelled by an administrator.
|
||||
*/
|
||||
ADMIN_FORCE_CANCEL(),
|
||||
/**
|
||||
* Cancelled by the player them self.
|
||||
*/
|
||||
PLAYER_FORCE_CANCEL()
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package me.badbones69.crazyauctions.api.events;
|
||||
|
||||
import me.badbones69.crazyauctions.api.enums.CancelledReason;
|
||||
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's item is cancelled.
|
||||
*
|
||||
*/
|
||||
public class AuctionCancelledEvent extends Event {
|
||||
|
||||
private OfflinePlayer offlinePlayer;
|
||||
private Player onlinePlayer;
|
||||
private boolean isOnline;
|
||||
private ItemStack item;
|
||||
private CancelledReason reason;
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param offlinePlayer The player who's item is cancelled.
|
||||
* @param item The item that is cancelled.
|
||||
*/
|
||||
public AuctionCancelledEvent(OfflinePlayer offlinePlayer, ItemStack item, CancelledReason reason) {
|
||||
this.offlinePlayer = offlinePlayer;
|
||||
this.item = item;
|
||||
this.isOnline = false;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param onlinePlayer The player who's item is cancelled.
|
||||
* @param item The item that is cancelled.
|
||||
*/
|
||||
public AuctionCancelledEvent(Player onlinePlayer, ItemStack item, CancelledReason reason) {
|
||||
this.onlinePlayer = onlinePlayer;
|
||||
this.item = item;
|
||||
this.isOnline = true;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public CancelledReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,9 @@ package me.badbones69.crazyauctions.controllers;
|
||||
import me.badbones69.crazyauctions.Methods;
|
||||
import me.badbones69.crazyauctions.api.*;
|
||||
import me.badbones69.crazyauctions.api.FileManager.Files;
|
||||
import me.badbones69.crazyauctions.api.enums.CancelledReason;
|
||||
import me.badbones69.crazyauctions.api.events.AuctionBuyEvent;
|
||||
import me.badbones69.crazyauctions.api.events.AuctionCancelledEvent;
|
||||
import me.badbones69.crazyauctions.api.events.AuctionNewBidEvent;
|
||||
import me.badbones69.crazyauctions.currency.CurrencyManager;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -629,10 +631,12 @@ public class GUI implements Listener {
|
||||
int num = 1;
|
||||
for(; data.contains("OutOfTime/Cancelled." + num); num++) ;
|
||||
String seller = data.getString("Items." + i + ".Seller");
|
||||
Player sellerPlayer = Methods.getPlayer(seller);
|
||||
if(Methods.isOnline(seller)) {
|
||||
Player S = Methods.getPlayer(seller);
|
||||
S.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage());
|
||||
sellerPlayer.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage());
|
||||
}
|
||||
AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Bukkit.getOfflinePlayer(seller)), data.getItemStack("Items." + i + ".Item"), CancelledReason.ADMIN_FORCE_CANCEL);
|
||||
Bukkit.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"));
|
||||
@ -799,6 +803,8 @@ public class GUI implements Listener {
|
||||
int ID = data.getInt("Items." + i + ".StoreID");
|
||||
if(id == ID) {
|
||||
player.sendMessage(Messages.CANCELLED_ITEM.getMessage());
|
||||
AuctionCancelledEvent event = new AuctionCancelledEvent(player, data.getItemStack("Items." + i + ".Item"), CancelledReason.PLAYER_FORCE_CANCEL);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
int num = 1;
|
||||
for(; data.contains("OutOfTime/Cancelled." + num); num++) ;
|
||||
data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller"));
|
||||
|
Loading…
Reference in New Issue
Block a user