Solved Problems with firework

Discussion in 'Plugin Development' started by Ciaranlol, Apr 27, 2014.

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

    Ciaranlol

    Hi guys,

    Again I have a problem with my plugin. I am making a plugin with fireworks and everything. I am now trying to get the firework from my hand and return to the player if it has trail and flicker. But I can't get it right because I get an error. I have debugged a lot and found out that it has to do with the line with:
    Code:java
    1. FireworkEffect[] effects = (FireworkEffect[]) effectslist.toArray();


    Here is my whole code:
    Code:java
    1. package me.Ciaran.showmaster;
    2.  
    3. import java.util.List;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.FireworkEffect;
    7. import org.bukkit.Material;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandExecutor;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Firework;
    12. import org.bukkit.entity.Item;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.FireworkMeta;
    16.  
    17. public class FireworkCommands implements CommandExecutor {
    18.  
    19. public ShowMaster plugin;
    20.  
    21. public FireworkCommands(ShowMaster plugin){
    22.  
    23. this.plugin = plugin;
    24. }
    25.  
    26.  
    27. @Override
    28. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    29.  
    30. if(cmd.getName().equalsIgnoreCase("savefirework")){
    31.  
    32. if(sender instanceof Player){
    33.  
    34. Player player = (Player) sender;
    35.  
    36. ItemStack items = player.getInventory().getItemInHand();
    37.  
    38. if(items.getType() == Material.FIREWORK){
    39.  
    40. if(args.length < 1){
    41.  
    42. player.sendMessage(ChatColor.RED + "You gave too few arguments!");
    43. }
    44. else if(args.length > 1){
    45.  
    46. player.sendMessage(ChatColor.RED + "You gave too many arguments!");
    47. }
    48. else{
    49.  
    50. String name = args[0];
    51. FireworkMeta meta = (FireworkMeta) items.getItemMeta();
    52.  
    53. List<FireworkEffect> effectslist = meta.getEffects();
    54.  
    55.  
    56. FireworkEffect[] effects = (FireworkEffect[]) effectslist.toArray();
    57.  
    58.  
    59. FireworkEffect effect = effects[0];
    60.  
    61. Boolean trail = effect.hasTrail();
    62. Boolean flicker = effect.hasFlicker();
    63.  
    64. player.sendMessage("trail: " + trail);
    65. player.sendMessage("flicker: " + flicker);
    66. }
    67.  
    68. }
    69. else{
    70.  
    71. player.sendMessage(ChatColor.RED + "You don't have firework in your hand!");
    72. }
    73.  
    74.  
    75. }
    76.  
    77. }
    78.  
    79.  
    80.  
    81. return true;
    82. }
    83.  
    84.  
    85.  
    86. }
    87.  


    And here is my error log:
    [​IMG]
     
  2. Ciaranlol
    PHP:
    FireworkEffect[] effects = (FireworkEffect[]) effectslist.toArray();
    Should be
    PHP:
    FireworkEffect effects efftslist.toArray(new FireworkEffect[]);
    Although I'm not sure why you need it as an array.
     
    Ciaranlol likes this.
  3. Offline

    Ciaranlol

    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page