stelarda

name: AbilityPlugin version: 1.0 main: me.abilityplugin.AbilityPlugin api-version: 1.20

commands: ability: description: use ability abilities: description: open ability INVENTORY GUI

📎 1 file 3,333 chars
📄
pasted-code-1773664757991.txt
txt 111 lines
▶
package me.abilityplugin;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;

import java.util.HashMap;
import java.util.UUID;

public class AbilityPlugin extends JavaPlugin {

    HashMap cooldown = new HashMap<>();

    @Override
    public void onEnable() {
        getLogger().info("Ability Plugin Enabled");
    }

    public void openAbilityMenu(Player player) {

        Inventory INVENTORY GUI = Bukkit.createInventory(null, 9, "Your Ability");

        ItemStack dash = new ItemStack(Material.FEATHER);
        ItemMeta meta = dash.getItemMeta();
        meta.setDisplayName("§bDash Ability");
        dash.setItemMeta(meta);

        INVENTORY GUI.setItem(4, dash);

        player.openInventory(INVENTORY GUI);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

        if (!(sender instanceof Player)) return true;

        Player player = (Player) sender;

        if (cmd.getName().equalsIgnoreCase("abilities")) {
            openAbilityMenu(player);
        }

        if (cmd.getName().equalsIgnoreCase("ability")) {

            long cd = 80 * 1000;

            if (cooldown.containsKey(player.getUniqueId())) {
                long timeLeft = ((cooldown.get(player.getUniqueId()) + cd) - System.currentTimeMillis()) / 1000;

                if (timeLeft > 0) {
                    player.sendMessage("Ability on cooldown for " + timeLeft + " seconds.");
                    return true;
                }
            }

            cooldown.put(player.getUniqueId(), System.currentTimeMillis());

            Vector direction = player.getLocation().getDirection().normalize();
            player.setVelocity(direction.multiply(2.5));

            player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 1));

            Bukkit.getScheduler().runTaskTimer(this, task -> {

                if (player.isOnGround()) {

                    player.getWorld().spawnParticle(
                            Particle.GUST,
                            player.getLocation(),
                            80,
                            1,1,1,
                            0.2
                    );

                    for (Entity entity : player.getNearbyEntities(5,5,5)) {
                        if (entity instanceof Player) {
                            Player target = (Player) entity;
                            target.damage(4.0, player);
                        }
                    }

                    task.cancel();
                    return;
                }

                player.getWorld().spawnParticle(
                        Particle.GUST,
                        player.getLocation(),
                        10,
                        0.3,0.3,0.3,
                        0
                );

            }, 0, 2);
        }

        return true;
    }
}
Kodari can make mistakes. Review important code before using.
Files

No files in this session

Code