Solved How to make a stick shoot this...

Discussion in 'Plugin Development' started by mrsamcraft, Dec 22, 2013.

Thread Status:
Not open for further replies.
  1. Hello,

    So i've just managed to make a command shoot a snowball from the player, But now stumped on how to make this shoot from a stick.

    In other words I still want the players to use the command, but for the snowballs to only shoot when the player uses the stick..

    Command
    Code:java
    1. package mscBoredAdmin.cmd;
    2.  
    3. import mscBoredAdmin.PDL;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10.  
    11. public class cmdShootSnowball
    12. implements CommandExecutor
    13. {
    14. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    15. {
    16. if (!(sender instanceof Player)) {
    17. sender.sendMessage(ChatColor.RED +"Sorry this command can only be used in game.");
    18. return true;
    19. }
    20. PDL.DispatchSnowball((Player)sender);
    21. return true;
    22. }
    23. }


    PDL.class
    Code:java
    1.  
    2. package mscBoredAdmin.PDL;
    3.  
    4. import org.bukkit.Sound;
    5. import org.bukkit.entity.LivingEntity;
    6. import org.bukkit.entity.Snowball;
    7.  
    8. public class PDL
    9. {
    10.  
    11. public static void DispatchSnowball(LivingEntity sender) {
    12. sender.launchProjectile(Snowball.class);
    13. sender.getWorld().playSound(sender.getLocation(), Sound.FIREWORK_BLAST, 3F, 1F);
    14. }
    15. }


    Thanks
    ~ Sam

    P.S sorry for the question, i'm still learning java :)
     
  2. Offline

    xTigerRebornx

    mrsamcraft Where is your class that extends JavaPlugin. Every plugin needs this, otherwise the server wont know its a plugin. It also needs the plugin.yml
     
  3. xTigerRebornx
    I've got all that, and the plugin works.
     
  4. Offline

    xTigerRebornx

    mrsamcraft Okay, so before you launch the snowball, check if the player has a stick in his hand, if he doesn't, then don't launch it
     
  5. Offline

    Ronbo

    if(player.getItemInHand().getType() == Material.STICK)

    simple as that.
     
    mrsamcraft likes this.
  6. Offline

    KaTaPowwDev

    I think this should work...

    Code:java
    1. public void onEnable(){
    2. PluginManager.registerEvents(this this);
    3. }
    4.  
    5. @EventHandler
    6. public void onPlayerInteract(PlayerInteractEvent e){
    7. if(e.getAction == Action.RIGHT_CLICK_BLOCK || Action.RIGHT_CLICK_AIR){
    8. if(e.getItem.getType == Material.STICK){
    9. <YOUR CODE TO LAUNCH A SNOWBALL>
    10. }
    11. }
    12. }
     
    mrsamcraft likes this.
  7. Ronbo

    Just tested it and it worked THANKS! :')
     
Thread Status:
Not open for further replies.

Share This Page