hello guys i am back and i did'nt give up from development soo... i chossed to change to the start... something like abilities... soo i know the main code for giving Items.... Code: ItemStack attacker = new ItemStack(ItemManagement.createItem(Material.WOOD_SWORD, 1, (short)0, "§0Enderman blade")); attacker.addUnsafeEnchantment(Enchantment.DURABILITY, 1000); attacker.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 1); attacker.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); p.getInventory().setItem(0, attacker); but i wanna change it... that if the player is right click with the sword he will shoot fireball! could someone give me the simplest code? thanks! Regards, OfirTIM
Yeah, this is probably the best way to go about it. For setting the velocity you can invoke the getDirection method of the player's location and multiply by whatever you want.
@EventHandler public void onInteract(PlayerInteractEvent e) { if(e.getAction()==Action.RIGHT_CLICK_AIR || e.getAction()==Action.RIGHT_CLICK_BLOCK) { if(e.getPlayer().getItemInHand().getItemMeta().getDisplayName()=="§0Enderman blade") { // code for the fireball here } } }
- Use ChatColor class, instead of using he special ChatColor symbols, for future compatibility. The special character can also corrupt some files on certain operating systems, therefore the ChatColor class is better. @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); Action action = event.getAction(); if(action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { Fireball fireball = player.launchProjectile(Fireball.class); fireball.setVelocity(player.getLocation().getDirection().multiply(1.6)); } } Please understand this code without copy pasting.
That is why I wrote at the end of the message to please understand the code without copy and pasting, because I know for a fact it is bad, and nobody will learn from it. And I usually don't spoon-feed, but in reality, it's not much code. I am just trying to help, and they just came back to the API, soo.