Essentials icon indicating copy to clipboard operation
Essentials copied to clipboard

Add PreTransactionEvent

Open Golfing7 opened this issue 1 month ago • 0 comments

Information

I added a PreTransactionEvent for cancelling transactions between users.

Details

Proposed feature:
Adding a PreTransactionEvent.

Environments tested:

OS: Linux Mint

Java version: 23

  • [x] 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.

Golfing7 avatar Dec 02 '25 15:12 Golfing7