Creating an Effect Booster (Java)
Below is an example of how you can create a booster that applies effects to the player
Main Class
package com.insurgencedev.exampleaddon;
import com.insurgencedev.exampleaddon.listeners.BoosterListener;
import lombok.Getter;
import org.insurgencedev.insurgenceboosters.api.addon.IBoostersAddon;
import org.insurgencedev.insurgenceboosters.api.addon.InsurgenceBoostersAddon;
@Getter
@IBoostersAddon(name = "ExampleAddon", version = "1.0.0", author = "Insurgence Dev Team", description = "Example Addon")
public class ExampleAddon extends InsurgenceBoostersAddon {
private static ExampleAddon instance;
private MyConfig config;
@Override
public void onAddonStart() {
instance = this;
config = new MyConfig();
}
@Override
public void onAddonReloadablesStart() {
registerEvent(new BoosterListener());
}
public static ExampleAddon instance() {
return instance;
}
}
Listener Class
package com.insurgencedev.exampleaddon.listeners;
import com.insurgencedev.exampleaddon.ExampleAddon;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.insurgencedev.insurgenceboosters.events.IBoosterEndEvent;
import org.insurgencedev.insurgenceboosters.events.IBoosterStartEvent;
import org.insurgencedev.insurgenceboosters.settings.IBoostersPlayerCache;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public final class BoosterListener implements Listener {
private static final List<UUID> activeList = new ArrayList<>();
private static final String TYPE = "Strength";
private static final String NAMESPACE = "CUSTOM_EFFECT";
@EventHandler
private void onStart(IBoosterStartEvent event) {
Player player = event.getPlayer();
IBoostersPlayerCache.Data.Booster data = event.getBoosterData();
if (!data.getType().equals(TYPE) && !data.getNamespace().equals(NAMESPACE)) {
return;
}
applyEffect(player);
}
@EventHandler
private void onEnd(IBoosterEndEvent event) {
IBoostersPlayerCache.Data.Booster data = event.getBoosterData();
if (!data.getType().equals(TYPE) && !data.getNamespace().equals(NAMESPACE)) {
return;
}
Player player = event.getPlayer();
removeEffect(player);
}
@EventHandler
private void onRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
if (activeList.contains(player.getUniqueId())) {
applyEffect(player);
}
}
private void applyEffect(Player player) {
activeList.add(player.getUniqueId());
player.addPotionEffect(new PotionEffect(
PotionEffectType.INCREASE_DAMAGE, 9999999, ExampleAddon.instance().getConfig().getAmplifier() - 1)
);
}
private void removeEffect(Player player) {
activeList.remove(player.getUniqueId());
player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
}
}
Custom Config Class
package com.insurgencedev.exampleaddon;
import lombok.Getter;
import org.insurgencedev.insurgenceboosters.api.addon.AddonConfig;
@Getter
public class MyConfig extends AddonConfig {
private int amplifier;
public MyConfig() {
loadAddonConfig("config.yml", "config.yml");
}
@Override
protected void onLoad() {
amplifier = getInteger("Amplifier");
}
}
Internal Config file
Amplifier: 2