Merge pull request #11 from rexlManu/master

feat: `AxTradeCompletedEvent` event
This commit is contained in:
BenceX100 2025-02-07 15:05:19 +01:00 committed by GitHub
commit 4f93ad02d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -2,12 +2,14 @@ package com.artillexstudios.axtrade.trade;
import com.artillexstudios.axapi.scheduler.Scheduler;
import com.artillexstudios.axapi.utils.ContainerUtils;
import com.artillexstudios.axtrade.api.events.AxTradeCompletedEvent;
import com.artillexstudios.axtrade.currency.CurrencyProcessor;
import com.artillexstudios.axtrade.hooks.currency.CurrencyHook;
import com.artillexstudios.axtrade.utils.HistoryUtils;
import com.artillexstudios.axtrade.utils.NumberUtils;
import com.artillexstudios.axtrade.utils.SoundUtils;
import com.artillexstudios.axtrade.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
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());
currencyProcessor1.run().thenAccept(success1 -> {
if (!success1) {