samkor14
📎 1 file 6,100 chars
📄
pasted-code-1787521766652.txt
txt 282 lines
▶
Create a Minecraft Java plugin for Paper 1.21+ where every player receives a random ability when they join.

## Main Concept

When a player joins for the first time, randomly assign them one ability from a configurable list.

The player can activate their assigned ability **ONLY by using the command `/ability-use`**.

Do not use right-click, items, sneak, jumping, or any other activation method.

## Ability Activation

Add the command:

`/ability-use`

When the player executes `/ability-use`:

1. Check whether the player has an assigned ability.
2. Check whether the ability is currently on cooldown.
3. If it is on cooldown, tell the player how many seconds remain.
4. If it is available, activate their ability.
5. Start the ability's cooldown.
6. Play the appropriate sound.
7. Spawn appropriate particles.
8. Send a message describing the ability activation.

Example:

`/ability-use`

Chat response:

`⚡ You used DASH!`

Then the ability activates immediately.

The command should have the permission:

`randomabilities.use`

## Example Abilities

Include at least these abilities:

### Freeze

When `/ability-use` is used:

* Freeze the nearest player the user is looking at.
* Freeze them for 3 seconds.
* Prevent normal movement.
* Spawn freezing particles.
* Play a freezing sound.
* Put the ability on cooldown.

### Launch

When `/ability-use` is used:

* Launch the nearest player the user is looking at into the air.
* Make the launch strength configurable.
* Spawn particles.
* Play a launch sound.
* Optionally prevent fall damage caused by the launch.

### Knockback

When `/ability-use` is used:

* Apply strong knockback to the nearest player the user is looking at.
* Make the knockback strength configurable.
* Play a sound and particle effect.

### Dash

When `/ability-use` is used:

* Dash the ability owner forward in the direction they are looking.
* Prevent teleporting/dashing through solid blocks.
* Spawn particles behind the player.
* Add a configurable cooldown.

### Heal

When `/ability-use` is used:

* Heal the ability owner.
* Make the amount configurable.
* Play a healing sound.
* Spawn regeneration particles.

### Lightning

When `/ability-use` is used:

* Strike lightning at the targeted player.
* Make damage configurable.
* Allow the lightning to be visual-only through `config.yml`.

### Teleport

When `/ability-use` is used:

* Teleport the player a configurable distance in the direction they are looking.
* Check for blocks and prevent unsafe teleportation.
* Play a teleport sound.

### Invisibility

When `/ability-use` is used:

* Make the player invisible for a configurable duration.
* Display particles when activated.
* Automatically remove invisibility when the duration ends.

### Super Jump

When `/ability-use` is used:

* Give the player a powerful upward velocity.
* Configure the jump strength.
* Reduce or prevent fall damage from the ability.

## Random Ability Assignment

When a player joins:

1. Check if they already have an ability.
2. If they don't, randomly select one from the enabled abilities.
3. Save the ability to their player data.
4. Show a title:

`YOUR RANDOM ABILITY`

`⚡ DASH`

5. Send them a message explaining how to use it:

`Your ability is DASH!`
`Use /ability-use to activate it.`

Add this configuration option:

`randomize-on-every-join: false`

If `false`, players keep their ability after reconnecting.

If `true`, they receive a new random ability every time they join.

## Commands

### `/ability-use`

Activates the player's assigned ability.

Permission:

`randomabilities.use`

### `/ability info`

Shows the player's current ability, description, and cooldown.

### `/ability reroll `

Gives a player a new random ability.

Permission:

`randomabilities.admin`

### `/ability set  `

Manually assigns an ability to a player.

Permission:

`randomabilities.admin`

### `/ability reload`

Reloads the plugin configuration.

Permission:

`randomabilities.admin`

## Cooldowns

Every ability must have its own configurable cooldown.

Example:

```yaml
abilities:
  freeze:
    cooldown: 30
    duration: 3

  launch:
    cooldown: 15
    strength: 2.5

  dash:
    cooldown: 10
    distance: 8

  heal:
    cooldown: 30
    amount: 6
```

When a player tries to use an ability during cooldown:

`Your ability is on cooldown for 12 seconds!`

Do not activate the ability or restart the cooldown.

## Configuration

Create a complete `config.yml` containing:

* Enabled abilities
* Ability cooldowns
* Ability durations
* Ability strengths
* Damage values
* Particle effects
* Sounds
* Messages
* Random ability settings
* Ability persistence
* Duplicate ability settings
* Targeting settings

## Targeting

For abilities that target another player:

* Target the player the user is looking at.
* Add a configurable maximum range.
* Ignore spectators.
* Ignore the ability user themselves.
* If no valid player is being targeted, display:

`You must be looking at a player!`

## Unique Abilities

Add:

`unique-abilities: false`

