Skip to content

Commit

Permalink
Merge pull request #242 from Serial-ATA/fast-walk-enhance
Browse files Browse the repository at this point in the history
Enhance path fast walking
  • Loading branch information
oddlama committed Apr 1, 2024
2 parents fae5edf + 9e8f81f commit 35d887d
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.oddlama.vane.trifles;

import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent;
import org.oddlama.vane.annotation.config.ConfigBoolean;
import org.oddlama.vane.core.Listener;

import io.papermc.paper.event.entity.EntityMoveEvent;
import net.minecraft.world.entity.monster.Monster;

public class FastWalkingListener extends Listener<Trifles> {

Expand All @@ -16,6 +19,14 @@ public FastWalkingListener(FastWalkingGroup context) {
super(context);
this.fast_walking = context;
}
@ConfigBoolean(def = false, desc = "Whether hostile mobs should be allowed to fast walk on paths.")
public boolean hostile_speedwalk;

@ConfigBoolean(def = true, desc = "Whether villagers should be allowed to fast walk on paths.")
public boolean villager_speedwalk;

@ConfigBoolean(def = false, desc = "Whether players should be the only entities allowed to fast walk on paths (will override other path walk settings).")
public boolean players_only_speedwalk;

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void on_player_move(final PlayerMoveEvent event) {
Expand Down Expand Up @@ -45,6 +56,15 @@ public void on_player_move(final PlayerMoveEvent event) {
public void on_entity_move(final EntityMoveEvent event) {
final var entity = event.getEntity();

// Cancel event if speedwalking is only enabled for players
if(players_only_speedwalk) return;

// Cancel event if speedwalking is disabled for Hostile mobs
if(entity instanceof Monster && !hostile_speedwalk) return;

// Cancel event if speedwalking is disabled for villagers
if(entity.getType() == EntityType.VILLAGER && !villager_speedwalk) return;

// Inspect block type just a little below
var block = event.getTo().clone().subtract(0.0, 0.1, 0.0).getBlock();
if (!fast_walking.config_materials.contains(block.getType())) {
Expand Down

0 comments on commit 35d887d

Please sign in to comment.