Fireworks kick Players because of NBT Error

Discussion in 'Plugin Development' started by AppleBabies, Jan 4, 2016.

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

    AppleBabies

    So, I have this random firework generator, and it kicks people for an NBT error. I know it is because of the below code. But I do not see where I am going wrong. If anybody could help, that would be fantastic.

    Code:
    public void spawnFirework(Player p){
            Firework fw = (Firework) p.getWorld().spawnEntity(p.getLocation(), EntityType.FIREWORK);
            FireworkMeta fwm = fw.getFireworkMeta();
         
         
            Random r = new Random();
    
          
            int rt = r.nextInt(4) + 1;
            Type type = Type.BALL;    
            if (rt == 1) type = Type.BALL;
            if (rt == 2) type = Type.BALL_LARGE;
            if (rt == 3) type = Type.BURST;
            if (rt == 4) type = Type.CREEPER;
            if (rt == 5) type = Type.STAR;
         
         
            int r1i = r.nextInt(17) + 1;
            int r2i = r.nextInt(17) + 1;
            Color c1 = getColor(r1i);
            Color c2 = getColor(r2i);
         
            //Create our effect with this
            FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
         
        
            fwm.addEffect(effect);
         
        
            int rp = r.nextInt(2) + 1;
            fwm.setPower(rp);
         
    
            fw.setFireworkMeta(fwm);        
          
          
        }
     
  2. Offline

    Zombie_Striker

  3. Offline

    AppleBabies

    @Zombie_Striker There's no console error: Just a error for the player io.ionetty.NBTHandler or something like that.
     
  4. Offline

    Zombie_Striker

    @AppleBabies
    "Something like that" doesn't really help. If it's not in the console, then post what the error is in the IDE.
     
  5. Offline

    567legodude

    @AppleBabies
    Code:
            int rt = r.nextInt(4) + 1;
            Type type = Type.BALL;   
            if (rt == 1) type = Type.BALL;
            if (rt == 2) type = Type.BALL_LARGE;
            if (rt == 3) type = Type.BURST;
            if (rt == 4) type = Type.CREEPER;
            if (rt == 5) type = Type.STAR;
    I just want to point out that rt will never be 5 in this case.
     
    Zombie_Striker likes this.
  6. Offline

    teej107

    It's not an IDE error. You can check Minecraft's console but I don't think you'd want to decipher through all that obfuscated garbally-goop.

    @AppleBabies Unless you can actually see what the error is from MC's console, I would comment out lines to see if the problem stops.
     
  7. Offline

    AppleBabies

    @teej107 I have looked into NBT handling more. This is a very rare thing that happens to players, and it's Minecraft basically saying that it doesn't support a certain feature of the firework. But, then wouldn't EVERYBODY be kicked? I am actually starting to believe that it's not the firework causing the problem.

    Could it be this?
    Code:
    ItemStack fwStack = new ItemStack(Material.FIREWORK);
        ItemMeta fwMeta = fwStack.getItemMeta();
       
        public void configureGadgets(){
            fwMeta.setDisplayName(ChatColor.AQUA + "Fireworks");
            fwMeta.setLore(Arrays.asList(ChatColor.RED + "Cool Fireworks."));
            fwStack.setItemMeta(fwMeta);
        }
     
  8. Offline

    teej107

    @AppleBabies I doubt it but
     
  9. Offline

    mythbusterma

    @AppleBabies

    Everyone who saw it.

    But you still haven't posted that error.
     
  10. Offline

    Xerox262

    @AppleBabies show your getColor(int) method?

    Switch statement too strong
    Code:
           int rt = r.nextInt(4) + 1;
            Type type = Type.BALL;  
           if (rt == 1) type = Type.BALL;
           if (rt == 2) type = Type.BALL_LARGE;
           if (rt == 3) type = Type.BURST;
           if (rt == 4) type = Type.CREEPER;
           if (rt == 5) type = Type.STAR
    Why store these?
    Code:
           int r1i = r.nextInt(17) + 1;
           int r2i = r.nextInt(17) + 1;
           Color c1 = getColor(r1i);
           Color c2 = getColor(r2i);
     
    Last edited: Jan 5, 2016
Thread Status:
Not open for further replies.

Share This Page