If `false`, multiple players can have the same ability.

If `true`, attempt to give different abilities to different players.

If there are more players than available abilities, allow duplicates.

## Technical Requirements

* Java
* Paper 1.21+
* Modern Paper APIs
* Complete working source code
* `plugin.yml`
* `config.yml`
* Maven or Gradle setup
* Persistent player ability storage
* Cooldown manager
* Ability manager
* Separate class for each ability
* Command handling
* Event listeners
* Clean up temporary effects when players leave
* Handle invalid players and abilities gracefully
* No pseudocode
* Code must be compilable and ready to build into a `.jar`

Most importantly, **`/ability-use` must be the only way a player can activate their ability.**
Kodari AI
KodariAug 23 at 9:51 pm 2
RandomAbilityPlugin
A Paper 1.21+ plugin that assigns every player a random ability on first join. Players activate their ability exclusively via the /ability-use command, which checks cooldowns, triggers effects like freeze, launch, knockback, dash, heal, lightning, teleport, invisibility, and super jump, and plays sounds/particles. Includes configurable cooldowns, durations, strengths, targeting, unique ability settings, and persistence. Admin commands manage abilities, rerolls, and config reloads. Persistent player data storage, cooldown manager, and separate ability classes ensure clean, compilable code.
  1. Create the Gradle/Paper project metadata and complete configuration.

  2. Add persistence, cooldown, temporary-effect, targeting, messaging, and visual utilities.

  3. Implement the ability interface plus all nine configurable abilities.

  4. Add managers, commands, listeners, and plugin bootstrap wiring.

Implemented the complete Paper 1.21+ RandomAbilities plugin.

  • Added Gradle project configuration and plugin.yml.

  • Added full configurable config.yml.

  • Implemented persistent player ability storage in players.yml.

  • Added cooldown management and temporary effect cleanup.

  • Added all requested abilities:

    • Freeze

    • Launch

    • Knockback

    • Dash

    • Heal

    • Lightning

    • Teleport

    • Invisibility

    • Super Jump

  • Added /ability-use.

  • Added /ability info, /ability reroll, /ability set, and /ability reload.

  • Added permissions:

    • randomabilities.use

    • randomabilities.admin

  • Added random assignment on join.

  • Added randomize-on-every-join.

  • Added unique-abilities.

  • Added configurable targeting, range, particles, sounds, cooldowns, damage, durations, and strengths.

  • Added movement blocking for Freeze.

  • Added safe-block checks for Dash and Teleport.

  • Added fall-damage protection for Launch and Super Jump.

  • Added cleanup when players leave or the plugin disables.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
28 1,172
src/main/java/com/kodari/randomabilities/RandomAbilitiesPlugin.java
package com.kodari.randomabilities;

import com.kodari.randomabilities.command.AbilityCommand;
import com.kodari.randomabilities.command.AbilityUseCommand;
import com.kodari.randomabilities.listener.AbilityListener;
import com.kodari.randomabilities.listener.JoinListener;
import com.kodari.randomabilities.manager.AbilityManager;
import com.kodari.randomabilities.manager.CooldownManager;
import com.kodari.randomabilities.manager.EffectManager;
import com.kodari.randomabilities.manager.PlayerDataManager;
import com.kodari.randomabilities.util.MessageUtil;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public final class RandomAbilitiesPlugin extends JavaPlugin {
    private PlayerDataManager playerDataManager;
    private CooldownManager cooldownManager;
    private EffectManager effectManager;
    private AbilityManager abilityManager;
    private MessageUtil messageUtil;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        messageUtil = new MessageUtil(this);
        playerDataManager = new PlayerDataManager(this);
        cooldownManager = new CooldownManager();
        effectManager = new EffectManager(this);
        abilityManager = new AbilityManager(this);

        getCommand("ability-use").setExecutor(new AbilityUseCommand(this));
        AbilityCommand abilityCommand = new AbilityCommand(this);
        getCommand("ability").setExecutor(abilityCommand);
        getCommand("ability").setTabCompleter(abilityCommand);

        Bukkit.getPluginManager().registerEvents(new JoinListener(this), this);
        Bukkit.getPluginManager().registerEvents(new AbilityListener(this), this);
    }

    @Override
    public void onDisable() {
        if (effectManager != null) {
            effectManager.clearAll();
        }
        if (playerDataManager != null) {
            playerDataManager.save();
        }
    }

    public PlayerDataManager getPlayerDataManager() {
        return playerDataManager;
    }

    public CooldownManager getCooldownManager() {
        return cooldownManager;
    }

    public EffectManager getEffectManager() {
        return effectManager;
    }

    public AbilityManager getAbilityManager() {
        return abilityManager;
    }

    public MessageUtil messages() {
        return messageUtil;
    }
}