mirror of
https://github.com/Artillex-Studios/AxTrade.git
synced 2025-02-14 01:21:56 +01:00
Merge pull request #11 from rexlManu/master
feat: `AxTradeCompletedEvent` event
This commit is contained in:
commit
4f93ad02d0
@ -0,0 +1,48 @@
|
|||||||
|
package com.artillexstudios.axtrade.api.events;
|
||||||
|
|
||||||
|
import com.artillexstudios.axtrade.trade.TradePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class AxTradeCompletedEvent extends Event implements Cancellable {
|
||||||
|
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLER_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final TradePlayer firstPlayer;
|
||||||
|
private final TradePlayer secondPlayer;
|
||||||
|
private boolean isCancelled = false;
|
||||||
|
|
||||||
|
public AxTradeCompletedEvent(TradePlayer firstPlayer, TradePlayer secondPlayer) {
|
||||||
|
this.firstPlayer = firstPlayer;
|
||||||
|
this.secondPlayer = secondPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return isCancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean b) {
|
||||||
|
isCancelled = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLER_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TradePlayer getFirstPlayer() {
|
||||||
|
return this.firstPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TradePlayer getSecondPlayer() {
|
||||||
|
return this.secondPlayer;
|
||||||
|
}
|
||||||
|
}
|
@ -2,12 +2,14 @@ package com.artillexstudios.axtrade.trade;
|
|||||||
|
|
||||||
import com.artillexstudios.axapi.scheduler.Scheduler;
|
import com.artillexstudios.axapi.scheduler.Scheduler;
|
||||||
import com.artillexstudios.axapi.utils.ContainerUtils;
|
import com.artillexstudios.axapi.utils.ContainerUtils;
|
||||||
|
import com.artillexstudios.axtrade.api.events.AxTradeCompletedEvent;
|
||||||
import com.artillexstudios.axtrade.currency.CurrencyProcessor;
|
import com.artillexstudios.axtrade.currency.CurrencyProcessor;
|
||||||
import com.artillexstudios.axtrade.hooks.currency.CurrencyHook;
|
import com.artillexstudios.axtrade.hooks.currency.CurrencyHook;
|
||||||
import com.artillexstudios.axtrade.utils.HistoryUtils;
|
import com.artillexstudios.axtrade.utils.HistoryUtils;
|
||||||
import com.artillexstudios.axtrade.utils.NumberUtils;
|
import com.artillexstudios.axtrade.utils.NumberUtils;
|
||||||
import com.artillexstudios.axtrade.utils.SoundUtils;
|
import com.artillexstudios.axtrade.utils.SoundUtils;
|
||||||
import com.artillexstudios.axtrade.utils.Utils;
|
import com.artillexstudios.axtrade.utils.Utils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -85,6 +87,17 @@ public class Trade {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AxTradeCompletedEvent event = new AxTradeCompletedEvent(
|
||||||
|
this.player1, this.player2
|
||||||
|
);
|
||||||
|
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if(event.isCancelled()) {
|
||||||
|
abort(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CurrencyProcessor currencyProcessor1 = new CurrencyProcessor(player1.getPlayer(), player1.getCurrencies().entrySet());
|
CurrencyProcessor currencyProcessor1 = new CurrencyProcessor(player1.getPlayer(), player1.getCurrencies().entrySet());
|
||||||
currencyProcessor1.run().thenAccept(success1 -> {
|
currencyProcessor1.run().thenAccept(success1 -> {
|
||||||
if (!success1) {
|
if (!success1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user