Extending the Effects

package me.leo_s.featheredelection.objects.effect.types;

import me.leo_s.featheredelection.annotations.EffectName;
import me.leo_s.featheredelection.objects.effect.Effect;
import me.leo_s.featheredelection.objects.trigger.TriggerData;
import org.bukkit.Particle;
import org.bukkit.entity.Player;

@EffectName(name = "spawn_particles")
public class SpawnParticlesEffect extends Effect {
    private final Particle particle;
    private final int amount;
    public SpawnParticlesEffect(String particle, int amount) {
        this.particle = Particle.valueOf(particle);
        this.amount = amount;
    }

    @Override
    public void dispatch(Player player, TriggerData data) {
        if(player != null) {
            player.getWorld().spawnParticle(particle, player.getLocation(), amount);
        }
    }
}

Class Effect

public abstract class Effect {
    protected Set<Condition> conditions;
    protected Filter<?> filter;

    public Effect(Set<Condition> conditions, Filter<?> filter){
        this.conditions = conditions;
        this.filter = filter;
    }

    public Effect(){}

    public abstract void dispatch(Player player, TriggerData data);

    public boolean isMet(Player player){
        return this.conditions.stream().allMatch(c -> c.isMet(player));
    }
}

The Effect class has parameters such as its conditions and the filter that it will carry, you can create your own filters as well as conditions or else directly pass it a predefined filter or conditions.

Packages and Imports

package me.leo_s.featheredelection.objects.effect.types;

import me.leo_s.featheredelection.annotations.EffectName;
import me.leo_s.featheredelection.objects.effect.Effect;
import me.leo_s.featheredelection.objects.trigger.TriggerData;
import org.bukkit.Particle;
import org.bukkit.entity.Player;

Annotation@EffectName:

@EffectName(name = "spawn_particles")

The SpawnParticlesEffect class is annotated with @EffectName, with a name parameter equal to "spawn_particles". This suggests that the instance of this class represents an effect involving particle generation in the game.

Class Declaration:

public class SpawnParticlesEffect extends Effect {

SpawnParticlesEffect extends the Effect class, meaning that it inherits its functionality and can have additional specific behavior.

Class Attributes:

private final Particle particle;
private final int amount;

The class has two private and final attributes called particle and amount. particle is of type Particle (enum) and amount is an integer representing the number of particles to be generated. You can implement your own attributes depending on the use you will give to this effect.

Constructor:

public SpawnParticlesEffect(String particle, int amount) {
    this.particle = Particle.valueOf(particle);
    this.amount = amount;
}

The class has a constructor that takes a particle name as a string (particle) and the number of particles (amount). Converts the string particle to a Particle enumeration value and assigns the corresponding values to the particle and amount attributes.

Methoddispatch:

@Override
public void dispatch(Player player, TriggerData data) {
    if(player != null) {
        player.getWorld().spawnParticle(particle, player.getLocation(), amount);
    }
}

This overridden (@Override) method belongs to the Effect base class. It is responsible for the execution of the effect. If player is not null, invokes the spawnParticle method in the player world, generating particles of the type and quantity specified in the class attributes.

In short, this class represents an effect that generates particles at a player's location in the game when activated. Specific information about the type and number of particles is set by the constructor when instantiating the class.

Last updated