zMobFighter addon - Fireball 1.0.0

Sample addon for the zMobFighter plugin

  1. Maxlego08
    Tested Minecraft Versions:
    • 1.8
    • 1.9
    • 1.10
    • 1.11
    • 1.12
    • 1.13
    • 1.14
    • 1.15
    • 1.16
    • 1.17
    This is an example of an addon for the zMobFighter plugin. The system is still under development. If you have any suggestions you can send them to me on discord: https://discord.groupez.dev/

    This addon allows you to send fireballs randomly during a fight.
    You must put the addon in the folder plugins/zmobfighter/addons

    [​IMG]

    Code (Java):

    package fr.maxlego08.fireball;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Fireball;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityExplodeEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.util.Vector;
    import fr.maxlego08.mobfighter.api.Arena;
    import fr.maxlego08.mobfighter.api.Duel;
    import fr.maxlego08.mobfighter.api.Fighter;
    import fr.maxlego08.mobfighter.api.addons.JavaAddon;
    public class FireBallAddon extends JavaAddon implements Listener {
        private long lastAttackSend = 0;
        private List<Fireball> fireBalls = new ArrayList<Fireball>();
        @Override
        public void onEnable() {
            System.out.println("Enable !");
            this.registerListener(this);
        }
        @Override
        public void onDisable() {
            System.out.println("Disable !");
        }
        @Override
        public void duelStart(Duel duel, Arena arena, Fighter first, Fighter second) {
            // TODO Auto-generated method stub
        }
        @Override
        public void duelStop(Duel duel, Arena arena, Fighter first, Fighter second) {
            // TODO Auto-generated method stub
        }
        @Override
        public void duelWin(Duel duel, Arena arena, Fighter first, Fighter second) {
            // TODO Auto-generated method stub
        }
        @Override
        public void duelTick(Duel duel, Arena arena, Fighter first, Fighter second) {
            if (System.currentTimeMillis() > lastAttackSend && first.getLocation().distance(second.getLocation()) > 5) {
                Random random = new Random();
                Fighter fighter = random.nextBoolean() ? first : second;
                       
                LivingEntity entity = fighter.getEntity();
               
                entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20, 150));
               
                Fireball fireball = entity.launchProjectile(Fireball.class);      
               
                Vector vector = fireball.getVelocity();
                fireball.setVelocity(vector);
               
                fireBalls.add(fireball);
                lastAttackSend = System.currentTimeMillis() + (1000 * (random.nextInt(2) + 1));
            }
        }
        @EventHandler
        public void onEntityExplode(EntityExplodeEvent event) {
            Entity entity = event.getEntity();
            if (this.fireBalls.contains(entity)) {
                event.setCancelled(true);          
                this.fireBalls.remove(entity);
            }
        }
    }