Skip to content

Conversation

@Golfing7
Copy link
Contributor

@Golfing7 Golfing7 commented Dec 2, 2025

Information

I added a PreTransactionEvent for cancelling transactions between users.

Details

Proposed feature:
Adding a PreTransactionEvent.

Environments tested:

OS: Linux Mint

Java version: 23

  • Most recent Paper version (1.XX.Y, git-Paper-BUILD)
  • CraftBukkit/Spigot/Paper 1.12.2
  • CraftBukkit 1.8.8

Demonstration:

    @EventHandler
    public void onPay(PreTransactionEvent event) {
        // Prevent money from being sent outside their own faction.
        IUser userSource = event.getRequester().getUser();
        if (userSource == null)
            return;

        FPlayer fplayerSource = FPlayers.getInstance().getByPlayer(userSource.getBase());
        if (fplayerSource == null || fplayerSource.isAdminBypassing())
            return;

        Faction faction = fplayerSource.getFaction();
        if (faction == null || !isFactionVoluntaryExcluded(faction.getId()))
            return;

        // Who are they sending it to?
        FPlayer target = FPlayers.getInstance().getById(event.getTarget().getUUID().toString());
        Faction factionTarget = target.getFaction();
        if (faction != factionTarget) {
            event.setCancelled(true);
            msg(userSource.getBase(), cantPayOutsideExcludedFactionMessage);
        }
    }

This code prevents transactions between two users when two factions can't interact.

Copy link
Member

@JRoy JRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if instead PreTransactionEvent extended TransactionEvent and also allowed you to update the amount?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants