import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EvokerFangs;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import java.util.function.Consumer;
public class Plugin
extends JavaPlugin {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only for player!");
return true;
}
Player player = (Player) sender;
Location location = player.getLocation().clone();
location.add(location.getDirection().clone().multiply(1)); // Add 1 block
location.setYaw(player.getLocation().getYaw());
location.setPitch(0);
spawnFangs(player, location, 8, true, null);
return true;
}
public void spawnFangs(LivingEntity owner, Location location, int amount, Boolean hasDelay, Consumer<EvokerFangs> onSpawn) {
World world = location == null || amount <= 0 ? null : location.getWorld();
if (world == null) return;
Vector direction = location.getDirection();
long delay = 0;
Consumer<Location> spawn = spawnLocation -> {
EvokerFangs fangs = world.spawn(spawnLocation, EvokerFangs.class);
if (fangs == null) return;
if (owner != null) fangs.setOwner(owner);
if (onSpawn != null) onSpawn.accept(fangs);
};
for (int i = 0; i < amount; i++) {
Location spawnLocation = location.clone().add(direction.clone().multiply(i));
if (hasDelay == Boolean.TRUE) Bukkit.getScheduler().runTaskLater(this,
() -> spawn.accept(spawnLocation),
delay += 1
);
else spawn.accept(spawnLocation);
}
}
}