Solved Fireworks Error Code!

Discussion in 'Plugin Help/Development/Requests' started by DeadlyDeath001, Apr 12, 2015.

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

    DeadlyDeath001

    So My Fire Works have been going off 100% when the player mines. I want it to Just Go off when The Player Breaks the Blocks Having a 2% chance. The Chance for the message is %2. But the fireworks is 100% Going off. How do i make it go off when the 2% chance is hit?
    Code:
    package me.DeadlyDeath001.test;
    
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Firework;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.FireworkMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    @SuppressWarnings("unused")
    public class BlockDrop extends JavaPlugin implements Listener {
        @Override
        public void onDisable() {
                System.out.println(getName()+" Is now disable!");
        }
    
        @Override
        public void onEnable() {
                System.out.println(getName()+" Is now enable!");
                getServer().getPluginManager().registerEvents(this, this);
                getConfig().options().copyDefaults(true);
                saveConfig();
        }
      
        @EventHandler
        public void onBlockBreak(BlockBreakEvent event) {
            Block block = event.getBlock();
            Player player = event.getPlayer();
            World world = block.getWorld();
            Random rand = new Random();
            int number = rand.nextInt(100);
            {
            if (block.getType() == Material.STONE) {
                if(number <= getConfig().getInt("StonePercentage"))
                player.sendMessage(getConfig().getString("StoneMessage"));
                Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), "eco give" + player.getPlayer() + "200");
                launchFirework(player.getPlayer(), 69/*random number I thought of first*/);
            }
            }
        }
    
        private void launchFirework(Player player, int i) {
            Firework fw = (Firework) player.getWorld().spawn(player.getEyeLocation(), Firework.class);
            FireworkMeta meta = fw.getFireworkMeta();
            //use meta to customize the firework or add parameters to the method
            fw.setVelocity(player.getLocation().getDirection().multiply(1));
            //speed is how fast the firework flies
        }
       
          
        }
    
     
  2. Offline

    cnc4

    @DeadlyDeath001

    What is the error? Maybe its because you dos not add effects to the fireworks?
     
  3. Offline

    DeadlyDeath001

    Error: The fireworks is suppose to go off with the 2% Lucky Break But Instead the Fireworks goes off 100% and the message 2%
     
  4. Offline

    I Al Istannen

    @DeadlyDeath001 You have no "{" after the if which checks the number. That means just the next line will be affected by the if. Do sth like this:
    Code:
    if (block.getType() == Material.STONE) {
      if(number <= getConfig().getInt("StonePercentage")) {
        player.sendMessage(getConfig().getString("StoneMessage"));
        Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(),"eco give"+player.getPlayer() +"200");
        launchFirework(player.getPlayer(), 69/*random number I thought of first*/);
      }
    }
    
     
Thread Status:
Not open for further replies.

Share This Page