Add leash protection

This commit is contained in:
2025-08-11 22:01:28 +02:00
parent 8a34bff9a6
commit 1ed722c299
3 changed files with 15 additions and 7 deletions

View File

@@ -1,14 +1,15 @@
package com.kasetoatz.fastGhast;
import org.bukkit.Bukkit;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HappyGhast;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDismountEvent;
import org.bukkit.event.entity.EntityMountEvent;
import org.bukkit.plugin.java.JavaPlugin;
import io.papermc.paper.entity.Leashable;
public final class FastGhast extends JavaPlugin implements Listener
{
@@ -21,6 +22,13 @@ public final class FastGhast extends JavaPlugin implements Listener
saveDefaultConfig();
SPEED = getConfig().getDouble("speed");
getServer().getPluginManager().registerEvents(this, this);
Bukkit.getScheduler().runTaskTimer(this, () -> {
getServer().getWorlds().forEach(world -> world.getEntities().forEach(entity -> {
if (entity instanceof Leashable leashed && leashed.isLeashed() && leashed.getLeashHolder() instanceof HappyGhast ghast && leashed.getLocation().distance(ghast.getLocation()) > 8) {
leashed.teleport(ghast.getLocation());
}
}));
}, 0, 1);
}
private void setSpeed(Entity entity, double speed)