Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance path fast walking #242

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading