I want to shoot a piece of tnt from the players face and then let it explode when it hits the target block.
if (cmd.getName().equalsIgnoreCase("cannon")) {
if(!perrmissionCheck(sender, "Needs.cannon", "cannon")){
return true;
}
if (!(sender instanceof Player)){
sender.sendMessage(nameC+"You must be a player to preform this command.");
return true;
}
Block block = ((Player) sender).getTargetBlock(null, 50);
Location location = ((Player) sender).getLocation();
//float power = 4;
//if (args.length == 1){
//power = Float.parseFloat(args[0]);
//}
sender.sendMessage(name+"BOOM!");
double x = block.getX();
double y = block.getY();
double z = block.getZ();
TNTPrimed tnt = (TNTPrimed) ((Player)sender).getWorld().spawn(location, TNTPrimed.class);
Vector v = new Vector(x, y, z);
tnt.setVelocity(v);
//block.getWorld().createExplosion(location, power);
//block.getWorld().spawn(tntLoc, TNTPrimed.class);
return true;
}
This kinda just ramdomly throws the tnt and then exploads i want to get where the player is looking and then shoot it that way if someone could also describe how the args work for new Vector(arg0, arg1, arg2) i would appreciate it...
Thanks any help is great
EDIT I relize this is really old but i wanted to share how I did it,
int v = 2;
if (args.length > 1){
v = Integer.parseInt(args[0]);
}
final Vector direction = user.getEyeLocation().getDirection().multiply(v);
TNTPrimed tnt = user.getWorld().spawn(user.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), TNTPrimed.class);
tnt.setVelocity(direction);
user.sendMessage(name + "Boom!");
plugin.inGameMsg.msgAdmins(plugin.chatDark_AQUA + user.getName() + plugin.chatGray + " used cannon command!");
return true;
this sends the tnt right where the player is looking
