LeftClickAir isn't working :(

Discussion in 'Plugin Development' started by Matthiaantje, Sep 2, 2016.

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

    Matthiaantje

    So, the bug of the inventory still isn't fixed ;(
    So, i'm making a gadget, the cresent rose, (to test it I made it a small pl)
    But it isn't working, I spammed debug messages but isn't working... Here's the code:
    Code:
    package rose.sniper;
    
    import java.util.Arrays;
    import org.bukkit.ChatColor;
    import org.bukkit.DyeColor;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.World;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.material.Dye;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.inventory.ShapedRecipe;
    
    public class Crescent extends JavaPlugin{
       public int bullets;
       public static ItemStack goldenHoe = new ItemStack(Material.GOLD_HOE);
       public static ItemStack crBullet = new ItemStack(Material.INK_SACK, 1);
       public static ItemStack crShell = new ItemStack(Material.INK_SACK, 1);
       public void onEnable()
       {
         System.out.println(ChatColor.GREEN + "Crescent Rose Sniper Riffle Made By Matthiaantje");
         setMeta();
       }
       @EventHandler
       public void crShoot (PlayerInteractEvent e)
       {
         Player p = e.getPlayer();
         if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK)
           System.out.println("Working!!!");
         {
           if(p.getItemInHand().getType().equals(goldenHoe))
           {
             System.out.println("Working!!!");
             if(!e.getPlayer().getInventory().contains(crBullet))
             {
               p.sendMessage(ChatColor.RED + "[Crescent Rose] You don't have any arrows left!!!!");
             }
             System.out.println("Working!!!");
             p.getInventory().remove(crBullet);
             onArrowShoot(p);
           }
         }
       }
       @EventHandler
       public void onArrowShoot(Player p)
       {
         System.out.println("Working!!!");
         Arrow crBullet = p.launchProjectile(Arrow.class);
         crBullet.setShooter(p);
         crBullet.setVelocity(p.getLocation().getDirection().multiply(4.9));
         World w = p.getWorld();
         w.playSound(p.getLocation(), Sound.ARROW_HIT, 1, 2);
       }
       @EventHandler
       public void onBulletHit(EntityDamageByEntityEvent e)
       {
         System.out.println("Working!!!");
         if(e.getEntity() instanceof Player)
         {
           System.out.println("Working!!!");
           if(e.getDamager() instanceof Arrow)
           {
             System.out.println("Working!!!");
             Arrow ar = (Arrow) e.getDamager();
             if(ar.getShooter() instanceof Player)
             {
               System.out.println("Working!!!");
               e.setDamage(10 + 7 / 2);
             }
           }
         }
       }
       public void setMeta()
       {
         /*
          * Crescent Rose Recipe
          */
         ItemMeta hoeMeta = goldenHoe.getItemMeta();
         hoeMeta.setDisplayName("Crescent Rose");
        hoeMeta.setLore(Arrays.asList(ChatColor.AQUA + "A Scythe wich is a" + " high velocity sniper riffle too"));
        goldenHoe.setItemMeta(hoeMeta);
        ShapedRecipe crRecipe = new ShapedRecipe(goldenHoe);
        crRecipe.shape(
             "IRF",
             "#P#",
             "#S#"
             );
        crRecipe.setIngredient('I', Material.IRON_INGOT);
        crRecipe.setIngredient('R', Material.REDSTONE);
        crRecipe.setIngredient('F', Material.FLINT);
        crRecipe.setIngredient('P', Material.PISTON_BASE);
        crRecipe.setIngredient('S', Material.STICK);
        getServer().addRecipe(crRecipe);
        /*
        * Bullet Recipe
        */
        Dye bullet = new Dye();
        bullet.setColor(DyeColor.GRAY);
        crBullet.setData(bullet);
        ItemMeta bulletMeta = crBullet.getItemMeta();
        bulletMeta.setDisplayName("Bullet");
        bulletMeta.setLore(Arrays.asList(ChatColor.AQUA + "Bullet"));
        crBullet.setItemMeta(bulletMeta);
        ShapedRecipe crBulletRecipe = new ShapedRecipe(crBullet);
        crBulletRecipe.shape(
             "@@@",
             "@P@",
             "@I@"
             );
        crBulletRecipe.setIngredient('P', Material.SULPHUR);
        crBulletRecipe.setIngredient('I', Material.IRON_INGOT);
        getServer().addRecipe(crBulletRecipe);
        /*
        * Set Dye for crShell
        */
        Dye shell = new Dye();
        shell.setColor(DyeColor.GRAY);
        crShell.setData(shell);
       }
    }
    
    Plugin.yml:
    Code:
    main: rose.sniper.Crescent
    name: Crescent Rose
    version: 1.0
    author: Matthiaantje
    
     
  2. Offline

    Zombie_Striker

    @Matthiaantje
    You forgot to register your class. Your class needs to implement Listener, and you must register the class in the onEnable. You can learn how HERE.
     
  3. Offline

    frej4189

    You need to

    1. Implement the Listener class
    2 Register your events in your onEnable
     
  4. @Matthiaantje You really need to address this code, you are abusing static, you capitalised method name, your indentation is super weird and pretty hard to read and you are comparing enuma with .equals rather than ==
     
  5. Offline

    Matthiaantje

    The .equals. agreed... but the capotalization is my way of coding and in sure other People do this as well


    Verstuurd vanaf mijn HUAWEI SCL-L21 met Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page