Skip to content

Commit

Permalink
- Fix PlayerChangePlotEvent not firing when a player changes plots by
Browse files Browse the repository at this point in the history
entering into a vehicle.
  • Loading branch information
LlmDl committed Jan 23, 2025
1 parent 18bd437 commit ba0cc89
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.palmergames.bukkit.towny.listeners;

import com.palmergames.bukkit.util.BukkitTools;
import com.palmergames.bukkit.util.EntityLists;

import org.bukkit.Material;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity;
Expand All @@ -11,6 +13,7 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;
Expand All @@ -19,7 +22,9 @@
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownySettings;
import com.palmergames.bukkit.towny.event.PlayerChangePlotEvent;
import com.palmergames.bukkit.towny.event.executors.TownyActionEventExecutor;
import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.bukkit.towny.utils.EntityTypeUtil;
import com.palmergames.bukkit.util.ItemLists;

Expand Down Expand Up @@ -154,4 +159,25 @@ private boolean isProtectedMobEnteringEmptyBoatInTown(Boat boat, Entity entity)
return boat.isEmpty() && !TownyAPI.getInstance().isWilderness(entity.getLocation())
&& EntityTypeUtil.isInstanceOfAny(TownySettings.getProtectedEntityTypes(), entity);
}


/**
* Handles entering a vehicle throwing a player change plot event.
*
* @param event VehicleEnterEvent.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVehicleEnterCheckingPlayerMovement(VehicleEnterEvent event) {
if (!TownyAPI.getInstance().isTownyWorld(event.getVehicle().getWorld()))
return;

if (event.getEntered() instanceof Player player) {
WorldCoord vehicleCoord = WorldCoord.parseWorldCoord(event.getVehicle());
WorldCoord playerCoord = WorldCoord.parseWorldCoord(player);
if (vehicleCoord.equals(playerCoord))
return;

BukkitTools.fireEvent(new PlayerChangePlotEvent(player, playerCoord, vehicleCoord, new PlayerMoveEvent(player, player.getLocation(), event.getVehicle().getLocation())));
}
}
}
3 changes: 2 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10213,4 +10213,5 @@ v0.92.0.11:
- New Config Option: global_town_settings.allows_outlaws_to_always_pvp
- Default: false
- While true, outlaws can always harm players in towns they are outlawed in, despite the town pvp setting.
- Fix an NPE in the isOutlawInTown method, courtesy of Warrior with PR #7736.
- Fix an NPE in the isOutlawInTown method, courtesy of Warrior with PR #7736.
- Fix PlayerChangePlotEvent not firing when a player changes plots by entering into a vehicle.

0 comments on commit ba0cc89

Please sign in to comment.