Why the witherskull dont launch?

Discussion in 'Plugin Development' started by BrainyXS, Jun 24, 2018.

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

    BrainyXS

    Hello today i`m coding a plugin for an item, wich can only be used by me. When you Click a Block, the Block dissapera and you hear a sound. When I Click in the Air, a Witherskull should launch and you should hear a sond. The Blocks dissaper workd, but when i rhight Click the Air, nothin happens, no witherskull, no sound, NO ERROR, Nothing. Code:
    Code:
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.Bukkit;
    import org.bukkit.Sound;
    import org.bukkit.entity.WitherSkull;
    import org.bukkit.World;
    
    public class brainy extends JavaPlugin implements Listener {
        @EventHandler
        public void onEvent(PlayerInteractEvent event){
            Player p = event.getPlayer();
            ItemStack gegenstand = event.getItem();
            ItemMeta metaData = gegenstand.getItemMeta();
           
            if(p.getName().equals("BrainyXS")){
                if(metaData.getDisplayName().equals("Brainys Handschuh")){
                    Block b = event.getClickedBlock();
                    Material m = b.getType();
    
                   
                    if(m == Material.AIR){
                        p.playSound(p.getLocation(), Sound.ENTITY_WITHER_SHOOT, 2F, 1F);
                        p.launchProjectile(WitherSkull.class);
                    }
                    else {
                       
                        Location loc = b.getLocation();
                        World w = p.getWorld();
                        w.getBlockAt(loc).setType(Material.AIR);
                        p.playSound(p.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 2F, 1F);
                    }
                }
            }
           
       
       
        }
       
        public void onEnable() {
            this.getLogger().info("Brainy-Items geladen.");
            ItemStack Guanlet = new ItemStack(Material.FEATHER);
            ItemMeta metaData = Guanlet.getItemMeta();
            metaData.setDisplayName("Brainys Handschuh");
            Guanlet.setItemMeta(metaData);
            Guanlet.addUnsafeEnchantment(Enchantment.LUCK, 1);
           
            ShapedRecipe GuanletRezept = new ShapedRecipe(Guanlet);
            GuanletRezept.shape("RGR", "GNG", "RGR");
            GuanletRezept.setIngredient('R', Material.REDSTONE);
            GuanletRezept.setIngredient('G', Material.GOLD_NUGGET);
            GuanletRezept.setIngredient('N', Material.NETHER_STAR);
            this.getServer().addRecipe(GuanletRezept);
               
            PluginManager pluginManager = this.getServer().getPluginManager();
            pluginManager.registerEvents(this, this);
        }
    }
    Here the witherskull should be launchd.
    Code:
    if(m == Material.AIR){
                        p.playSound(p.getLocation(), Sound.ENTITY_WITHER_SHOOT, 2F, 1F);
                        p.launchProjectile(WitherSkull.class);
     
  2. Offline

    CommonSenze

    @BrainyXS
    Have you done some debugs to see if the if statement is even called to true?
     
  3. Offline

    BrainyXS

    @CommonSenze
    No I didn`t du that. I dont work with Eclipse. I code in my sparetime and i`m not a proffesional coder. I dot know how to do that. But if i click a Block, the Else statement will be called and works fine...
     
  4. Offline

    CommonSenze

    @BrainyXS
    What you can do is check the action of the player in the interact event by using this:
    Code:java
    1. if (event.getAction() == Action.LEFT_CLICK_BLOCK){
    2. //Player clicked on a block
    3. } else if (e.getAction() == Action.LEFT_CLICK_AIR){
    4. //player click in the air
    5. }
     
Thread Status:
Not open for further replies.

Share This Page