Event.getAction() == Action.RIGHT_CLICK_AIR | Not Working

Discussion in 'Plugin Development' started by ConversionGaming, Oct 8, 2013.

Thread Status:
Not open for further replies.
  1. Hi guys please help i have just signed up to the forums ESPCIALLY for this problem i cant crack it.
    Ok i have no errors and i have spent hours trying to get my head around the problem but i dont see anything wrong. My code is too shoot a fireball when i right click a iron spade.
    Here my code

    Main:
    Code:java
    1.  
    2. //Fireball
    3. if(SIEnabled == true){
    4. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    5. if(player.getItemInHand().getType() == Material.IRON_SPADE){
    6. Fireball f = player.launchProjectile(Fireball.class);
    7. f.setIsIncendiary(false);
    8. f.setFireTicks(0);
    9. f.setYield(0);
    10. }
    11. }
    12. }else return;
    13.  

    Main:
    Further up the class is this:
    Code:java
    1. public class Main extends JavaPlugin implements Listener{
    2. public final Logger logger = Logger.getLogger("Minecraft");
    3. public static Main plugin;
    4. public boolean SIEnabled = false;
    5. public boolean flying = false;
    6.  
    7.  
    8. @Override
    9. public void onDisable() {
    10. PluginDescriptionFile pdfFile = this.getDescription();
    11. this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    12. }
    13.  
    14. @Override
    15. public void onEnable() {
    16. PluginDescriptionFile pdfFile = this.getDescription();
    17. this.logger.info(pdfFile.getName() + " Version: " + pdfFile.getVersion() + " Has Been Enabled!");
    18. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    19. }
    20.  
    21. @EventHandler
    22. public void onPlayerInteract(PlayerInteractEvent e) {
    23. Player player = e.getPlayer();


    If you are wondering SIEnable is to enable SuperItems so the items can be used to the super standard and then disabled to return to normal items with another command like bellow:

    /si-enable - SIEnable = true; | This allows the SuperItems To BE Super
    /si-disable - SIEnable = false | Returns the items back into normal or disables the possibilities

    Code:java
    1.  
    2. if(commandLabel.equalsIgnoreCase("si-enable")) {
    3. if(player.hasPermission("SI.Enable")){
    4. player.sendMessage(ChatColor.YELLOW + "SuperItems" + ChatColor.GREEN + " Enabled");
    5. SIEnabled = true;
    6. }
    7. }
    8.  
    9. if(commandLabel.equalsIgnoreCase("si-disable")){
    10. if(player.hasPermission("SI.Disable")){
    11. player.sendMessage(ChatColor.YELLOW + "SuperItems" + ChatColor.DARK_RED + " Disabled");
    12. SIEnabled = false;
    13. }
    14. }
    15.  
     
  2. Offline

    calebbfmv

    Can I get the whole class?
    Can I also see your plugin.yml
     
    ConversionGaming likes this.
  3. I have PM'd you most of the information because it does not need mod review
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteract(PlayerInteractEvent e) {
    4. Player player = e.getPlayer();
    5.  
    6. //Flying
    7. if(SIEnabled == true) {
    8. if(e.getClickedBlock() == null) return;
    9. if(player.hasPermission("SI.Fly")){
    10. if(e.getItem().getType().equals(Material.FEATHER)) {
    11. if(flying == false){
    12. flying = true;
    13. player.setAllowFlight(true);
    14. player.sendMessage(ChatColor.GREEN + "Flight is now enabled!");
    15. }else if(flying == true){
    16. flying = false;
    17. player.setAllowFlight(false);
    18. player.sendMessage(ChatColor.DARK_RED + "Flight is now disabled!");
    19. }
    20. }
    21. }else return;
    22. }else return;
    23.  
    24.  
    25. //Fireball
    26. if(SIEnabled == true){
    27. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    28. if(player.getItemInHand().getType() == Material.IRON_SPADE){
    29. Fireball f = player.launchProjectile(Fireball.class);
    30. f.setIsIncendiary(false);
    31. f.setFireTicks(0);
    32. f.setYield(0);
    33. }
    34. }
    35. }else return;
    36. }

    Every single one works but this one i want it to fire even if im not looking at a block, the others i need to look at a block for them to work this one i want it to fire no matter what
     
  4. Offline

    HyrulesLegend

    Are you importing the right "Action" ?
     
  5. I am
     
  6. Offline

    PatoTheBest

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e) {
    3. Player player = e.getPlayer();
    4.  
    5. //Flying
    6. if(SIEnabled == true) {
    7. if(e.getClickedBlock() == null){
    8. if(player.getItemInHand().getType() == Material.IRON_SPADE){
    9. Fireball f = player.launchProjectile(Fireball.class);
    10. f.setIsIncendiary(false);
    11. f.setFireTicks(0);
    12. f.setYield(0);
    13. }
    14. } else {
    15. if(player.hasPermission("SI.Fly")){
    16. if(e.getItem().getType().equals(Material.FEATHER)) {
    17. if(flying == false){
    18. flying = true;
    19. player.setAllowFlight(true);
    20. player.sendMessage(ChatColor.GREEN + "Flight is now enabled!");
    21. }else if(flying == true){
    22. flying = false;
    23. player.setAllowFlight(false);
    24. player.sendMessage(ChatColor.DARK_RED + "Flight is now disabled!");
    25. }
    26. }
    27. }
    28. }else return;
    29. }else return;
    30.  
     
  7. Thank you guys so much for the support it seems that my e.getClickedBlock and getting the action was clashing so now i have implemented the RIGHT_CLICK_AIR and the RIGHT_CLICK_BLOCK together as an if and added all my extras within, Thanks so much guys you all have helped me!
    If you want the code its here
    Main:
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteract(PlayerInteractEvent e) {
    4. Player player = e.getPlayer();
    5. if(SIEnabled == true) {
    6. if((e.getAction() == Action.RIGHT_CLICK_AIR) || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    7.  
    8.  
    9.  
    10. //Flying
    11. if(player.hasPermission("SI.Fly")){
    12. if(e.getItem().getType().equals(Material.FEATHER)) {
    13. if(flying == false){
    14. flying = true;
    15. player.setAllowFlight(true);
    16. player.sendMessage(ChatColor.GREEN + "Flight is now enabled!");
    17. }else if(flying == true){
    18. flying = false;
    19. player.setAllowFlight(false);
    20. player.sendMessage(ChatColor.DARK_RED + "Flight is now disabled!");
    21. }
    22. }
    23. }else return;
    24.  
    25.  
    26. //Lightning
    27. if(player.hasPermission("SI.Lightning")){
    28. if(e.getItem().getType().equals(Material.COMPASS)){
    29. Block block = player.getTargetBlock(null, 50);
    30. Location location = block.getLocation();
    31. World world = player.getWorld();
    32. world.strikeLightning(location);
    33. }
    34. }else return;
    35.  
    36.  
    37. //Fireball
    38. if(player.hasPermission("SI.Fireball")){
    39. if(player.getItemInHand().getType().equals(Material.IRON_SPADE)){
    40. Fireball f = player.launchProjectile(Fireball.class);
    41. f.setIsIncendiary(false);
    42. f.setFireTicks(0);
    43. f.setYield(0);
    44. }
    45. }else return;
    46.  
    47.  
    48.  
    49.  
    50.  
    51.  
    52. }else return;
    53. }
    54. }
     
  8. Offline

    PatoTheBest

    No Problem :D
     
  9. Offline

    calebbfmv

  10. Offline

    xTrollxDudex

    They review it because you are a new member.
     
Thread Status:
Not open for further replies.

Share This Page