mod version
This commit is contained in:
58
plugin/src/main/java/com/kasetoatz/fastGhast/FastGhast.java
Normal file
58
plugin/src/main/java/com/kasetoatz/fastGhast/FastGhast.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.kasetoatz.fastGhast;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
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
|
||||
{
|
||||
private static final double UNMOUNTED_SPEED;
|
||||
private double MOUNTED_SPEED;
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
saveDefaultConfig();
|
||||
UNMOUNTED_SPEED = getConfig().getDouble("unmounted-speed");
|
||||
MOUNTED_SPEED = getConfig().getDouble("mounted-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)
|
||||
{
|
||||
if (entity instanceof HappyGhast ghast)
|
||||
{
|
||||
AttributeInstance attr = ghast.getAttribute(Attribute.FLYING_SPEED);
|
||||
if (attr != null)
|
||||
{
|
||||
attr.setBaseValue(speed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityMount(EntityMountEvent event)
|
||||
{
|
||||
setSpeed(event.getMount(), MOUNTED_SPEED);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDismount(EntityDismountEvent event)
|
||||
{
|
||||
setSpeed(event.getDismounted(), UNMOUNTED_SPEED);
|
||||
}
|
||||
}
|
4
plugin/src/main/resources/config.yml
Normal file
4
plugin/src/main/resources/config.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
# Default flying speed.
|
||||
unmounted-speed: 0.05
|
||||
# Flying speed of mounted Happy Ghasts, default speed is 0.05 so 0.15 is 3 times as fast.
|
||||
mounted-speed: 0.15
|
4
plugin/src/main/resources/plugin.yml
Normal file
4
plugin/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
name: FastGhast
|
||||
version: '1.2'
|
||||
main: com.kasetoatz.fastGhast.FastGhast
|
||||
api-version: '1.21'
|
Reference in New Issue
Block a user