i have a problem with fireworks

Discussion in 'Plugin Development' started by reboxer, Apr 4, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    reboxer

    hello guys, i have a problem with fireworks, when a player join to the server with the permission, the firework does not appears.
    this is my current code:

    Code:
    package main;
    
    import java.util.Random;
    import org.bukkit.Color;
    import org.bukkit.FireworkEffect;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Firework;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.meta.FireworkMeta;
    
    public class JoinFirework
      implements Listener
      {
          Integer i;
    
      public JoinFirework(Main plugin)
      {
      }
    
      private Color getColor(int i)
      {
        Color c = null;
        if (i == 1) {
          c = Color.AQUA;
        }
        if (i == 2) {
          c = Color.BLACK;
        }
        if (i == 3) {
          c = Color.BLUE;
        }
        if (i == 4) {
          c = Color.FUCHSIA;
        }
        if (i == 5) {
          c = Color.GRAY;
        }
        if (i == 6) {
          c = Color.GREEN;
        }
        if (i == 7) {
          c = Color.LIME;
        }
        if (i == 8) {
          c = Color.MAROON;
        }
        if (i == 9) {
          c = Color.NAVY;
        }
        if (i == 10) {
          c = Color.OLIVE;
        }
        if (i == 11) {
          c = Color.ORANGE;
        }
        if (i == 12) {
          c = Color.PURPLE;
        }
        if (i == 13) {
          c = Color.RED;
        }
        if (i == 14) {
          c = Color.SILVER;
        }
        if (i == 15) {
          c = Color.TEAL;
        }
        if (i == 16) {
          c = Color.WHITE;
        }
        if (i == 17) {
          c = Color.YELLOW;
        }
        return c;
      }
     
      @EventHandler
      public void onPlayerJoin(PlayerJoinEvent e)
      {
        if (this.i.intValue() == 0)
        {
          Player p = e.getPlayer();
          if (p.hasPermission("vipjoin.firework"))
          {
            Firework fw = (Firework)p.getWorld().spawnEntity(p.getLocation(), EntityType.FIREWORK);
            FireworkMeta fwm = fw.getFireworkMeta();
           
            Random r = new Random();
            int rt = r.nextInt(4) + 1;
           
            FireworkEffect.Type type = FireworkEffect.Type.BALL;
            if (rt == 1) {
              type = FireworkEffect.Type.BALL;
            }
            if (rt == 2) {
              type = FireworkEffect.Type.BALL_LARGE;
            }
            if (rt == 3) {
              type = FireworkEffect.Type.BURST;
            }
            if (rt == 4) {
              type = FireworkEffect.Type.CREEPER;
            }
            if (rt == 5) {
              type = FireworkEffect.Type.STAR;
            }
            int r1i = r.nextInt(17) + 1;
            int r2i = r.nextInt(17) + 1;
            Color c1 = getColor(r1i);
            Color c2 = getColor(r2i);
           
            FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
           
            fwm.addEffect(effect);
            fwm.setPower(1);
            fw.setFireworkMeta(fwm);
          }
        }
      }
    }
     
  2. @reboxer You're never spawning the firework. Just use spawnEntity for this. All of those if statements could be compressed using a switch statement. Why do you have an Integer object, and why not just use int?
     
    mine-care likes this.
  3. Offline

    mine-care

    Will 'i' ever have more than 1 value at the same time? No. so use a switch as @CodePlaysMinecraft said, or an if-else if-else block.
    Have you gone through the basics of Java? If not, i advise you to do so because Bukkit development without Java knowledge = trouble & disaster.
     
    CodePlaysMinecraft likes this.
Thread Status:
Not open for further replies.

Share This Page