Skip to content

Commit

Permalink
Fixed boats not considered as valid entities to limit (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed May 6, 2023
1 parent 8564457 commit b58c882
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Expand Up @@ -105,27 +105,32 @@ public void onHangingPlace(HangingPlaceEvent e) {
@EventHandler
public void onVehicleSpawn(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getItem() == null ||
e.getPlayer().getGameMode() == GameMode.CREATIVE ||
!Materials.isRail(e.getClickedBlock().getType()) ||
!Materials.isMinecart(e.getItem().getType()))
e.getPlayer().getGameMode() == GameMode.CREATIVE)
return;

Material handType = e.getItem().getType();

// Check if minecart or boat
boolean isMinecart = Materials.isRail(e.getClickedBlock().getType()) && Materials.isMinecart(handType);
boolean isBoat = Materials.isBoat(handType);
if (!isMinecart && !isBoat)
return;

if (INTERACT_GET_HAND.isValid() && INTERACT_GET_HAND.invoke(e) != EquipmentSlot.HAND)
return;

Island island = plugin.getGrid().getIslandAt(e.getClickedBlock().getLocation());
Location blockLocation = e.getClickedBlock().getLocation();
Island island = plugin.getGrid().getIslandAt(blockLocation);

if (island == null)
return;

Location blockLocation = e.getClickedBlock().getLocation();

vehiclesOwners.put(new LocationKey(blockLocation), e.getPlayer().getUniqueId());
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onVehicleSpawn(VehicleCreateEvent e) {
if (!(e.getVehicle() instanceof Minecart) || BukkitEntities.canBypassEntityLimit(e.getVehicle()))
if (BukkitEntities.canBypassEntityLimit(e.getVehicle()))
return;

Island island = plugin.getGrid().getIslandAt(e.getVehicle().getLocation());
Expand Down
Expand Up @@ -21,6 +21,7 @@
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Vehicle;
import org.bukkit.inventory.AbstractHorseInventory;
import org.bukkit.inventory.HorseInventory;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -131,8 +132,8 @@ public static Key getLimitEntityType(Entity entity) {

public static boolean canHaveLimit(EntityType entityType) {
Class<?> entityClass = entityType.getEntityClass();
return entityType.name().contains("MINECART") || (entityClass != null &&
(LivingEntity.class.isAssignableFrom(entityClass) || Hanging.class.isAssignableFrom(entityClass)));
return (entityClass != null && (LivingEntity.class.isAssignableFrom(entityClass) ||
Hanging.class.isAssignableFrom(entityClass) || Vehicle.class.isAssignableFrom(entityClass)));
}

public static boolean canBypassEntityLimit(Entity entity) {
Expand Down

0 comments on commit b58c882

Please sign in to comment.