Skip to content

Commit

Permalink
Fixing checkstyle errors and moving event to aligning with other even…
Browse files Browse the repository at this point in the history
…t location.
  • Loading branch information
sumsar1812 committed Feb 25, 2025
1 parent d3daf32 commit e9c4be3
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.signs.event.SignTransactionEvent;
import net.ess3.api.events.SignTransactionEvent;
import net.ess3.api.IEssentials;
import net.ess3.api.MaxMoneyException;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.math.BigDecimal;
Expand Down Expand Up @@ -47,11 +46,13 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
}

charge.isAffordableFor(player);
SignTransactionEvent signTransactionEvent = new SignTransactionEvent(
final SignTransactionEvent signTransactionEvent = new SignTransactionEvent(
sign,
this,
player,
items.getItemStack(),
player.getBase(),
sign.getBlock().getLocation(),
SignTransactionEvent.TransactionType.BUY
SignTransactionEvent.TransactionType.BUY,
charge.getMoney()
);

ess.getServer().getPluginManager().callEvent(signTransactionEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.Trade.OverflowType;
import com.earth2me.essentials.User;
import com.earth2me.essentials.signs.event.SignTransactionEvent;
import net.ess3.api.events.SignTransactionEvent;
import net.ess3.api.IEssentials;
import net.ess3.api.MaxMoneyException;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -49,11 +49,14 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri

charge.isAffordableFor(player);

SignTransactionEvent signTransactionEvent = new SignTransactionEvent(
final SignTransactionEvent signTransactionEvent = new SignTransactionEvent(
sign,
this,
player,
charge.getItemStack(),
player.getBase(),
sign.getBlock().getLocation(),
SignTransactionEvent.TransactionType.SELL
SignTransactionEvent.TransactionType.SELL,
money.getMoney()

);
ess.getServer().getPluginManager().callEvent(signTransactionEvent);
if (signTransactionEvent.isCancelled()) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package net.ess3.api.events;

import com.earth2me.essentials.signs.EssentialsSign;
import net.ess3.api.IUser;
import org.bukkit.event.Cancellable;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;

/**
* Fired when a player either buys or sells from an essentials sign
*/
public final class SignTransactionEvent extends SignInteractEvent implements Cancellable {
private final ItemStack itemStack;
private final TransactionType transactionType;
private final BigDecimal transactionValue;
private boolean isCancelled = false;

public SignTransactionEvent(EssentialsSign.ISign sign,
EssentialsSign essSign,
IUser user,
@NotNull ItemStack itemStack,
@NotNull TransactionType transactionType,
BigDecimal transactionValue) {
super(sign, essSign, user);
this.itemStack = itemStack;
this.transactionType = transactionType;
this.transactionValue = transactionValue;
}

/**
*
* @return if the event should be cancelled.
*/

@Override
public boolean isCancelled() {
return this.isCancelled;
}

/**
*
* @param cancelled sets the event to be cancelled, this will cancel the transaction.
*/

@Override
public void setCancelled(boolean cancelled) {
this.isCancelled = cancelled;
}

/**
*
* @return a copy of the itemstack in the current transaction.
*/

public @NotNull ItemStack getItemStack() {
return itemStack.clone();
}

/**
*
* @return the type of transaction executed.
*/
public @NotNull TransactionType getTransactionType() {
return transactionType;
}

/**
*
* @return how much was either sold or bought through the sign.
*/

public BigDecimal getTransactionValue() {
return transactionValue;
}

/**
* Transaction type of the event
*/

public enum TransactionType {
BUY,
SELL
}
}

0 comments on commit e9c4be3

Please sign in to comment.