Any help with this code ?

Discussion in 'Plugin Development' started by q8minecraft, Oct 8, 2014.

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

    q8minecraft

    I've been trying to solve these problems in my code, But I can't seem to find any answers! This is the code
    Code:java
    1. package me.q8minecraft.chesteffects.ChestEffects;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Color;
    6. import org.bukkit.Effect;
    7. import org.bukkit.Effect.Type;
    8. import org.bukkit.FireworkEffect;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.EntityType;
    12. import org.bukkit.entity.Firework;
    13. import org.bukkit.entity.Item;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.block.Action;
    17. import org.bukkit.event.player.PlayerInteractEvent;
    18. import org.bukkit.event.player.PlayerLevelChangeEvent;
    19. import org.bukkit.inventory.meta.FireworkMeta;
    20. import org.bukkit.plugin.java.JavaPlugin;
    21.  
    22. public class ChestEffects extends JavaPlugin {
    23.  
    24. @Override
    25. public void onEnable() {;
    26. getLogger().info("ChestEffects Has Been Activated!");
    27. }
    28.  
    29. @Override
    30. public void onDisable() {;
    31. getLogger().info("ChestEffects Has Been Deactivated!");
    32. return;
    33.  
    34. }
    35.  
    36. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    37. if (cmd.getName().equalsIgnoreCase("")) {
    38. return true;
    39. }
    40. return false;
    41. }
    42.  
    43. public void onPlayerInteract(PlayerInteractEvent event) {
    44. {
    45. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    46. @EventHandler
    47. public void onLevelChange(PlayerLevelChangeEvent event1) {
    48. Player p = event1.getPlayer();
    49. if (p.hasPermission("firework.level")){
    50.  
    51. Firework fw = (Firework) p.getWorld().spawnEntity(p.getLocation(), EntityType.FIREWORK);
    52. FireworkMeta fwm = fw.getFireworkMeta();
    53.  
    54. Random r = new Random();
    55.  
    56. int rt = r.nextInt(4) + 1;
    57. org.bukkit.FireworkEffect.Type type = Type.BALL;
    58. if (rt == 1) type = Type.BALL;
    59. if (rt == 2) type = Type.BALL_LARGE;
    60. if (rt == 3) type = Type.BURST;
    61. if (rt == 4) type = Type.CREEPER;
    62. if (rt == 5) type = Type.STAR;
    63.  
    64. int r1i = r.nextInt(17) + 1;
    65. int r2i = r.nextInt(17) + 1;
    66. Color c1 = getColor(r1i);
    67. Color c2 = getColor(r2i);
    68.  
    69. FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
    70.  
    71. fwm.addEffect(effect);
    72.  
    73. int rp = r.nextInt(2) + 1;
    74. fwm.setPower(rp);
    75.  
    76. fw.setFireworkMeta(fwm);
    77. }
    78. }
    79.  
    80.  
    81. }
    82. }
    83. }
    84.  
    85. private Color getColor(int r2i) {
    86. return null;
    87. }}
    88.  
    89.  


    plugin.yml
    Code:java
    1. name: ChestEffects
    2. main: me.q8minercaft.chesteffcts.ChestEffects
    3. version: 1.0
    4. commands:
    5. ChestEffects:
    6. description: Plays sounds and fireworks when opening a chest!
    7. usage:
     
  2. Offline

    MomsKnife

    I don't know where to start. The amount of errors in this code is making me sad.

    What do you want this to do, anyways?
     
    es359 likes this.
  3. Well, you didn't mention what problem you were having, so I quickly went through the code noting all issues I saw

    - Don't call the logger in onEnable() and onDisable() - Bukkit prints messages automatically
    - When would a command name ever be an empty String?
    - Why do you have an onCommand method that does nothing except print the usage if it's a valid command?
    - Why do you have usage: in your plugin.yml but then don't specify anything?
    - Why do you declare a method inside a method? (I'm guessing this is the problem you meant)
    - Why have you defined a method that just returns null?
     
  4. Offline

    q8minecraft

    I just started to code, I'm not a pro.. At least some help would be appreciated ?

    What I'm trying to do is, When someone opens a chest they get some fire works. And obviously I failed really hard doing that :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  5. q8minecraft If you're new to Java then I'd recommend learning the basics from either the Oracle tutorials, or from a Java book - trust me, you need the basics of Java before you're able to properly make a plugin. :)
     
  6. Offline

    q8minecraft

    Any direct links ?
     
  7. Offline

    MomsKnife

    Code:java
    1.  
    2. @EventHandler
    3. public void onInteract(PlayerInteractEvent e){
    4. if (e.getAction == Action.RIGHT_CLICK_BLOCK{
    5. launchFirework(e.getPlayer());
    6. }
    7. }
    8.  
    9. public static void launchFirework(Player p) {
    10. Firework fw = p.getWorld().spawn(p.getEyeLocation(), Firework.class);
    11. FireworkMeta meta = fw.getFireworkMeta();
    12. FireworkEffect effect = FireworkEffect.builder().flicker(true).withColor(org.bukkit.Color.RED).build();
    13. meta.addEffect(effect);
    14. fw.setFireworkMeta(meta);
    15. }
     
  8. Offline

    q8minecraft

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

Share This Page