@@ -1054,7 +1054,7 @@ void onPlayerPortal(PlayerPortalEvent event) {
10541054 }
10551055
10561056 // when a player teleports
1057- @ EventHandler (priority = EventPriority .MONITOR , ignoreCancelled = true )
1057+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
10581058 public void onPlayerTeleport (PlayerTeleportEvent event ) {
10591059 Player player = event .getPlayer ();
10601060 PlayerData playerData = this .dataStore .getPlayerData (player .getUniqueId ());
@@ -1065,32 +1065,34 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
10651065 // Get the claim at the original location
10661066 Claim fromClaim = playerData .lastClaim ;
10671067
1068- // Update the lastClaim to the new location
1069- playerData .lastClaim = toClaim ;
1070-
1071- // If we're moving from one claim to another, or from a claim to wilderness,
1072- // we need to update the player's permissions
1073- if (fromClaim != toClaim ) {
1074- player .updateCommands ();
1075- }
1076-
10771068 // Special handling for ender pearls and chorus fruit to prevent gaining access
1078- // to secured claims
1069+ // to secured claims. Must run before updating lastClaim so we don't corrupt
1070+ // player state when cancelling. Use ProtectionHelper for proper 3D claim and
1071+ // parent inheritance handling.
10791072 if (instance .config_claims_enderPearlsRequireAccessTrust ) {
10801073 TeleportCause cause = event .getCause ();
10811074 if (cause == TeleportCause .CHORUS_FRUIT || cause == TeleportCause .ENDER_PEARL ) {
1082- if (toClaim != null ) {
1083- Supplier <String > noAccessReason = toClaim .checkPermission (player , ClaimPermission .Access , event );
1084- if (noAccessReason != null ) {
1085- GriefPrevention .sendMessage (player , TextMode .Err , noAccessReason .get ());
1086- event .setCancelled (true );
1087- if (cause == TeleportCause .ENDER_PEARL && instance .config_claims_refundDeniedEnderPearls ) {
1088- player .getInventory ().addItem (new ItemStack (Material .ENDER_PEARL ));
1089- }
1075+ Supplier <String > noAccessReason = ProtectionHelper .checkPermission (player , event .getTo (),
1076+ ClaimPermission .Access , event );
1077+ if (noAccessReason != null ) {
1078+ GriefPrevention .sendMessage (player , TextMode .Err , noAccessReason .get ());
1079+ event .setCancelled (true );
1080+ if (cause == TeleportCause .ENDER_PEARL && instance .config_claims_refundDeniedEnderPearls ) {
1081+ player .getInventory ().addItem (new ItemStack (Material .ENDER_PEARL ));
10901082 }
1083+ return ; // Don't update lastClaim when teleport is cancelled
10911084 }
10921085 }
10931086 }
1087+
1088+ // Update the lastClaim to the new location (only when teleport proceeds)
1089+ playerData .lastClaim = toClaim ;
1090+
1091+ // If we're moving from one claim to another, or from a claim to wilderness,
1092+ // we need to update the player's permissions
1093+ if (fromClaim != toClaim ) {
1094+ player .updateCommands ();
1095+ }
10941096 }
10951097
10961098 // when a player triggers a raid (in a claim)
0 commit comments