package com.yourname.abilities;
import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; 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.Random; import java.util.UUID;
public class AbilityPlugin extends JavaPlugin implements Listener {
// Store abilities and cooldowns in memory private final String[] ABILITIES = {"Fireball", "Dash", "Lightning", "Heal", "Invisibility", "Leap", "Frost", "Poison"}; private final HashMap<UUID, Long> cooldowns = new HashMap<>(); private final int COOLDOWN_SECONDS = 10;
@Override public void onEnable() { getServer().getPluginManager().registerEvents(this, this); saveDefaultConfig(); // Creates config.yml to save player abilities permanently getLogger().info("AbilityPlugin has been enabled!"); }
// --- 1. RANDOM ABILITY ON FIRST JOIN --- @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); String path = "players." + player.getUniqueId().toString();
// Check if player already has an ability saved in config if (!getConfig().contains(path)) { Random random = new Random(); String randomAbility = ABILITIES[random.nextInt(ABILITIES.length)];
getConfig().set(path, randomAbility); saveConfig();
player.sendMessage(ChatColor.GOLD + "Welcome! You have been granted the " + ChatColor.AQUA + randomAbility + ChatColor.GOLD + " ability!"); player.sendMessage(ChatColor.GRAY + "Right-click with a stick to use it!"); } }
// --- 2. USING THE ABILITY --- @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer();
// Trigger ability by right-clicking with a Stick if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (player.getInventory().getItemInMainHand().getType() == Material.STICK) {
String path = "players." + player.getUniqueId().toString(); if (!getConfig().contains(path)) return; // Player has no ability
String ability = getConfig().getString(path);
// Handle Cooldowns if (cooldowns.containsKey(player.getUniqueId())) { long secondsLeft = ((cooldowns.get(player.getUniqueId()) / 1000) + COOLDOWN_SECONDS) - (System.currentTimeMillis() / 1000); if (secondsLeft > 0) { player.sendMessage(ChatColor.RED + "Ability is on cooldown for " + secondsLeft + " more seconds!"); return; } }
// Execute Ability executeAbility(player, ability);
// Set Cooldown cooldowns.put(player.getUniqueId(), System.currentTimeMillis()); } } }
private void executeAbility(Player player, String ability) { switch (ability.toLowerCase()) { case "fireball": player.launchProjectile(Fireball.class); player.sendMessage(ChatColor.RED + "You cast a Fireball!"); break; case "dash": player.setVelocity(player.getLocation().getDirection().multiply(2)); player.sendMessage(ChatColor.AQUA + "You dashed forward!"); break; case "lightning":
Location target = player.getTargetBlock(null, 50).getLocation(); player.getWorld().strikeLightning(target); player.sendMessage(ChatColor.YELLOW + "You struck lightning!"); break; case "heal": player.setHealth(Math.min(player.getHealth() + 10.0, player.getAttribute(org.bukkit.attribute.Attribute.GENERIC_MAX_HEALTH).getValue())); player.sendMessage(ChatColor.GREEN + "You healed yourself!"); break; case "invisibility": player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 200, 1)); // 10 seconds player.sendMessage(ChatColor.GRAY + "You vanished into the shadows!"); break; case "leap": player.setVelocity(new Vector(0, 1.5, 0)); player.sendMessage(ChatColor.WHITE + "You leaped into the air!"); break; case "frost": for (Entity e : player.getNearbyEntities(5, 5, 5)) { if (e instanceof LivingEntity) { ((LivingEntity) e).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100, 2)); } } player.sendMessage(ChatColor.AQUA + "You froze nearby enemies!"); break; case "poison": for (Entity e : player.getNearbyEntities(5, 5, 5)) { if (e instanceof LivingEntity) { ((LivingEntity) e).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 1)); } } player.sendMessage(ChatColor.DARK_GREEN + "You poisoned nearby enemies!"); break; default: player.sendMessage(ChatColor.RED + "Error: Unknown ability."); } }
// --- 3. ADMIN COMMANDS --- @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("abilityadmin")) { if (!sender.hasPermission("abilityplugin.admin")) { sender.sendMessage(ChatColor.RED + "You don't have permission to use this command."); return true; }
if (args.length == 0) { sender.sendMessage(ChatColor.RED + "Usage: /abilityadmin <set|check> <player> [ability]"); return true; }
if (args[0].equalsIgnoreCase("check") && args.length == 2) { Player target = Bukkit.getPlayer(args[1]); if (target != null) { String path = "players." + target.getUniqueId().toString(); String ability = getConfig().getString(path, "None"); sender.sendMessage(ChatColor.YELLOW + target.getName() + "'s ability is: " + ChatColor.AQUA + ability); } else { sender.sendMessage(ChatColor.RED + "Player not found online."); } return true; }
if (args[0].equalsIgnoreCase("set") && args.length == 3) { Player target = Bukkit.getPlayer(args[1]); if (target != null) { String newAbility = args[2]; boolean valid = false; for (String ab : ABILITIES) { if (ab.equalsIgnoreCase(newAbility)) valid = true; }
if (!valid) { sender.sendMessage(ChatColor.RED + "Invalid ability! Choose from: Fireball, Dash, Lightning, Heal, Invisibility, Leap, Frost, Poison."); return true; }
getConfig().set("players." + target.getUniqueId().toString(), newAbility); saveConfig();
sender.sendMessage(ChatColor.GREEN + "Set " + target.getName() + "'s ability to " + newAbility); target.sendMessage(ChatColor.GOLD + "An admin changed your ability to: " + ChatColor.AQUA + newAbility); } else { sender.sendMessage(ChatColor.RED + "Player not found online."); } return true; } } return false; } }
I see you’ve provided code for an ability plugin! To set this up as a proper project, I need to understand what you’d like me to do:
Convert this existing code into a properly structured Minecraft plugin project (with build.gradle, plugin.yml, XSeries compatibility fixes, etc.)?
Create a new ability plugin from scratch based on similar concepts but with improved architecture?
Something else with this code?
Please let me know what you’d like, and I’ll help you set it up! If you want me to convert this into a proper project structure, I’ll:
Fix Bukkit enum usage (replace with XSeries for cross-version compatibility)
Create proper plugin.yml with command definitions
Add build.gradle
Fix attribute access issues
Organize the code structure
Set up proper project metadata
What would you like me to do?
No files in this session