Simple code doesn't work!

Discussion in 'Plugin Development' started by quinster08, Nov 15, 2013.

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

    quinster08

    Hello guys, i coded a simple code but i seems not to work. Check this

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. final Player p = event.getPlayer();
    4. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
    5. p.getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    6. p.getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    7. p.getWorld().playSound(p.getLocation(), Sound.PORTAL_TRIGGER, 8, 8);
    8. p.getWorld().playSound(p.getLocation(), Sound.ENDERDRAGON_GROWL, 8, 8);
    9. p.sendMessage(ChatColor.AQUA + "Ohai");
    10. }
    11. }
    12. }


    Somebody help me plz?
     
  2. Offline

    The_Doctor_123

    You probably didn't register events. Let us see your whole class(es).
     
  3. Offline

    quinster08

    The_Doctor_123
    Code:java
    1. package Me.krickie;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Effect;
    6. import org.bukkit.Sound;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Main extends JavaPlugin implements Listener {
    15.  
    16. @Override
    17. public void onEnable() {
    18. }
    19.  
    20. {
    21. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    22. }
    23.  
    24. @Override
    25. public void onDisable() {
    26.  
    27. }
    28. @EventHandler
    29. public void onPlayerInteract(PlayerInteractEvent event) {
    30. final Player p = event.getPlayer();
    31. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
    32. p.getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    33. p.getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    34. p.getWorld().playSound(p.getLocation(), Sound.PORTAL_TRIGGER, 8, 8);
    35. p.getWorld().playSound(p.getLocation(), Sound.ENDERDRAGON_GROWL, 8, 8);
    36. p.sendMessage(ChatColor.AQUA + "Ohai");
    37. }
    38. }
    39. }
     
  4. Offline

    Sweatyyyy

    quinster08
    Uhm it seems that
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(this, this);

    is not inside the onEnable
    It should be:
    Code:java
    1. @Override
    2. public void onEnable() {
    3. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    4. }
    5.  
    6. @Override
    7. public void onDisable() {
    8.  
    9. }
     
  5. Offline

    The_Doctor_123

    Sweatyyyy
    Geeze, what is with people and bodies today?? Nobody is getting it. :p
     
  6. Offline

    quinster08

    Sweatyyyy
    Code:java
    1. package Me.krickie;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Effect;
    6. import org.bukkit.Sound;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Main extends JavaPlugin implements Listener {
    15.  
    16. @Override
    17. public void onEnable() {
    18. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    19. }
    20.  
    21. @Override
    22. public void onDisable() {
    23.  
    24. }
    25. @EventHandler
    26. public void onPlayerInteract(PlayerInteractEvent event) {
    27. final Player p = event.getPlayer();
    28. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
    29. p.getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    30. p.getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    31. p.getWorld().playSound(p.getLocation(), Sound.PORTAL_TRIGGER, 8, 8);
    32. p.getWorld().playSound(p.getLocation(), Sound.ENDERDRAGON_GROWL, 8, 8);
    33. p.sendMessage(ChatColor.AQUA + "Ohai");
    34. }
    35. }
    36. }


    Still doesn't do anything!
     
  7. Offline

    Sweatyyyy

    quinster08
    Uhm, try this maybe:
    Code:java
    1.  
    2.  
    3. @Override
    4. public void onEnable() {
    5. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    6. }
    7.  
    8. @Override
    9. public void onDisable() {
    10.  
    11. }
    12. @EventHandler
    13. public void onPlayerInteract(PlayerInteractEvent event) {
    14. Player p = event.getPlayer();
    15. if(event.getAction()==Action.RIGHT_CLICK_AIR && p.getInventory().getItemHand.getType == Material.AIR){
    16. p.getLocation().getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    17. p.getLocation().getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    18. p.getLocation().getWorld().playSound(p.getLocation(), Sound.PORTAL_TRIGGER, 8, 8);
    19. p.getLocation().getWorld().playSound(p.getLocation(), Sound.ENDERDRAGON_GROWL, 8, 8);
    20. p.sendMessage(ChatColor.AQUA + "Ohai");
    21. }
    22. }
    23. }
    24.  
     
  8. Offline

    The_Doctor_123

    quinster08
    Does the plugin load? Is there any errors? Does the event execute?
     
  9. Offline

    quinster08

    The_Doctor_123 The plugin loads, no errors and doesn't do anything..

    Sweatyyyy New code still doesn't work!

    Code:java
    1. package Me.krickie;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Effect;
    6. import org.bukkit.Material;
    7. import org.bukkit.Sound;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Main extends JavaPlugin implements Listener {
    16.  
    17. @Override
    18. public void onEnable() {
    19. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    20. }
    21.  
    22. @Override
    23. public void onDisable() {
    24.  
    25. }
    26. @EventHandler
    27. public void onPlayerInteract(PlayerInteractEvent event) {
    28. Player p = event.getPlayer();
    29. if(event.getAction()==Action.RIGHT_CLICK_AIR && p.getInventory().getItemInHand().getType() == Material.AIR){
    30. p.getLocation().getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    31. p.getLocation().getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    32. p.getLocation().getWorld().playSound(p.getLocation(), Sound.PORTAL_TRIGGER, 8, 8);
    33. p.getLocation().getWorld().playSound(p.getLocation(), Sound.ENDERDRAGON_GROWL, 8, 8);
    34. p.sendMessage(ChatColor.AQUA + "Ohai");
    35. }
    36. }
    37. }


    Somebody help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  10. Offline

    PolarCraft

    quinster08 You are unable to do air for some reason. lel. Because air is unidentified as a block around you.
     
  11. Offline

    tenowg

    Code:java
    1. if (event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
    2.  
    3.  
    4. player.getLocation().getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    5. player.getLocation().getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 20);
    6. player.getLocation().getWorld().playSound(player.getLocation(), Sound.PORTAL_TRIGGER, 8, 8);
    7. player.getLocation().getWorld().playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 8, 8);
    8. player.sendMessage(ChatColor.AQUA + "Ohai");
    9. }


    player is retrieved earlier in the code...

    This code was tested in one of my plugins, and it works with no problem, so either your plugin isn't loading, or some other issue is wrong.
     
  12. Offline

    AoH_Ruthless

    Eats_Rainbows likes this.
  13. Offline

    Bart

    Check if p.getInventory().getItemInHand() is null rather than Material.AIR
     
  14. Offline

    PolarCraft

    Bart null with throw null exception. Without it being defined.
     
  15. Offline

    quinster08

  16. Offline

    AoH_Ruthless

  17. Offline

    quinster08

    It's oke. Nothing wrong with it!
    Code:
    name: Kikinogwattes
    main: Me.krickie.Main
    version: 1.0
    description: >
                pleple
    
     
  18. Offline

    AoH_Ruthless

    quinster08
    I am positive the description cannot be stretched over 2 lines. Try making it all in the same line.

    FYI: Tahg me or I may not see the post.
     
  19. Offline

    quinster08

    AoH_Ruthless New plugin.yml still doesn't work!
    Code:
    name: CoolThingy
    main: Me.krickie.Main
    version: 1.0
    description: Hai
    I think its another wierd/rare problem! I got that earlier i made a fine code and it doesn't work but it does load like this one:
    Code:
    @EventHandler
    void onDamage(EntityDamageByEntityEvent e){
        if(!(e.getEntity() instanceof Player)){
        return;    }
        if(!(e.getDamager() instanceof Player)){
          return;
        }
        Player PlayerWhoGotHit = (Player)e.getEntity();
        Player PlayerWhoHit = (Player)e.getDamager();
        if (!PlayerWhoHit.getItemInHand().getItemMeta().getDisplayName().equals("GrassBlade")) {
          return; }
        PlayerWhoGotHit.playEffect(PlayerWhoGotHit.getLocation(), Effect.STEP_SOUND, Material.GRASS);
        e.setDamage(6);
    }
    }
    
    And other 2.
     
  20. Offline

    AoH_Ruthless

    quinster08
    You are positive there is no error code?
     
Thread Status:
Not open for further replies.

Share This Page